条纹连接 |直接收费 | Node.js:没有这样的付款方式:'pm_card_visa'
Stripe Connect | Direct Charges | Node.js: No such PaymentMethod: 'pm_card_visa'
我正在尝试通过 React Native 使用 Stripe Connect 直接付款。
我包含了创建 paymentIntent 的 Node.js 后端函数。
这些是 Stripe Docs 上的指南,其中如下:
正在创建 PaymentIntent:
1: https://stripe.com/docs/payments/accept-a-payment?platform=react-native
Stripe Connect 创建直接充电:
2: https://stripe.com/docs/connect/direct-charges
按照这两个指南操作后,我收到错误客户不存在 (customerID)。好的,据我所知,这是有道理的,因为我在平台 lvl 上创建了一个客户,并尝试使用该客户为没有该客户的关联帐户创建 paymentIntent。所以我进一步研究并发现了这个:
跨账户克隆客户:
3: https://stripe.com/docs/connect/cloning-customers-across-accounts
这正是我想要的,因为我正在构建一个平台应用程序,我不希望客户每次都重新输入付款信息。
如果您的平台使用支付方式API,您必须从该客户创建支付方式
我不确定,但我认为我需要这样做?好的,所以我转到这个 link...
https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
现在,这里说:使用 API 创建一个 PaymentMethod 或在发出此请求之前编写一个固定的测试 ID。
点击“固定测试 ID”后,您将进入此页面:
https://stripe.com/docs/testing#cards
有测试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'
});
});
测试卡仅在美国提供。
https://stripe.com/docs/testing#cards
如果您不在美国,则不能使用测试卡并且必须使用。使用适合您所在国家/地区的国际卡:
https://stripe.com/docs/testing?numbers-or-method-or-token=payment-methods#international-cards
这是我最终使用的代码。在克隆之前,我需要先为平台客户创建一个支付方式。
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'
});
});
我正在尝试通过 React Native 使用 Stripe Connect 直接付款。 我包含了创建 paymentIntent 的 Node.js 后端函数。 这些是 Stripe Docs 上的指南,其中如下:
正在创建 PaymentIntent:
1: https://stripe.com/docs/payments/accept-a-payment?platform=react-native
Stripe Connect 创建直接充电:
2: https://stripe.com/docs/connect/direct-charges
按照这两个指南操作后,我收到错误客户不存在 (customerID)。好的,据我所知,这是有道理的,因为我在平台 lvl 上创建了一个客户,并尝试使用该客户为没有该客户的关联帐户创建 paymentIntent。所以我进一步研究并发现了这个:
跨账户克隆客户:
3: https://stripe.com/docs/connect/cloning-customers-across-accounts
这正是我想要的,因为我正在构建一个平台应用程序,我不希望客户每次都重新输入付款信息。
如果您的平台使用支付方式API,您必须从该客户创建支付方式
我不确定,但我认为我需要这样做?好的,所以我转到这个 link...
https://stripe.com/docs/payments/payment-methods/connect#cloning-payment-methods
现在,这里说:使用 API 创建一个 PaymentMethod 或在发出此请求之前编写一个固定的测试 ID。
点击“固定测试 ID”后,您将进入此页面:
https://stripe.com/docs/testing#cards
有测试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'
});
});
测试卡仅在美国提供。 https://stripe.com/docs/testing#cards 如果您不在美国,则不能使用测试卡并且必须使用。使用适合您所在国家/地区的国际卡: https://stripe.com/docs/testing?numbers-or-method-or-token=payment-methods#international-cards
这是我最终使用的代码。在克隆之前,我需要先为平台客户创建一个支付方式。
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'
});
});