我试图将平衡支付集成到一个节点应用程序中,但由于某种原因,我在创建一个客户时得到了一个未定义的响应。然而,客户是在市场上创建的。
balanced.configure('ak-test-2dE1FyvrskNw4o7CiAsGvYOgD7aPSb0ww');
var customer = balanced.marketplace.customers.create({
email: userAccount.emails[0].address,
name: userAccount.username
});
console.log('customer' + customer.ID);返回未定义的客户端
到我的控制台。
任何帮助都将不胜感激!
发布于 2014-03-09 18:47:39
balanced.marketplace.customers.create在后台预先形成一个网络调用并返回承诺,这意味着要访问资源上的底层数据,您必须使用.then。
var customer = balanced.marketplace.customers.create(...);
customer.then(function(c) {
console.log(c.href);
});这可能会使您感到困惑的原因是平衡节点库使用的承诺是“重载”,因为您可以将操作串在一起。您只需要在希望访问承诺的结果时使用.then。这意味着您可以执行如下操作:
var card = balanced.get('/cards/CCasdfadsf'); // this is a network call
var customer = balanced.marketplace.customers.create(); // this is a network call that will go in parallel
card.associate_to_customer(customer).debit(5000); // using promises these will complete once all the previous request are complete
customer.then(function (c) {
console.log(c.href); // since we need to access the data (href) on the customer, we have to wait for the non blocking requests to complete and then the data will be ready.
});https://stackoverflow.com/questions/22276269
复制相似问题