【发布时间】:2022-01-10 19:21:17
【问题描述】:
我正在使用 Stripe.js 的 React 组件来尝试处理已连接帐户的付款,并从每次付款中收取费用。我不确定我的客户端和服务器之间的流程是否正确提取了我的克隆客户和付款方式。当我的测试客户尝试付款时,我收到“No such payment_intent: 'pi_abc...zyx'”。我确保我在客户端和服务器上都使用了正确的私有测试密钥。我的关联账户是快速账户。当我转到我的 Stripe 仪表板查看“连接”下的“客户”选项卡时,我看到的是:
每次我尝试付款时都会创建一个空白条目。
以下是我目前正在采取的让平台客户支付关联帐户的步骤:
- 当客户首次在我的网站上注册时,我安装的 Stripe-firebase 扩展程序会自动生成一个客户 ID。这些现在被视为我的平台客户
- 我允许平台客户创建一个 Express Connected 帐户,这非常好用。我现在有了他们的 Stripe 帐户 ID,例如:'acct_abc...xyz`。
- 下面是平台客户尝试向关联账户付款时的流程:
React/Client Side - 仅使用测试密钥加载Stripe,而不使用 Stripe Connected 帐户 ID
const stripePromise = loadStripe('pk_test_abc...');。我将此提供给<Elements stripe={stripePromise}>
React/客户端 - 用户填写付款表格并按下提交。从客户端/平台创建 paymentMethodReq:
const paymentMethodReq = await stripe.createPaymentMethod({
type: 'card',
card: cardElement,
billing_details: billingDetails
});
节点/服务器端 - 客户端然后向我的服务器发出请求,尝试将平台支付方式克隆到已连接的帐户:
const serverPaymentMethod = await stripe.paymentMethods.create({
customer: data.customerStripeId, // Customer ID of the customer paying (platform customer)
payment_method: data.paymentMethodId, // Using the payment method Id generated from 'paymentMethodReq' on the client side
}, {
stripeAccount: connectedAccountStripeAccountId, // Using the Connected Account
});
节点/服务器端 - 客户端然后向我的服务器发出请求以从平台创建/“克隆”新客户并将其链接到已连接的帐户
const customer = await stripe.customers.create({
payment_method: data.paymentMethodId, //Payment method id generated from 'serverPaymentMethod' above
}, {
stripeAccount: connectedAccountStripeAccountId, // Using the same Connected Account
});
节点/服务器端 - 客户端然后向我的服务器发出请求,以使用与连接帐户相关联的客户 ID 以及从服务器生成的付款方式创建付款意图
const intent = await stripe.paymentIntents.create({
amount: data.price * 100,
currency: 'usd',
payment_method_types: ['card'],
payment_method: data.paymentMethodId, // Payment method id generated from 'serverPaymentMethod' above
customer: data.customerStripeId, // Customer Id generated from 'customer' above
description: data.desc,
capture_method: 'manual',
application_fee_amount: (data.price * 100) * 0.15,
}
React/Client Side - 我尝试确认卡付款,结果出现“No such payment_intent: 'pi_abc...zyx'”错误
const confirmedCardPayment = await stripe.confirmCardPayment(paymentIntentResult?.data?.client_secret, {
payment_method: serverPaymentMethod?.data.id //Payment method id generated from 'serverPaymentMethod' above
});
我尝试将客户端上的 stripe.confirmCardPayment 替换为对我的服务器的调用,以确认付款意图,如下所示:
const confirmPaymentIntent = await stripe.paymentIntents.confirm(
data.paymentIntentId, // Payment intent id generated from 'intent' above
{
payment_method: data.paymentMethodId // Payment method id generated from 'serverPaymentMethod' above
});
这也会导致“No such payment_intent 'pi_3K...9Rx'”
如果有人能帮助我找出我在这个过程中哪里出了问题,那将不胜感激。谢谢
【问题讨论】:
标签: node.js reactjs firebase stripe-payments