title: Javascript promises - retrieve result
body: <p>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. </p>
  
  <p>Here's the series:</p>
  
  <p>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. </p>
  
  <pre><code>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
  });
  </code></pre>