[英]Working With Stripe and Node / Express to Charge Existing Customer with No Card
我在Stripe創建了沒有外部集成卡的客戶。
因此,客戶對象存在,但沒有卡。
我希望客戶能夠轉到付款頁面並通過結帳進行付款。 但是,客戶ID是已知的。 因此,我們只是在要求客戶輸入他們的“參考”,然后輸入卡並付款。
我有以下代碼:
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'});
});
});
但是,這將返回錯誤:
Error: Cannot charge a customer that has no active card
我認為結帳的全部目的是為客戶創建了一張卡。
如何存儲在結帳時針對指定客戶輸入的卡並收取費用?
結帳代碼為:
<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>
我認為結帳的全部目的是為客戶創建了一張卡。
它會創建一張卡,但您仍然需要自己將其附加到客戶:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.