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. Java
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Calendar;
import com.braintreegateway.*;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

class Report {
  public static void main(String[] args) {
    generateCustomReport("./transaction_report.csv");
  }

  private static final Object [] HEADER = {"id", "type", "amount", "status", "created_at", "service_fee_amount", "merchant_account_id"};

  private static void generateCustomReport(String fileName) {
    FileWriter writer = null;
    CSVPrinter csv = null;

    CSVFormat csvFormat = CSVFormat.DEFAULT.withRecordSeparator("
");

    try {
      writer = new FileWriter(fileName);
      csv = new CSVPrinter(writer, csvFormat);

      csv.printRecord(HEADER);

      Calendar dates = Calendar.getInstance();
      dates.add(Calendar.DATE, -1); // a day ago
      ResourceCollection<Transaction> collectionOfTransactions = getTransactions(dates);

      for (Transaction transaction : collectionOfTransactions) {
        List transactionData = getTransactionData(transaction);
        csv.printRecord(transactionData);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        writer.flush();
        writer.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

  private static ResourceCollection<Transaction> getTransactions(Calendar dates) {
    BraintreeGateway gateway = new BraintreeGateway(
      Environment.[choose SANDBOX or PRODUCTION],
      "[enter merchant ID]",
      "[enter public key]",
      "[enter private key]"
    );

    TransactionSearchRequest request = new TransactionSearchRequest()
      .settledAt()
      .greaterThanOrEqualTo(dates);

    ResourceCollection<Transaction> collection = gateway
      .transaction()
      .search(request);

    return collection;
  }

  private static List getTransactionData(Transaction transaction) {
    List<String> transactionData = new ArrayList<String>();

    transactionData.add(String.valueOf(transaction.getId()));
    transactionData.add(String.valueOf(transaction.getType()));
    transactionData.add(String.valueOf(transaction.getStatus()));
    transactionData.add(String.valueOf(transaction.getCreatedAt().getTime()));
    transactionData.add(String.valueOf(transaction.getServiceFeeAmount()));
    transactionData.add(String.valueOf(transaction.getMerchantAccountId()));

    return transactionData;
  }
}

Search limitanchor

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

See also