#roshe10_code

1 messages ¡ Page 1 of 1 (latest)

lavish carbonBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1467809203354730572

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

paper kindle
#

⁨⁨`func (p *PaymentProvider) GetPaymentReferencesForPayoutID(ctx context.Context, payoutID domain.PaymentProviderPayoutID, orgAccID domain.PaymentProviderOrganisationAccountID) ([]string, error) {
params := &stripe.BalanceTransactionListParams{
Payout: stripe.String(string(payoutID)),
}
params.SetStripeAccount(string(orgAccID))

var paymentIntents []string
for bt, err := range p.sc.V1BalanceTransactions.List(ctx, params) {
    if err != nil {
        return nil, fmt.Errorf("error listing balance transactions for payout %s: %w", payoutID, err)
    }

    if bt.Source == nil || bt.Source.ID == "" || !isRelevantBTType(bt.Type) {
        continue
    }

    intentID, err := p.getPaymentIntentFromChargePayment(ctx, bt.Source.ID, string(orgAccID))
    if err != nil {
        fmt.Printf("warn: %v\n", err)
        continue
    }
    if intentID != "" {
        paymentIntents = append(paymentIntents, intentID)
    }
}

return paymentIntents, nil

}

func (p *PaymentProvider) getPaymentIntentFromChargePayment(ctx context.Context, chargeID, accountID string) (string, error) {
params := &stripe.ChargeRetrieveParams{}
params.SetStripeAccount(accountID)
params.AddExpand("balance_transaction")

chrg, err := p.sc.V1Charges.Retrieve(ctx, chargeID, params)
if err != nil {
    return "", fmt.Errorf("failed to fetch charge (ID: %s): %w", chargeID, err)
}
if chrg.PaymentIntent != nil {
    return chrg.PaymentIntent.ID, nil
}
return "", nil

}`⁊⁊

// We only care about balance transactions of type 'charge' (from cards) or 'payment' (from wire transfers) in the list (those transactions are related to actual donations)
func isRelevantBTType(t stripe.BalanceTransactionType) bool {
return t == stripe.BalanceTransactionTypeCharge || t == stripe.BalanceTransactionTypePayment
}

#

Failing event: evt_1SwB8vPeBLev00TBSkempgIj
Same event with same handler , but different payout, with less charges, goes through without any problems: evt_1SwBRuPU6qwHdB7BWodJL9Te

lavish folio
#

Hi Hapy to help!

#

Could you please share the request Id of the fialure API call ?

paper kindle
#

not sure where can i find the request ID, I'm doing it through code when payout.created event is triggered

lavish folio
#

Firstly, in the event handler, you should respond quickly with 2xx then do your treatment async

paper kindle
#

re quickly 2xx, if i do that, then I will not be able to repeat the event if it fails for some reason like it is failing now ?

yes, I'm doing similar, because after I received balance transactions, I need a way to get payment intent ID, and only way I found I could do it is through charge ID (which i get from source ID like in your link) (getPaymentIntentFromChargePayment)

lavish folio
#

re quickly 2xx, if i do that, then I will not be able to repeat the event if it fails for some reason like it is failing now ?
No, but you shouldn't rely oon stripe webhook for heavy processes

#

You just need to acknowldge the event quickly, then you need to implement internal retries in your integration for heavy batches

#

yes, I'm doing similar, because after I received balance transactions, I need a way to get payment intent ID, and only way I found I could do it is through charge ID (which i get from source ID like in your link) (getPaymentIntentFromChargePayment)
Yes correct

paper kindle
#

okay I see, so we can at least confirm this event failing was due to heavy process, and that's why we got error context cancelled ?

lavish folio
#

Yes that's the only reason I'm seeing for now.

paper kindle
#

okay thank you

#

I have other question, also related to payouts

lavish folio
#

Yes sure, what is it ?

paper kindle
#

payout : po_1Stdk6BSG0C5LgUOBGOVBxB3 was completed at 3am, however it included a transaction: pi_3SrlYiBSG0C5LgUO1WjwqYTW (wire transfer) which succeeded later at 7am same day . I was not expecting it in the payout because I consider payment finalised only after payment succeeded event happend

#

payout.paid evt_1Stg1YBSG0C5LgUOYnyXUTzC
pi_succeded: evt_3SrlYiBSG0C5LgUO1VIT36K2

lavish folio
#

Let me check this further...

paper kindle
#

sure

lavish folio
#

So that Payout was created on the 2026-01-26

#

The payment youw ere referring to was created on 2026-01-20

#

Which is way before the payout creation

paper kindle
#

correct, that's when the payment is created, but isn't payment finalized (money lands) only after its payment intent succeeded (or invoice paid) event happens, which came after payout

#

it was a wire transfer, so how can I now it will not fail - here we 'got lucky' so it succeeded eventually, but it could also fail right ?

lavish carbonBOT
lavish folio
#

Yeah agreed, but no worries if the capture was failed, you'll get regulated in the next payout

#

Stripe handles this automatically

slim depot
#

👋 taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

paper kindle
#

hmm, what does that exactly mean - 'get regulated'? Does it mean if stripe payed out extra $25 in first payout (included not-yet succeeded payment), then payment fails after the initial payout, so in the next payout I will get $25 less than expected which will appear as "fee" (in order to 'get regulated') or ?

slim depot
#

you only get paid out the available balance which only includes succeeded payment that has been in your pending balance for more than the pending payout delay

paper kindle
#

only get paid out the available balance which only includes succeeded payment
hmm, but that's the thing I don't understand, my payout included 'pending', not fully 'succeeded' payment - pi_3SrlYiBSG0C5LgUO1WjwqYTW

slim depot