Search code examples
node.jsbalanced-payments

Balanced Payments Account debit not working with Node.js


I am trying to do an account credit request with Node.js using the following example. But it fails even when I use the sample code without any change. https://docs.balancedpayments.com/current/overview.html?language=node#charge-a-credit-card

balanced.Accounts.get("/v1/marketplaces/TEST-MP60c88vnFHzgzEyzGcbMKic/accounts/AC1a77avbmVTUt8pciwDlMJW/debits", function(err, result) {
var user = balanced.Accounts.nbalanced(result);
user.Debits.create({ amount: 1000 }, function(err, result) {
/* . . . */
});

});

It fails after this statement is executed...

var user = balanced.Accounts.nbalanced(result);

The error message I get is...

The following properties are required and are missing or null (id).

Here is the full stack trace...

C:\Users\Nabeel\GroupFund\node\node_modules\balanced-official\lib\nbalanced\validate.js:112
if (!callback) throw error;
                     ^
The following properties are required and are missing or null (id).

Solution

  • I found the mistake in the sample code given in the documentation. All I had to do was omit the /debits from the uri in balanced.Accounts.getcall...

    The following code works...

        balanced.Accounts.get("/v1/marketplaces/TEST-MP60c88vnFHzgzEyzGcbMKic/accounts/AC1a77avbmVTUt8pciwDlMJW", function(err, result) {
        var user = balanced.Accounts.nbalanced(result);
        user.Debits.create({ amount: 1000 }, function(err, result) {
        /* . . . */
        });
    });