#Kalluste
1 messages ยท Page 1 of 1 (latest)
that is the normal and correct way
it's explained in https://stripe.com/docs/expand/use-cases#charges-in-payout
you listen to payout.created and then can list related BalanceTransactions to trace back and know that certain payments were in that payout
the alternatives would be to use the reporting API https://stripe.com/docs/reports/payout-reconciliation
Okay, I see that if I list balance transactions I can set the expand to "data.source.source_transfer.source_transaction" and then get the original payment intent ID from there.
yes
thats great! Thank you for the fast reply and information! ๐
But when a payout.created webhook arrives I need to know which connected account this payout is related to. Thats necessary to then fetch the balance transactions connected to that payout with the Stripe-Account parameter.
How can I get data about the connected account ID when the payout webhook is sent to me?
it's in the webhook
https://stripe.com/docs/connect/webhooks
As we state in the event object reference, each event for a connected account also contains a top-level
accountproperty. It identifies the account that the webhook is sent to and the data[object] it belongs to
When fetching balance transactions then what should be entered in the starting_after parameter when trying to paginate? It's difficult to test with more than 100 transactions and that's why I'm asking ๐
first of all I should check if the "has_more" property is true and then enter the ID of the last balance transaction to starting_after?
you shouldn't pass anything to those parameters yourself really
just use the auto-pagination built into our libraries
So I just make a request like:
const payoutTransactions = await this.stripe.balanceTransactions.list(
{
payout: stripePayoutId,
expand: ['data.source.source_transfer.source_transaction'],
},
{
stripeAccount: stripeAccountId,
},
);
And then it will return more than 100 rows?
no;
you would do more like
// Do something with balanceTransaction
});
the function will be called for each matching balancetransaction regardless of how many there are including if there's more than 100
you can use the for await syntax too, should work fine I just haven't used it much myself in my own code https://stripe.com/docs/api/pagination/auto?lang=node
My main concern here is that isn't the library then making a ton of requests to stripe? If there are for example 1000 balance transactions then I would like my code to make 10 requests to stripe each having 100 balance transactions
my question basically is what is the most optimal way in node to get an array of 1000 balance transactions
๐ stepping
yes but that's not a concern really
that's normal and it's what we would like โ it's better for our system to have multiple smaller requests than one really large one which could timeout trying to generate the response
Do I understand correctly that this would be correct syntax?
const allInvoices = await stripe.invoices.list({limit: 100}).autoPagingToArray({limit: 10000});
best way is to not try to have an array like that, instead try to build it to 'stream' things where you process each balancetransaction independently.
I didn't know that (https://github.com/stripe/stripe-node/blob/c384675a/README.md#autopagingtoarray) existed actually, but you could use that too
obviously the problem is if you have a payout with many transactions in it, that might not fit into the limit you set, so the 'streaming' approach is more robust. But maybe I'm overthinking it.
yeah, thats a good point. Although since I'm saving that data to my DB then streaming isn't a good option since it would create too many DB roundTrips.
I think this would work but I'll just set the limit to a smaller number. So that each request would fetch for example 10 balance transactions and the total could be set to a larger number
const allInvoices = await stripe.invoices.list({limit: 100}).autoPagingToArray({limit: 10000});
I'd recommend not bothering to set the first limit( the one to the list command)
just leave it at the default. There's a non-trivial chance of requests that pass the maximum 100 limit timing out on our end at the database layer
so we prefer that integrations make multiple requests for smaller 'pages' of data. It doesn't matter at the end of the day, you'll get the exact same information returned to your code, best to leave that page size as an implementation detail of the SDK.
Okay, good point!
I ended up with this piece of code
const payoutTransactions = await this.stripe.balanceTransactions
.list(
{
payout: stripePayoutId,
expand: ['data.source.source_transfer.source_transaction'],
},
{
stripeAccount: stripeAccountId,
},
)
.autoPagingToArray({ limit: 10000 });
yes something like that seems decent
cool, thank you!
gotta run for now but @visual nebula can help with anything else