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. Python
import braintree
from datetime import datetime
from datetime import timedelta
import csv
from collections import OrderedDict

gateway = braintree.BraintreeGateway(
  braintree.Configuration(
    braintree.Environment.Production, # or braintree.Environment.Sandbox
    merchant_id="use_your_merchant_id",
    public_key="use_your_public_key",
    private_key="use_your_private_key"
  )
)

N = 1
date_N_days_ago = datetime.now() - timedelta(days=N)

search_results = gateway.transaction.search(
  braintree.TransactionSearch.created_at.between(
    date_N_days_ago,
    datetime.now()
  ),
  (braintree.TransactionSearch.type == braintree.Transaction.Type.Sale),
  (braintree.TransactionSearch.status == braintree.Transaction.Status.Settled)
)

fieldnames = ['transaction_id', "transaction_type", "transaction_status", "settlement_date",
"merchant_account","amount_submitted_for_settlement", "order_id", "payment_instrument_type",
"credit_card_type", "customer_location", "customer_id", "payment_method_token", "processor_authorization_code",
"paypal_payer_email", "paypal_payment_id", "paypal_authorization_id", "paypal_payer_id" ]

resultFile = open("output.csv", 'wb')

csvwriter = csv.DictWriter(resultFile, delimiter=',', fieldnames=fieldnames)
wr = csv.writer(resultFile, dialect='excel')
csvwriter.writerow(dict((fn,fn) for fn in fieldnames))

for transaction in search_results.items:
  if transaction.payment_instrument_type == "credit_card":
    wr.writerow ([transaction.id, transaction.type, transaction.status, transaction.updated_at, transaction.merchant_account_id, transaction.amount,
      transaction.order_id, transaction.payment_instrument_type, transaction.credit_card_details.card_type,
      transaction.credit_card_details.customer_location, transaction.customer_details.id, transaction.credit_card_details.token,
      transaction.processor_authorization_code]),
  #elif transaction.payment_instrument_type == "paypal":
    #wr.writerow ([transaction.paypal_details.payer_email, transaction.paypal_details.payment_id, transaction.paypal_details.authorization_id,
       #transaction.paypal_details.payer_id])
  #elif transaction.payment_instrucment_type == "apple_pay_card":
    #wr.writerow ([transaction.id, transaction.type, transaction.status, transaction.updated_at, transaction.merchant_account_id, transaction.amount,
      #transaction.order_id, transaction.payment_instrument_type, transaction.credit_card_details.card_type,
      #transaction.credit_card_details.customer_location, transaction.customer_details.id, transaction.credit_card_details.token,
      #transaction.processor_authorization_code])
  else: pass

print "Script Complete"

Search limitanchor

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

See also