//server
var Stripe = StripeAPI('your_secret_key');
Meteor.methods({
stripeCreateUser: function(options) {
// get a sync version of our API async func
var stripeCustomersCreateSync=Meteor.wrapAsync(Stripe.customers.create,Stripe.customers);
// call the sync version of our API func with the parameters from the method call
var result=stripeCustomersCreateSync({
description: 'Woot! A new customer!',
card: options.card,
plan: options.plan
});
// do whatever you want with the result
return result;
}
});
EDIT - just realized that all the formatting was omitted after submitting.... gross
Yes, the fact that Stripe is async and Meteor methods are not is bit confusing. I will try to find a good reference about this and add it the readme. Thanks for the suggestion!
I'd like to suggest updating the readme. It currently states that an asynchronous function can be run on the server. This isn't the case and requires Meteor.wrapAsync. See my SO question: http://stackoverflow.com/questions/26226583/meteor-proper-use-of-meteor-wrapasync-on-server
I suggest changing the usage documentation to: //client Stripe.setPublishableKey('YOUR_PUBLISHABLE_KEY');
Meteor.call('stripeCreateUser', options, function(err, result) { //do something
console.log(err, result); });
//server var Stripe = StripeAPI('your_secret_key');
Meteor.methods({ stripeCreateUser: function(options) { // get a sync version of our API async func var stripeCustomersCreateSync=Meteor.wrapAsync(Stripe.customers.create,Stripe.customers); // call the sync version of our API func with the parameters from the method call var result=stripeCustomersCreateSync({ description: 'Woot! A new customer!', card: options.card, plan: options.plan }); // do whatever you want with the result return result; } });
EDIT - just realized that all the formatting was omitted after submitting.... gross