Last active
February 16, 2023 03:43
-
-
Save iloveitaly/e7958e5f55136928f082 to your computer and use it in GitHub Desktop.
Find Stripe transfer associated with charge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Michael Bianco <[email protected]> | |
# Description: Find Stripe transfer (payout) associated with charge (payment) | |
require 'stripe' | |
Stripe.api_key = 'sk_test' | |
# NOTE `auto_paging_each` requires a recent stripe ruby gem version | |
def stripe_transfer_containing_charge(stripe_charge, limit: 100) | |
txn = stripe_charge.balance_transaction | |
Stripe::Transfer.list({ limit: 100, created: { gt: stripe_charge.created }}).auto_paging_each do |transfer| | |
Stripe::BalanceTransaction.list({ limit: 100, transfer: transfer.id }).auto_paging_each do |bt| | |
if bt.id == stripe_charge.balance_transaction | |
return transfer | |
end | |
end | |
limit -= 1 | |
if limit < 0 | |
return nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment