Skip to content

Instantly share code, notes, and snippets.

@adamjstevenson
Last active November 3, 2023 13:31
Show Gist options
  • Save adamjstevenson/574eba8acee7c66eff896d449f16bef5 to your computer and use it in GitHub Desktop.
Save adamjstevenson/574eba8acee7c66eff896d449f16bef5 to your computer and use it in GitHub Desktop.
Calculate gross and net transaction volume on a connected account
require 'stripe'
Stripe.api_key = "YOUR-API-KEY"
# Authenticate as the connected account and retrieve the first 100 transactions
transactions = Stripe::BalanceTransaction.list({limit: 100},{stripe_account: "acct_YourConnectedAcctID"})
total_volume = 0
net_volume = 0
# Iterate through transactions using auto-pagination
transactions.auto_paging_each do |txn|
# Sum the total payments volume
if txn.type.eql?('charge')
total_volume += txn.amount
end
# Sum the net transaction volume
net_volume += txn.amount
end
puts "Total volume: #{total_volume}"
puts "Net volume: #{net_volume}"
@inexuscore
Copy link

Thank you for this gist. However, I'm not getting the correct results.
The gross volume (total_volume) is correct, but the net_volume is a bit off.
I'm subtracting total_volume by net_volume, but the result is different than what I see on the Stripe dashboard.
Any ideas on how to calculate the Net volume from sales?
I need to get the gross/net volumes as seen on the Stripe dashboard using the Stripe API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment