You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel 9中使用Stripe支付网关出现API不支持异常求助

解决Laravel 9中Stripe印度收款API不支持的问题

问题原因

Stripe在印度地区已不再支持旧版的Charge API进行收款,必须使用官方推荐的Payment Intents API来处理INR货币的支付交易。

解决方案

替换原有的Charge::create逻辑,改用Payment Intents API实现收款,具体调整如下:

后端代码修改

public function makePayment(Request $request)
{
    \Stripe\Stripe::setApiKey('sk_test_.............KTt');

    // 创建Payment Intent
    $paymentIntent = \Stripe\PaymentIntent::create([
        'amount' => 2000, // 单位为最小货币单位,此处代表20.00印度卢比
        'currency' => 'inr',
        'description' => "10 cucumbers from Roger's Farm",
        'payment_method_types' => ['card'], // 指定支持的支付方式类型
    ]);

    // 返回前端所需的client_secret,用于完成支付确认
    return response()->json([
        'client_secret' => $paymentIntent->client_secret
    ]);
}

前端配合逻辑

前端需使用Stripe.js/Stripe Elements收集支付信息并完成支付确认,核心示例逻辑:

// 初始化Stripe实例
const stripe = Stripe('pk_test_你的公钥');

// 调用后端接口获取client_secret
fetch('/make-payment', { method: 'POST' })
  .then(res => res.json())
  .then(data => {
    // 确认卡片支付
    stripe.confirmCardPayment(data.client_secret, {
      payment_method: {
        card: cardElement, // 页面中的卡片输入元素实例
        billing_details: {
          name: '客户姓名'
        }
      }
    }).then(result => {
      if (result.error) {
        // 处理支付错误
        console.error(result.error.message);
      } else if (result.paymentIntent.status === 'succeeded') {
        // 支付成功后的业务逻辑处理
        console.log('支付完成');
      }
    });
  });

关键提示

  • 确保你的Stripe SDK为最新版本,避免兼容性问题
  • 印度地区支付需遵守当地监管规则,确认账号已完成印度地区合规配置

内容的提问来源于stack exchange,提问作者shameema cp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 06:12:47