#DaanVDH

1 messages ยท Page 1 of 1 (latest)

lyric pastureBOT
pine raven
#

๐Ÿ‘‹ happy to help

#

any more context?

dawn cypress
#

This function adds the refundId as MetaData to the paymentIntent and then creates a refund for the same paymentIntent in that order

#

but the problem is the refund goes trough before the paymentIntent is updated

#

so when my webhook tries to get the refundId from the MetaData it's not there yet

#

and the webhook fails

pine raven
#

why not add the metadata to the refund itself

#

and in your webhook you get the metadata and update the PI if it's really necessary for you

dawn cypress
#

Let me try it for a second

pine raven
#

yes sure

lyric pastureBOT
dawn cypress
#

So this would be the way to get the last refund from the pi right: go refundId, err := uuid.Parse(pi.LatestCharge.Refunds.Data[0].Metadata["refundId"])

#

and parsing it in my case

lament flame
#

๐Ÿ‘‹ stepping in

dawn cypress
#

Hi

lament flame
#

Yep that looks right to me

#

Are you expanding refunds?

dawn cypress
#

This is the whole func:

func (s service) GetRefundIdForPaymentIntent(pid string, accountId string) (uuid.UUID, error) {
    params := &stripe.PaymentIntentParams{}
    params.AddExpand("latest_charge.balance_transaction")
    params.SetStripeAccount(accountId)

    pi, err := paymentintent.Get(pid, params)
    if err != nil {
        return uuid.Nil, nil
    }

    refundId, err := uuid.Parse(pi.LatestCharge.Refunds.Data[0].Metadata["refundId"])
    if err != nil {
        return uuid.Nil, nil
    }
    return refundId, nil
}
#

Ohh i think i need to change it to: latest_charge.refunds right?

lament flame
#

Yeah looks like you are just expanding latest_charge.balance_transaction so you want to also expand latest_charge.refunds

#

You can either change it or expand both

#

Depends if you are going to want the balance transaction info

dawn cypress
#

No, refunds is all i need for this function