Skip to content

Instantly share code, notes, and snippets.

@cairesr
Last active June 29, 2018 19:04
Show Gist options
  • Save cairesr/d5ef53221fb1c56db85cfe05e6280656 to your computer and use it in GitHub Desktop.
Save cairesr/d5ef53221fb1c56db85cfe05e6280656 to your computer and use it in GitHub Desktop.
Stripe API: List of Charges by Payout
def retrieve_charges_from_payout(payout_id, stripe_custom_account)
payout = Stripe::Payout.retrieve(payout_id, stripe_account: stripe_custom_account)
balance_transaction = Stripe::BalanceTransaction.retrieve(
payout.balance_transaction, stripe_account: stripe_custom_account
)
balance_transaction_list = Stripe::BalanceTransaction.list(
{payout: payout_id},
stripe_account: stripe_custom_account
)
payment_transactions = balance_transaction_list.select do |trans|
trans.source.match /^py_/ # will match only payments
end
payment_transactions.map do |payment_transaction|
payment = Stripe::Charge.retrieve(payment_transaction.source, stripe_account: stripe_custom_account)
Stripe::Transfer.retrieve(payment.source_transfer).source_transaction
end
end
retrieve_charges_from_payout('po_00000000000', 'acct_0000000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment