将支付方法从平台复制到关联帐户

时间:2021-05-10 20:47:44

标签: java stripe-payments

我将 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);

在这一点上一切似乎都很好。 Payment Intent 返回条带 client secret,如 'pi_1Ipfl3Bf0KWukpZWQdbAzoz1_secret_RAKsPMLpyhkDJ7q8N1VvSmaoR'status'requires_confirmation'。因此,当我尝试在客户端进行确认时,它会抛出一个错误:No such payment_intent: 'pi_1Ipfl3Bf0KWukpZWQdbAzoz1'

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

有人能解释一下吗?问候!

2 个答案:

答案 0 :(得分:1)

您的服务器端步骤是正确的,您正在在 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 以进行克隆),您必须在您的客户端上创建第二个 Stripe.js 实例,一个经过身份验证的 Connect 帐户。

答案 1 :(得分:0)

嗯,最后我在客户端解决了。我只需要告诉 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
    ...
});