[英]Working With Stripe and Node / Express to Charge Existing Customer with No Card
I have customers created at Stripe with no card from an external integration. 我在Stripe创建了没有外部集成卡的客户。
So the customer object exists, but it doesn't have a card. 因此,客户对象存在,但没有卡。
I'd like the customer to be able to go to a payment page and make a payment through the checkout. 我希望客户能够转到付款页面并通过结帐进行付款。 However, the customer ID is already known.
但是,客户ID是已知的。 So we're just asking the customer to enter their 'reference' and then enter a card and pay.
因此,我们只是在要求客户输入他们的“参考”,然后输入卡并付款。
I have this code: 我有以下代码:
app.post('/charge', (req, res) => {
stripe.charges.create({
amount: 4000,
description: 'Sample Charge',
currency: 'gbp',
customer: req.body.stripeId
},function(err,result){
console.log(err);
res.render('charge'});
});
});
However this returns the error: 但是,这将返回错误:
Error: Cannot charge a customer that has no active card
I thought the whole point of the checkout was that it created a card for the customer. 我认为结帐的全部目的是为客户创建了一张卡。
How do I store the card that is entered through the checkout against the specified customer and the charge it? 如何存储在结帐时针对指定客户输入的卡并收取费用?
The checkout code is: 结帐代码为:
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_Some_key"
data-email="customer email"
data-billing-address="true"
data-allow-remember-me="false"
data-name="Company Limited"
data-description="Example charge"
data-image="an-image.jpg"
data-locale="auto"
data-zip-code="true"
data-currency="gbp">
</script>
I thought the whole point of the checkout was that it created a card for the customer.
我认为结帐的全部目的是为客户创建了一张卡。
It creates a card, but you still need to attach it to the customer yourself: 它会创建一张卡,但您仍然需要自己将其附加到客户:
stripe.customers.update(req.body.stripeId, { // I assume this is the customer ID (`cus_xxx`)
source: req.body.stripeToken // `tok_xxx` generated by Stripe Checkout
}, function(err, customer) {
stripe.charges.create({
amount: 4000,
description: 'Sample Charge',
currency: 'gbp',
customer: customer.id
}) ...
});
https://stripe.com/docs/saving-cards + https://stripe.com/docs/api/customers/update?lang=node#update_customer-source https://stripe.com/docs/saving-cards + https://stripe.com/docs/api/customers/update?lang=node#update_customer-source
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.