Dheer
Dheer

Reputation: 793

Fetch transactions from Stripe::Transfer with latest stripe version

I am using stripe latest version in production.

When I try to fetch transactions:

Stripe::Transfer.all.first.transactions

I fount, there is no transactions method for latest Stripe::Transfer

 undefined method `transactions' for #<Stripe::Transfer

Stripe API is upgrades: 2014-08-04

The transactions, summary, and other_transfers properties in automatic transfer responses have been removed in favor of the balance history endpoint (/v1/balance/history), which can be called with the transfer id (using the ?transfer= parameter) to filter transactions by transfer.

So How we fetch transactions from Stripe transfer ?

But its working fine with Stripe old version.

Upvotes: 0

Views: 434

Answers (1)

cyberwombat
cyberwombat

Reputation: 40104

You have a couple of options depending on what you want. If you a certain level of detail for charges you can fetch all the charges associated with a transfer which will fetch only that:

var options = {};
stripe.transfers.listTransactions(id, options);

If, on the other hand, you would like something more akin to the old summary object then I would get the balances associated with the transfer:

var options =  { transfer: id };
stripe.balance.listTransactions(options);

The balances returned will contain a variety of balance types - the first one refers to the actual transfer as a whole and can be ignored and the rest is a combo of charges, refunds, adjustments, etc including the fees for each.

In both the above cases id refers to the transfer ID. Note that you will need to loop through these to fetch all items - this can be done in a couple of ways as listed under Pagination. In the above cases, I check if the result contains the has_more: true field and, if so, loop through again using the starting_after: X addecd to the options object where X is the ID of the last charge/balance returned on previous call.

Upvotes: 1

Related Questions