Reports

Customanchor

We believe you should have total control of your data. That's why Braintree's API gives you the flexibility to generate your own custom reports, allowing you to focus on what's important to your business without being subject to the limits of our standard reports. You can start setting up your own reporting as soon as you've integrated with Braintree.

note

As you scale your business, you may outgrow our standard reports, and having your own reporting in place is crucial. We strongly recommend that you build out custom reporting that fully encompasses your interactions with Braintree, including all transactions and customers you create.

Sample reporting scriptanchor

This script is a sample of one of many ways that you can generate your own custom reports via the API by:

  • Using the Braintree API to search for all transactions with a particular status
  • Iterating over those results and pulling specific transaction values
  • Adding those details for each transaction to a new row of the output CSV

Remember toanchor

  1. Enter your own API keys
  2. Use the header row fields to define which values you want in the report
  1. Node
const fs = require('fs');
const braintree = require("braintree");
const stream = require('stream');
const readable = require('stream').Readable;
const csvWriter = require('csv-write-stream');
const date = require('date-utils');

const gateway = new braintree.BraintreeGateway({
  environment: braintree.Environment.Sandbox,
  merchantId: "enter merchant ID",
  publicKey: "enter public key",
  privateKey: "enter private key"
});

const today = Date.today();

/*using API for finding a transaction
gateway.transaction.find("transactionID", (err, transaction) => {
  //console.dir(transaction);
  console.log('BT1transaction='+transaction.type+' Amount='+transaction.amount+' Status='+transaction.status+' Mechant account id='+transaction.merchantAccountId
    );
});
*/

/* running throu a search response list from a Search stream
const stream = gateway.transaction.search((search) => {
  search.customerEmail().is("jen@example.com");
}, (err, response) => {
  response.each((err, transaction) => {
    //console.log(transaction.disbursementDetails.settlementAmount);
  });
});
*/

// create the read and write streams
const streambt = gateway.transaction.search((search) => {
    console.log('Todays date: '+today);

    //Use this to find transactions between specic dates
    search.settledAt().between(Date.yesterday(),Date.today());

    //Use this to find transactions for a specific email
    //search.customerEmail().is("jen@example.com");
});

// Use this to find the length of the Stream or no of objects
// before you extract it into a csv
streambt.on("ready", () => {
  console.log(streambt.searchResponse.length());
});

// You can either create a Array of JSON objects for the transactions
let transactions=[];

// or just put the JSON object stream in to stream writer
const writer = csvWriter({ headers: ['id', 'status', 'type']});
writer.pipe(fs.createWriteStream('out.csv'));

streambt.on("data", (transaction) => {
  //console.log(transaction);
  //console.dir(transaction);
  writer.write(transaction);
  transactions.push(transaction);
});

streambt.on("end", () => {
  //console.log(streambt.searchResponse.ids.length);
  writer.end();
  //console.log('transactions length ='+ transactions.length);
  for (let i = transactions.length - 1; i >= 0; i--) {
    console.log(transactions[i].disbursementDetails.settlementAmount);
  };
});

Search limitanchor

Transaction searches return a maximum of 50,000 results; all other searches return a maximum of 10,000 results.

See also