Keith Ng
Keith Ng

Reputation: 11

Retrieving line items from Braintree Transactions

The Braintree Transaction API has a field for lineItems, but how do I use it? The Transaction response doesn't return line items, and there are no lineitems int the control panel for transactions either.

It looks like the line items aren't actually stored anywhere. Am I right? If so, what's the point of them?

I want to show customers an itemised receipt of the transaction (which is a really obvious use case, right?). Is there anyway to get Braintree to generate this as part of the transaction?

I'm using version 2.5 of the Braintree Node.js SDK.

Upvotes: 1

Views: 678

Answers (2)

Shea
Shea

Reputation: 896

UPDATED ANSWER

As of version 2.6.0 of the Braintree Node SDK, lineItems is an attribute of the Transaction response object. See Braintree's associated documentation here.

ORIGINAL ANSWER

You may use gateway.transactionLineItem.findAll(someTransactionId, function(err, response) {}) to retrieve the line items associated with a transaction. This is documented in the tests of the SDK:

specHelper.defaultGateway.transactionLineItem.findAll(response.transaction.id, function (err, response) {
    assert.equal(response.length, 1);
    let lineItem = response[0];

    assert.equal(lineItem.quantity, '1.0232');
    assert.equal(lineItem.name, 'Name #1');
    assert.equal(lineItem.kind, 'debit');
    assert.equal(lineItem.unitAmount, '45.1232');
    assert.equal(lineItem.totalAmount, '45.15');
    done();
});

We are in the process of updating our developer docs and Control Panel to reflect this behavior.

Upvotes: 0

Mike Davlantes
Mike Davlantes

Reputation: 1035

I'm not sure if this was the case a month ago when you asked the question, but it seems that the transaction response does return line items:

https://developers.braintreepayments.com/reference/response/transaction/node#line_items

Upvotes: 0

Related Questions