Transfer from Refund

27 views
Skip to first unread message

Tim Thomas

unread,
Dec 19, 2016, 7:02:13 PM12/19/16
to api-d...@lists.stripe.com
Hi, 

I've found that I can figure out which transactions a transfer contains, but I can't seem to go the other direction using the API. I'd like to be able to see what transfer a refund is associated with, but can't seem to figure a trivial way to go from refund back up to transfer. Is this possible? I'm iterating over all the transfers right now, which is painful.

Thanks,
Tim Thomas

Remi J.

unread,
Dec 20, 2016, 3:46:51 AM12/20/16
to api-d...@lists.stripe.com
Hey Tim,

There isn't a way to go from a given charge or refund to the transfer that contained it. The only solution is to go the opposite way from the transfer to the list of transactions that are bundled in it.

What I usually recommend is to store that information in your own database for each transfer. The idea is that you listen for the `transfer.created` events on your webhook endpoint and, for each one, you track the list of transactions bundled in it. This allows you to easily find the transfer for a given charge or refund as you have that information already stored. If you haven't tracked this historically, you can go through all your transfers one by one via the API to start tracking it from now on.

Otherwise, when you look at a given transaction, you can see the `available_on` property on the associated balance transaction. Based on this, you know when the funds would be released and you can then look at the transfers that were created around that date. You can then see in the list of associated transactions for one of those transfers whether it contains your transaction (charge, refund, etc.).

Hope this helps!
Remi

--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Michael

unread,
Dec 20, 2016, 8:56:04 AM12/20/16
to Stripe API Discussion
Hey Tim,

As Remi mentioned, you'll need to iterate through the transactions on a transfer to see if it contains the charge/refund. Here's a script outlining how to do this:


Cheers,

Mike

Tim Thomas

unread,
Dec 20, 2016, 9:02:27 AM12/20/16
to api-d...@lists.stripe.com
Ah, the transfer.created is a great idea going forward. This was for a script to populate historical data in my database. Just trying to simplify it. Thanks for the help!

-tim

--
Reply all
Reply to author
Forward
0 new messages