使用测试卡创建客户时出错
Error when creating a customer using test card
尝试为新创建的客户开始订阅时,我从 Stripe 收到以下错误消息:
invalid_request_error
Error: This customer has no attached payment source
客户似乎创建得很好。我正在使用 Stripe Checkout 来收集卡令牌。为了进行测试,我使用带有随机信息的 Stripe 4242 4242 4242 4242
卡号。令牌似乎正在创建并很好地传递到我的服务器。下面是我的服务器端代码:
stripe.plans.retrieve(
"basic-monthly",
function(err, plan) {
if (err) {
console.error(err)
res.sendStatus(500)
} else {
stripe.customers.create({
email: owner,
source: token.id,
}, function(err, customer) {
if (err) {
console.error(err)
res.sendStatus(500)
} else {
stripe.subscriptions.create({
customer: customer.id,
items: [
{
plan: "basic-monthly",
quantity: 1
},
],
}, function(err, subscription) {
if (err) {
console.error(err)
console.log('@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@')
res.sendStatus(500)
} else {
console.log('Subscription created.')
console.dir(subscription)
res.sendStatus(200);
}
});
}
});
}
});
@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@
与上述错误一起记录。我明白错误的含义,但我不确定它是如何发生的。正如您在上面看到的,我在创建客户时传入了令牌 ID,source: token.id,
。
这里有什么问题?
这里最可能的原因是 token.id
是空的,因此在没有源的情况下创建了客户。我建议记录 token
的内容,看看你得到了什么。
尝试为新创建的客户开始订阅时,我从 Stripe 收到以下错误消息:
invalid_request_error
Error: This customer has no attached payment source
客户似乎创建得很好。我正在使用 Stripe Checkout 来收集卡令牌。为了进行测试,我使用带有随机信息的 Stripe 4242 4242 4242 4242
卡号。令牌似乎正在创建并很好地传递到我的服务器。下面是我的服务器端代码:
stripe.plans.retrieve(
"basic-monthly",
function(err, plan) {
if (err) {
console.error(err)
res.sendStatus(500)
} else {
stripe.customers.create({
email: owner,
source: token.id,
}, function(err, customer) {
if (err) {
console.error(err)
res.sendStatus(500)
} else {
stripe.subscriptions.create({
customer: customer.id,
items: [
{
plan: "basic-monthly",
quantity: 1
},
],
}, function(err, subscription) {
if (err) {
console.error(err)
console.log('@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@')
res.sendStatus(500)
} else {
console.log('Subscription created.')
console.dir(subscription)
res.sendStatus(200);
}
});
}
});
}
});
@@@@@ UNABLE TO CREATE SUBSCRIPTION @@@@
与上述错误一起记录。我明白错误的含义,但我不确定它是如何发生的。正如您在上面看到的,我在创建客户时传入了令牌 ID,source: token.id,
。
这里有什么问题?
这里最可能的原因是 token.id
是空的,因此在没有源的情况下创建了客户。我建议记录 token
的内容,看看你得到了什么。