Skip to content

Instantly share code, notes, and snippets.

@daveroma
Last active July 6, 2016 15:58
Show Gist options
  • Save daveroma/8f056ffe356c4f384bf2883ada97d0b6 to your computer and use it in GitHub Desktop.
Save daveroma/8f056ffe356c4f384bf2883ada97d0b6 to your computer and use it in GitHub Desktop.
Meteor 1.3 code to expose a server method which leverages Futures enabling a synchronous call to the Stripe API, creates a new "Customer" and returns a response once the request has completed.
import { Meteor } from 'meteor/meteor';
import { Stripe } from 'meteor/mrgalaxy:stripe';
import Future from 'fibers/future';
Meteor.methods({
stripeCreateCustomer(token, email) {
const stripeCustomer = new Future();
check(token, String);
check(email, String);
Stripe.customers.create({
source: token,
email
}, (error, customer) => {
if (error) {
stripeCustomer.return(error);
} else {
stripeCustomer.return(customer);
}
});
return stripeCustomer.wait();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment