正如标题所述,我正在尝试使用一次付款方式(信用卡)付款,但该付款方式未保存在客户的个人资料中。我仍然希望能够在Stripe的客户资料中记录该费用。
根据the docs,这可以通过在发送给id
的有效负载中的customer
键中传递客户的Stripe.customers.createCharge
来完成。但是,这样做时,我收到一条错误消息,指出该卡未与客户链接(这显然不是,并且我不希望这样)。
客户
cus_***
没有ID为tok_visa的卡
要解决此问题,我暂时应用了in this answer中提到的修复程序,该修复程序基本上涉及为付款创建一个临时卡,然后将其删除。
我想知道如果没有明确记录,API怎么会不起作用,希望有人在同一条带上出现Stripe铃声的人中找到
。这是我要运行的代码:
await stripeService.charges.create({
source: token, // temporary token received from Checkout
customer: user.stripeCustomerId, // the Stripe customer ID from my database
amount,
currency: 'usd',
description: 'Test charge'
});
答案 0 :(得分:1)
您显式链接到的一次性使用源文档仅适用于Sources,但是tok_visa
会创建一个Card对象。我相信这就是您得到错误的原因。
如果您尝试使用源代码(其ID为'src_xxx')(例如createSource)通过前端的Elements / Checkout获得的代码,它将成功,我只是测试了。您也可以使用以下代码进行测试:
const src = await stripe.sources.create({
type : "card",
token : "tok_visa"
});
const charge = await stripe.charges.create({
source : src.id,
customer : "cus_xxxx",
amount : 1000,
currency : "usd"
});
答案 1 :(得分:0)
我能够做到这一点,首先创建源,然后创建费用,然后在其中指定如下所示的customerId和sourceId:
//Create the source first
var options = new SourceCreateOptions
{
Type = SourceType.Card,
Card = new CreditCardOptions
{
Number = Number,
ExpYear = ExpYear,
ExpMonth = ExpMonth,
Cvc = Cvc
},
Currency = "gbp"
};
var serviceSource = new SourceService();
Source source = serviceSource.Create(options);
//Now do the payment
var optionsCharge = new ChargeCreateOptions
{
Amount = 500,
Currency = "gbp",
Description = "Your description",
SourceId = source.Id,
CustomerId = "yourcustomerid"
};
var service = new ChargeService();
service.Create(optionsCharge);
result = "success";