admin管理员组文章数量:1271801
I am trying to initialize a customer for the first time. I have a form where they sign up and everything, and they submit it. On the client, the following happens:
var cardValues = AutoForm.getFormValues('credit-card-form').insertDoc;
Stripe.createToken(cardValues, function (err, token) {
if (!err && token) {
Meteor.call('Stripe.initializeCustomer', token);
}
});
On the serverside, I am trying to do something like this:
Meteor.methods({
'Stripe.initializeCustomer': function (token) {
var Stripe = StripeAPI(process.env.STRIPE_KEY);
// some validation here that nobody cares about
Stripe.customers.create({
source: token
}).then(function (customer) {
return Stripe.customers.createCard(customer.id, {
source: token
})
}).catch(function (error) {
// need to do something here
})
}
});
It would seem that the Stripe API doesn't like this
Unhandled rejection Error: You cannot use a Stripe token more than once
Is there a canonical way to make multiple requests to stripe on the server for a single token?
I am trying to initialize a customer for the first time. I have a form where they sign up and everything, and they submit it. On the client, the following happens:
var cardValues = AutoForm.getFormValues('credit-card-form').insertDoc;
Stripe.createToken(cardValues, function (err, token) {
if (!err && token) {
Meteor.call('Stripe.initializeCustomer', token);
}
});
On the serverside, I am trying to do something like this:
Meteor.methods({
'Stripe.initializeCustomer': function (token) {
var Stripe = StripeAPI(process.env.STRIPE_KEY);
// some validation here that nobody cares about
Stripe.customers.create({
source: token
}).then(function (customer) {
return Stripe.customers.createCard(customer.id, {
source: token
})
}).catch(function (error) {
// need to do something here
})
}
});
It would seem that the Stripe API doesn't like this
Unhandled rejection Error: You cannot use a Stripe token more than once
Is there a canonical way to make multiple requests to stripe on the server for a single token?
Share Improve this question asked May 19, 2015 at 19:38 corvidcorvid 11.2k12 gold badges70 silver badges134 bronze badges 1- It looks like you are passing the entire token dictionary, when in this manner I think you should only pass the tokenID when creating the customer. – hybrdthry911 Commented May 20, 2015 at 18:06
1 Answer
Reset to default 11It seems that you're running into this issue because you're accidentally trying to reuse a token to create a new card for a customer when, unbeknownst to you, you've already used that token to create that card for that user. Creating a customer with a stored card is actually much easier than you expect: when you initialize a customer object with a token, the Stripe API goes ahead and stores that card in association with the new customer. That is, you can immediately go ahead and make a charge to your customer upon creation as in:
Stripe.customers.create({
source: token.id
}).then(function (customer) {
Stripe.charge.create({
amount: 1000,
currency: 'usd',
customer: customer.id
});
});
For more information, I'd remend the Stripe docs at https://support.stripe./questions/can-i-save-a-card-and-charge-it-later and https://stripe./docs/api/node#create_customer.
Let me know if that solves your problem!
本文标签: javascriptHow to create both a customer and a card in a single action with StripeStack Overflow
版权声明:本文标题:javascript - How to create both a customer and a card in a single action with Stripe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741124324a2343887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论