将 PaymentMethods 从平台克隆到关联账户

Cloning PaymentMethods from the Platform to Connected Accounts

我在标准帐户中使用 Stripe。

我在平台上保存了客户和付款方式,因此,客户在客户端选择付款方式并将其发送到服务器。因此,在服务器端,我将 PaymentMethod 克隆到将接收付款的关联帐户。我的服务器端代码如下所示

RequestOptions requestOptions = RequestOptions.builder()
    .setStripeAccount("{{CONNECTED_STRIPE_ACCOUNT_ID}}")
    .build();

PaymentMethodCreateParams paramsClone = PaymentMethodCreateParams.builder()
    .setCustomer("cus_1")//Id of the customer in the platform
    .setPaymentMethod("payment_method_id")//One of the payment methods of the cus_1
    .build();

PaymentMethod newPaymentMethod = PaymentMethod.create(paramsClone, requestOptions);

此时我假设这个新的 newPaymentMethod 在连接的帐户中,对吗?

那我创建一个PaymentIntent

PaymentIntentCreateParams params = PaymentIntentCreateParams.builder()
    .setAmount(100)
    .setPaymentMethod(newPaymentMethod.getId())
    .setCurrency("usd")
    .setApplicationFeeAmount(10)
    .build();

PaymentIntent paymentIntent = PaymentIntent.create(params, requestOptions);

此时一切似乎都很好。付款意向正在返回 client secret 条带 'pi_1Ipfl3Bf0KWukpZWQdbAzoz1_secret_RAKsPMLpyhkDJ7q8N1VvSmaoR' 并且 status'requires_confirmation'。因此,当我尝试在客户端确认时,它会抛出一条错误消息:No such payment_intent: 'pi_1Ipfl3Bf0KWukpZWQdbAzoz1'.

我认为这与我的平台和关联帐户之间的切换有关,但我无法弄清楚具体问题是什么。我正在关注这个 https://stripe.com/docs/connect/cloning-customers-across-accounts and this https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods 但我仍然不知道如何让它工作。

谁能解释一下?此致!

嗯,最后我在客户端解决了。我只需要告诉 stripe 代表关联帐户进行确认即可。在 react native 中使用 tipsi-stripe 是这样的:

stripe.setStripeAccount('acct_XYZ');//Set the connected account
stripe.confirmPaymentIntent({ clientSecret: stripeClientSecret })
.then((cofirmResponse) => {
    stripe.setStripeAccount(null);//Reset the connected account
    ...
}).catch((e) => { 
    stripe.setStripeAccount(null);//Reset the connected account
    ...
});

您的服务器端步骤是正确的,您正在在 Connect 帐户上创建一个 PaymentIntent。

您在客户端缺少的是,因为 PaymentIntent 存在于 Connect 帐户中,所以您的 Stripe。js/mobile SDK 也需要作为 Connect 帐户进行身份验证。

您基本上需要在客户端指定:

var stripe = Stripe('{{PLATFORM_PUBLISHABLE_KEY}}', {
  stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
});

https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application

因为我假设您已经将 Stripe.js 认证为您的平台可发布密钥(为了在平台上创建第一个 PaymentMethod,进行克隆),您必须创建 [=25] 的第二个实例=] 在您的客户端上,一个被验证为 Connect 帐户。