Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting customer in Sandbox throws TypeError: Cannot read property 'creditCards' of undefined #56

Closed
BarthesSimpson opened this issue Sep 11, 2015 · 1 comment

Comments

@BarthesSimpson
Copy link

I am testing adding and deleting customers in my Sandbox before going live.

First, I query my database to find the customers I want to delete. The user ID in my database is the same as the customer ID in braintree. My query returns a result which is an array of users:

    if (result.length > 0) {
        for (i = 0 ; i < result.length ; i++) {
            console.log('deleting ' + result[i]['id'] + ' from braintree');
            gateway.customer.delete(result[i]['id'], function (err) {
              if (err) {
                  console.log(err);
              } else {
                  console.log('deleted customer from braintree');
              };
            }); 
        };
    };

It seems to work fine at first - I see the correct console messages. But then a few moments later it throws (doesn't just log but crashes on) this error:

10:18:53 web.1 | /.../node_modules/braintree/lib/braintree/customer.js:27
10:18:53 web.1 | if (attributes.creditCards) {
10:18:53 web.1 | ^
10:18:53 web.1 | TypeError: Cannot read property 'creditCards' of undefined
10:18:53 web.1 | at new Customer (/.../node_modules/braintree/lib/braintree/customer.js:27:19)
10:18:53 web.1 | at /.../node_modules/braintree/lib/braintree/gateway.js:121:35
10:18:53 web.1 | at /.../node_modules/braintree/lib/braintree/http.js:103:20
10:18:53 web.1 | at Parser. (/.../node_modules/braintree/node_modules/xml2js/lib/xml2js.js:134:18)
10:18:53 web.1 | at Parser.emit (events.js:107:17)
10:18:53 web.1 | at Object.saxParser.onclosetag (/.../node_modules/braintree/node_modules/xml2js/lib/xml2js.js:120:24)
10:18:53 web.1 | at emit (/.../node_modules/braintree/node_modules/xml2js/node_modules/sax/lib/sax.js:625:33)
10:18:53 web.1 | at emitNode (/.../node_modules/braintree/node_modules/xml2js/node_modules/sax/lib/sax.js:630:3)
10:18:53 web.1 | at closeTag (/.../node_modules/braintree/node_modules/xml2js/node_modules/sax/lib/sax.js:874:5)
10:18:53 web.1 | at Object.write (/.../node_modules/braintree/node_modules/xml2js/node_modules/sax/lib/sax.js:1314:29)
10:18:53 web.1 | at Parser.exports.Parser.Parser.parseString (/.../node_modules/braintree/node_modules/xml2js/lib/xml2js.js:145:29)
10:18:53 web.1 | at Parser.parseString (/.../node_modules/braintree/node_modules/xml2js/lib/xml2js.js:3:63)
10:18:53 web.1 | at IncomingMessage. (/.../node_modules/braintree/lib/braintree/http.js:102:31)
10:18:53 web.1 | at IncomingMessage.emit (events.js:129:20)
10:18:53 web.1 | at _stream_readable.js:908:16
10:18:53 web.1 | at process._tickCallback (node.js:355:11)
10:18:53 web.1 | exited with code 1

@BarthesSimpson
Copy link
Author

I guess the problem was that I had another call to the gateway that was still running while the customer deletions were taking place, creating a race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant