#Kalluste

1 messages ยท Page 1 of 1 (latest)

tiny capeBOT
alpine magnet
#

that is the normal and correct way

twilit lantern
#

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.

alpine magnet
#

yes

twilit lantern
#

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?

alpine magnet
#

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 account property. It identifies the account that the webhook is sent to and the data[object] it belongs to

twilit lantern
#

Okay! I'll check it out! ๐Ÿ™‚

#

thanks

twilit lantern
#

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?

alpine magnet
#

you shouldn't pass anything to those parameters yourself really

#

just use the auto-pagination built into our libraries

twilit lantern
#

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?

alpine magnet
#

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

tiny capeBOT
twilit lantern
#

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

visual nebula
#

๐Ÿ‘‹ stepping

alpine magnet
#

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

twilit lantern
#

Do I understand correctly that this would be correct syntax?

const allInvoices = await stripe.invoices.list({limit: 100}).autoPagingToArray({limit: 10000});

alpine magnet
#

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.

twilit lantern
#

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});

alpine magnet
#

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.

twilit lantern
#

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 });

alpine magnet
#

yes something like that seems decent

twilit lantern
#

cool, thank you!

alpine magnet
#

gotta run for now but @visual nebula can help with anything else