braintree / braintree_node

Braintree Node.js library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
335 stars 104 forks source link

Cannot read property 'transactionLineItem' of undefined #146

Closed yeldarby closed 6 years ago

yeldarby commented 6 years ago

General information

Issue description

I'm trying to use the Transaction.lineItems method and getting an error.

/Users/yeldarb/Code/hatchlings-club/www/node_modules/braintree/lib/braintree/transaction.js:138
    return this[gatewaySymbol].transactionLineItem.findAll(this.id);
                               ^

TypeError: Cannot read property 'transactionLineItem' of undefined
    at Transaction.lineItems (/Users/yeldarb/Code/hatchlings-club/www/node_modules/braintree/lib/braintree/transaction.js:138:32)
    at Transaction.<anonymous> (/Users/yeldarb/Code/hatchlings-club/www/node_modules/@braintree/wrap-promise/wrap-promise.js:17:33)
    at async.mapLimit.output.data (/Users/yeldarb/Code/hatchlings-club/www/index.js:493:30)
    at /Users/yeldarb/Code/hatchlings-club/www/node_modules/async/dist/async.js:1121:9
    at replenish (/Users/yeldarb/Code/hatchlings-club/www/node_modules/async/dist/async.js:998:17)
    at /Users/yeldarb/Code/hatchlings-club/www/node_modules/async/dist/async.js:1002:9
    at _asyncMap (/Users/yeldarb/Code/hatchlings-club/www/node_modules/async/dist/async.js:1119:5)
    at Object.mapLimit (/Users/yeldarb/Code/hatchlings-club/www/node_modules/async/dist/async.js:1205:16)
    at SearchResponseStream.<anonymous> (/Users/yeldarb/Code/hatchlings-club/www/index.js:492:10)
    at emitNone (events.js:106:13)

Here's an minimal code snippet that reproduces the error:

var stream = gateway.transaction.search(function(search) {
    search.customerId().is(<SOME_USER_ID_HERE>);
});

stream.on('data', function(t) {
    t.lineItems();
});
yeldarby commented 6 years ago

I should note as a followup that this does work. It's just the Transaction.lineItems method that's broken.

var stream = gateway.transaction.search(function(search) {
    search.customerId().is(<SOME_USER_ID_HERE>);
});

stream.on('data', function(t) {
    gateway.transactionLineItem.findAll(transaction.id, function(e, items) {
        console.log(items);
    });
});
crookedneighbor commented 6 years ago

My guess is that there's something funky going on with the wrapping of the transaction search results, as the method does exist on the transaction object returns from transaction.sale https://github.com/braintree/braintree_node/blob/dcd9f1984bcec888994e92c97cdcd7653976c90b/spec/integration/braintree/transaction_gateway_spec.js#L450-L464

crookedneighbor commented 6 years ago

We've identified the issue and are working on a fix. Thanks for the report!

hollabaq86 commented 6 years ago

@yeldarby We've deployed a fix to this issue in version 2.13.1.