Last active
July 6, 2016 15:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}, (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