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

如何通过Stripe API从关联账户检索Payment Intent?

解决Stripe关联账户检索Payment Intent的问题

当然可以从关联账户检索Payment Intent,你遇到的错误是因为stripe_account参数的传递方式不对——它不属于Payment Intent retrieve接口的API参数,而是请求级别的选项,不能放在retrieve方法的第二个参数数组里。以下是具体的正确实现方式:

PHP服务端方案(优先推荐)

方式1:使用withStripeAccount方法(Stripe PHP SDK v7+支持)

这是针对单个请求指定关联账户最直观的写法:

$payment_intent = $stripe->paymentIntents->withStripeAccount($connected_account_id)->retrieve(
    $payment_intent_id
);

方式2:初始化客户端时指定关联账户

如果你的请求会持续针对同一个关联账户,可以在创建StripeClient时直接配置:

$stripe = new \Stripe\StripeClient([
    'api_key' => '你的秘钥',
    'stripe_account' => $connected_account_id,
]);

// 后续所有请求都会默认使用该关联账户
$payment_intent = $stripe->paymentIntents->retrieve($payment_intent_id);

方式3:通过请求选项传递

retrieve方法的第三个参数是请求选项容器,stripe_account可以放在这里:

$payment_intent = $stripe->paymentIntents->retrieve(
    $payment_intent_id,
    [], // 第二个参数是API专属参数(如expand),无需时留空即可
    ['stripe_account' => $connected_account_id] // 请求级别的选项数组
);

客户端JS方案

如果需要前端实现,在Stripe JS中要在选项里指定stripeAccount:

// 方式1:初始化时全局指定
const stripe = Stripe('你的可发布密钥', {
  stripeAccount: $connected_account_id
});

stripe.retrievePaymentIntent($payment_intent_id)
  .then(({paymentIntent}) => {
    // 处理返回的Payment Intent数据
  });

// 方式2:单个请求单独指定
const stripe = Stripe('你的可发布密钥');
stripe.retrievePaymentIntent($payment_intent_id, {
  stripeAccount: $connected_account_id
})
.then(({paymentIntent}) => {
  // 处理结果
});

内容的提问来源于stack exchange,提问作者Topher Rhodes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:59:57