【发布时间】:2020-10-13 10:40:56
【问题描述】:
我正在努力让 Stripe 在我的服务器上运行。
所以,在客户端,我有这段代码(经过努力让元素工作):
this.props.stripe.createPaymentMethod({ type: 'card', card: cardElement, billing_details: { name: name } }).then((paymentMethod) => {
// server request with customer_id and paymentMethod.id);
});
这很好用。现在,在服务器 (NodeJS) 上,我想为我的客户添加一个新的持续订阅,并收取固定费用。
这就是我所拥有的:
const paymentIntent = await stripe.paymentIntents.create({
amount: 1000,
currency: 'usd',
payment_method_types: ['card'],
customer: req.body.customer_id,
metadata: { integration_check: 'accept_a_payment' },
});
const paymentIntentConfirmation = await stripe.paymentIntents.confirm(paymentIntent.id, { payment_method: req.body.paymentMethod_id });
const newSubscription = await stripe.subscriptions.create({
customer: req.body.customer_id,
items: [{ plan: premium_plan.id, quantity: 1 }],
default_payment_method: req.body.paymentMethod_id,
});
const attachPaymentToCustomer = await stripe.paymentMethods.attach(req.body.paymentMethod_id, { customer: req.body.customer_id });
const updateCustomerDefaultPaymentMethod = await stripe.customers.update(req.body.customer_id, {
invoice_settings: {
default_payment_method: req.body.paymentMethod_id,
},
});
所以,如果我没有将付款附加给客户,我会收到以下错误消息:
'The customer does not have a payment method with the ID pm_1Gx9m1HVGJbiGjghYhrkt6j. The payment method must be attached to the customer.'
如果这样做,我会收到以下错误消息:
'This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.'
那么,我该如何添加该死的付款方式,所以当我检索我的客户时,它显示该客户已更新了他刚刚订阅的服务的新订阅,以及他的付款方式(此中的 CC案例)。
非常感谢您在这里为沮丧的用户提供任何帮助!
总的来说,到目前为止,实施 Stripe 是一段非常痛苦的经历。似乎没有任何效果。我使用 Typescript,并且有很多错误。该文档不是很有帮助,也没有得到很好的解释。 “创建一个来源”、“创建一个令牌”、“创建一个支付意图”、“创建一个设置意图”,我应该如何理解所有这些东西之间的区别?我想添加一个该死的在线订阅,这应该是一个互联网服务的标准程序。为什么会有这么多不同的指导方针,包括令牌、来源等等......
【问题讨论】:
-
我非常同意。
-
看到有人对此有同样的感受,我感到很欣慰。说得好。