当这个承诺运行时,浏览器只是超时(没有发送任何数据。 ERR_EMPTY_RESPONSE)。终端没有任何错误。第一个console.log被打印,但没有别的。
var createStripeCustomer = function(customer, source) {
console.log('create stripe customer');
return new Promise(function(res, rej) {
stripe.customers.create({
email: customer.email,
source: source,
account_balance: 500,
metadata: {
first_name: customer.first_name,
last_name: customer.last_name,
phone: customer.phone,
address: `${customer.address} ${customer.appt}`,
city: customer.city,
state: customer.state,
zipcode: customer.zip,
referral: customer.referral
},
function(err, newCustomer) {
if (err) {
console.log(err);
rej(err);
}
else {
console.log('created customer');
res(newCustomer);
}
}
});
});
};
答案 0 :(得分:1)
您错过了}
方法第一个参数中的stripe.customers.create
:
var createStripeCustomer = function(customer, source) {
console.log('create stripe customer');
return new Promise(function(res, rej) {
stripe.customers.create({
email: customer.email,
source: source,
account_balance: 500,
metadata: {
first_name: customer.first_name,
last_name: customer.last_name,
phone: customer.phone,
address: `${customer.address} ${customer.appt}`,
city: customer.city,
state: customer.state,
zipcode: customer.zip,
referral: customer.referral
}
},
function(err, newCustomer) {
if (err) {
console.log(err);
rej(err);
}
else {
console.log('created customer');
res(newCustomer);
}
}
});
});
};
然后它应该以这种方式工作:
createStripeCustomer(customer, source).then( res => console.log(res) ).catch(error => console.error(error))