【发布时间】:2021-02-13 23:53:30
【问题描述】:
所以我正在尝试使用 Stripe、React 和 Nodejs 进行测试付款。
在前端,我使用createPaymentMethod() 并发送一个发布请求,其中包含与产品相关的有效用户信息、项目数量、用户和地址信息。像这样:
const purchase = {
...paymentMethod,
address: {
line1: `${user.address.number} ${user.address.street}`,
postal_code: user.address.zipcode,
city: user.address.city,
state: user.address.state,
country: 'Brazil'
},
customer: {
email: user.email,
name: user.name,
},
product,
quantity,
}
let data = await fetch('http://localhost:3002/checkout', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(purchase),
})
到目前为止一切都很好......
在后端我正在检索此信息并在尚未创建用户时使用stripe.customers.create()
const customerPurchase = await stripe.customers.create({
email: customer.email,
name: customer.name,
address,
payment_method: payment_method_id //response from paymentMethod on the front end
})
最后,创建费用我使用charges.create() 方法:
const idempotencyKey = uuid()
return stripe.charges.create({
amount: product.price * quantity * 100,
currency: 'brl',
customer: customerStripeId,
receipt_email: customer.email,
description: `Congratulations! You just purchased the item: ${product.name}!`,
shipping: {
address: {
line1: address.line1,
city: 'Manaus',
country: 'Brazil',
postal_code: address.zipcode,
}
}
},{
idempotencyKey
})
但是我收到此错误:StripeCardError: Cannot charge a customer that has no active card。
我认为这可能与一些必须像这样传递的source 属性有关:source: req.body.stripeToken。但是,我不知道从哪里获得这个 stripeToken,尝试了所有方法但还没有找到任何东西。
有人可以帮帮我吗?我真的很感激。
【问题讨论】:
标签: node.js reactjs stripe-payments