我想檢索下面一系列承諾的結果並將其存儲到變量中,以便我可以在此鏈之外使用它。這就是說,我一直在得到錯誤或變量出來未定義。Javascript承諾 - 檢索結果
這裏的系列:
我已經試過存放在變量VAR即= customerToken下面的代碼//的承諾。但是,customerToken是未定義的,因爲承諾在變量設置後結束。
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
});
你試圖存儲哪個變量?沒有值從第二個'.then()' – guest271314
返回。我想將customer.id存儲在第一個返回中,並將charge.id存儲在最後一箇中。第二個沒有回報,因爲我悲傷地試圖將結果存儲在變量中。 –
您是否想在'Stripe.tokens.create({'call?')之外存儲'customer.id',或者在'Stripe.tokens.create({'? – guest271314