0

Balanced payment をノード アプリに統合しようとしていますが、何らかの理由で、顧客を作成するときに未定義の応答が返されます。ただし、顧客は市場で作成されています。

    balanced.configure('ak-test-2dE1FyvrskNw4o7CiAsGvYOgD7aPSb0ww');    
    var customer = balanced.marketplace.customers.create({
         email: userAccount.emails[0].address,
         name: userAccount.username
    });
    console.log('customer' + customer.ID);

未定義の顧客を返します

私のコンソールに。

どんな助けでも大歓迎です!

4

1 に答える 1

3

balanced.marketplace.customers.createバックグラウンドでネットワーク呼び出しを実行し、プロミスを返します。これは、リソースの基になるデータにアクセスすることを意味します。使用する必要があります.then

var customer = balanced.marketplace.customers.create(...);
customer.then(function(c) {
    console.log(c.href);
});

これがあなたを混乱させた理由は、バランスの取れたノード ライブラリが使用するプロミスが「オーバーロード」されているためです。つまり、アクションをつなぎ合わせることができます。.thenpromise の結果にアクセスする場合にのみ使用する必要があります。これは、次のようなことができることを意味します。

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. 
});
于 2014-03-09T18:47:39.130 に答える