我正试图通过React Native与Stripe Connect直接付款。我包含了创建paymentIntent的Node.js后端函数。这些是关于条纹文档I的指南,如下所示:
创建PaymentIntent:
1: https://stripe.com/docs/payments/accept-a-payment?platform=react-native
Stripe Connect Create Direct Charge:
2: https://stripe.com/docs/connect/direct-charges
在遵循这两个指南之后,我得到了错误客户不存在(customerID)。就我所知,这是有意义的,因为我在平台层面上创建了一个客户,并试图使用该客户为没有该客户的连接帐户创建paymentIntent。所以我进一步研究,发现了这个:
跨帐户克隆客户:
3: https://stripe.com/docs/connect/cloning-customers-across-accounts
这正是我不想做的,因为我正在构建一个平台应用程序,我不希望客户每次都重新输入支付信息。
如果您的平台使用支付方法API,您必须从该客户创建一个PaymentMethod
我不确定,但我想我需要这样做。我打开这个链接。
https://stripe.com/docs/payments/payment-methods/connect cloning-payment-methods
现在,这里说:在发出此请求之前,使用API创建一个PaymentMethod或编写一个固定的测试ID。
点击"固定测试id"后你进入这个页面:
https://stripe.com/docs/testing卡片
有测试paymentMethod: "pm_card_visa"我用它,它不工作。这是我的问题。请看看我下面的注释代码,以完全理解我的问题。
app.post('/payment-sheet', async (req, res) => {
// Use an existing Customer ID if this is a returning customer.
const customer = await stripe.customers.create();
console.log("CUSTOMER_ID", customer.id);
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 4,
exp_year: 2023,
cvc: '314',
},
});
console.log("PAYMENT_METHOD_ID", customer.id);
const clonedPaymentMethod = await stripe.paymentMethods.create({
customer: customer.id,
payment_method: paymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_PAYMENT_METHOD_ID", paymentMethod.id);
const clonedCustomer = await stripe.customers.create({
paymentMethod: clonedPaymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_CUSTOMER_ID", customer.id);
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
customer: clonedCustomer.id,
paymentMethod: clonedPaymentMethod.id,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
res.json({
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: customer.id,
publishableKey: 'pk_test_51If3LbLceO********************9xxLypLlBm24BXiP5FsLsb9TgNOwmHGCYYPKZsDoU000J8jVZmF'
});
});
这是我最终得到的代码。在克隆之前,我需要先为平台客户创建一种支付方式。
app.post('/payment-sheet', async (req, res) => {
// Use an existing Customer ID if this is a returning customer.
const customer = await stripe.customers.create();
console.log("CUSTOMER_ID", customer.id);
const paymentMethod = await stripe.paymentMethods.create({
type: 'card',
card: {
number: '4242424242424242',
exp_month: 4,
exp_year: 2023,
cvc: '314',
},
});
console.log("PAYMENT_METHOD_ID", customer.id);
const clonedPaymentMethod = await stripe.paymentMethods.create({
customer: customer.id,
payment_method: paymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_PAYMENT_METHOD_ID", paymentMethod.id);
const clonedCustomer = await stripe.customers.create({
payment_method: clonedPaymentMethod.id,
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
console.log("CLONED_CUSTOMER_ID", customer.id);
const ephemeralKey = await stripe.ephemeralKeys.create({
customer: clonedCustomer.id
}, {
apiVersion: '2020-08-27',
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
},
);
console.log("EPHEMERAL_KEY", ephemeralKey.secret);
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
customer: clonedCustomer.id,
payment_method: clonedPaymentMethod.id,
currency: 'eur',
automatic_payment_methods: {
enabled: true,
},
}, {
stripeAccount: 'acct_1Ks7wyQ7pYORq1ll',
});
res.json({
paymentIntent: paymentIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: clonedCustomer.id,
publishableKey: 'pk_test_51If3LbLceOiP5FsLsb9Tg********************NOwmHGCYYPKZsDoU000J8jVZmF'
});
});
测试卡仅在美国可用。https://stripe.com/docs/testing#cards如果你不在美国,你不能使用测试卡,必须使用。使用适合本国的国际卡:https://stripe.com/docs/testing?numbers-or-method-or-token=payment-methods国际电话卡