I would like to retrieve the result of a series of promises below and store it into a variable, so that I could use it outside of this chain. That being said, I keep on getting errors or the variable comes out as undefined.
Here's the series:
I've tried storing the promises in a variable i.e. var customerToken = //the code below. But, customerToken comes out as undefined, since the promises end after the variable is set.
var Stripe = StripeAPI('sk_test_key');
Stripe.customers.create({
email: Meteor.user().emails[0].address,
description: "SIDIM 2016",
source: stripeToken
}).then(function(customer) {
return Stripe.tokens.create({
customer: customer.id
}, {stripe_account: "acct_XXXYYYZZZ"});
}).then(function(token) {
console.log(token);
var charge = Stripe.customers.create({
email: Meteor.user().emails[0].address,
description: "SIDIM 2016",
source: token.id
}, {stripe_account: "acct_XXXYYYZZZ"});
console.log(charge);
}).then(function(charge) {
return Stripe.charges.create({
amount: total,
currency: 'usd',
customer: charge.id
}, {stripe_account: "acct_XXXYYYZZZ"});
}).catch(function(err) {
// Deal with an error
});