Raj*_*dha 3 node.js stripe-payments
我想知道如何使用Node.js库向Stripe中的现有客户添加新的银行卡.例如:我有一个客户使用Stripe客户ID:cus_XXXXXXXXXX,此客户已经有1张卡,我想向同一客户添加另一张卡.
您应该像这样使用createSource:
var stripe = require("stripe")(
// your secret key
);
stripe.customers.createSource(
"cus_XXXXXXXXXX",
{ source: "tok_amex" },
function(err, card) {
// asynchronously called
}
);
Run Code Online (Sandbox Code Playgroud)
其中source之一是:
包含用户信用卡详细信息的字典!像这样(未经测试):
stripe.customers.createSource(
"cus_XXXXXXXXXX",
{ source: {
object: 'card',
exp_month: ... ,//expiry month
exp_year: ... ,//expiry year
number: ... ,//card number
cvc: ... // cvc of the card
}},
function(err, card) {
// asynchronously called
}
);
Run Code Online (Sandbox Code Playgroud)此外,如果您希望将新卡设置为客户的默认卡,则应更新客户对象.
小智 5
答案如下:首先创建一个令牌,然后使用该令牌通过 Stripe API 创建新客户,或使用新帐号和路由号码更新客户。
stripe.tokens.create({
bank_account: {
country: 'US',
currency: 'usd',
account_holder_name:"xxxx",
account_holder_type: "xx",
routing_number: :"xx",
account_number: :"xx",
}}, function(err, token) {
var tokenID = token.id;
stripe.customers.createSource("cus_xxxxxxx",{
source: tokenID
},
function(err, card) {}
);
}
Run Code Online (Sandbox Code Playgroud)
它将为 Stripe 上的现有客户添加一张新卡。