我想知道如何使用Node.js库向Stripe中的现有客户添加新的银行卡。例如:我有一个客户使用Stripe客户ID:cus_XXXXXXXXXX,此客户已经有1张卡,我想向同一客户添加另一张卡。
答案 0 :(得分:7)
你应该像这样使用createSource:
var stripe = require("stripe")(
// your secret key
);
stripe.customers.createSource(
"cus_XXXXXXXXXX",
{ source: "tok_amex" },
function(err, card) {
// asynchronously called
}
);
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
}
);
此外,如果您希望将新卡设置为客户的默认卡,则应更新customer对象。
答案 1 :(得分:3)
以下是答案:首先创建一个令牌并使用该令牌通过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) {}
);
}
它将向Stripe上的现有客户添加新卡。
答案 2 :(得分:0)
这是适用于我向客户添加卡的代码。它可以帮助其他人。
stripe.tokens.create({
// Create the card
card: {
number: cardNumber,
exp_month: expMonth,
exp_year: expYear,
cvc: cardCVC
}
}, function(err, token) {
if (err) {
// Error creating card token
console.log(err)
} else {
stripe.customers.createSource(
// Set the customer ID
"cus_XXXXXXXX",
// Set the source to the id of the token that was just created
{ source: token.id },
function(err, card) {
if (err) {
// Error adding card to customer
console.log(err)
} else {
// Success
console.log(card)
}
}
);
}
});