#themacproguy_webhooks

1 messages ¡ Page 1 of 1 (latest)

wraith auroraBOT
#

👋 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/1240747561497792643

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

tame notch
#

So this has fired the payment_intent.succeeded, charge.refunded, and charge.refund.updated events but it did not create a refund.created event even though a refund object was created.

#

Essentially, I am trying to get notified of the refund ID. It appears charge.refunded doesn't have this exposed but for some reason charge.refund.updated does?

fathom oracle
tame notch
#

Ah, disregard. I found it buried in the docs that refund.created is fired for cash balances.

#

So when receiving the charge.refunded event, what is the recomened way to get the refund ID that its referring to?

fathom oracle
#

You can retrieve the charge object after you get charge.refunded and expand refunds if that's needed

tame notch
#

But obviously, expanding the refunds on the charge object would list all when I am trying to only figure out which it is notifying me about. IE if I refund more than once on a single charge

fathom oracle
#

They'll be listed in creation order, so the newest one should be the first entry

tame notch
#

Playing devils advocate here, lets say things got backlogged (ie the webhook ingestion on my end fails for a few days, etc) and more than one was created. I would now have to check each record in the expanded refunds to see if exists within our reconciliation map. Is there not a webhook event that would return something that would give me the refund object ID when it is created?

#

For example, charge.refund.updated provides the refund object in question where as there is no charge.refund.created

fathom oracle
#

No not necessarily, but does that charge.refund.updated event not do that for you?

tame notch
#

That doesn't get fired on creation

#

In test it does because test immediately updates it with an ARN, but in production, that could either not happen at all or be extremely delayed.

fathom oracle
tame notch
#

Example from production - three charge.refunded events but not charge.refund.updated

#

So, I thought of that and we are acutally going to be using the metadata in case our mapping ever explodes but this still seems like a short coming on Stripe's end. It very much seems there either needs to be a charge.refund.created event or refund.created shouldn't be related to cash balances

#

Like I said, looking for a simpler way to get the underlying re_ ID tied to the event.

#

Yes, iterating over a short list could work but that would add edge cases if a refund was purposefully ignored/deleted out, it would rediscover it

#

Even though this probably won't turn into anything, can this become a feature request? Its a PITA when there is an event that returns what I need but only for updates, not creates.

fathom oracle
#

Yep, going to file feedback about this, i agree we should make it easier

#

Except where you are creating multiple refunds in close succession, retrieving the Charge with refunds expands and looking at the first entry would be the way to get the "new" refund

tame notch
#

Yeah, I am probably going to pluck the created timestamp on all of them and diff it and pick the closest one to the event timestamp

#

A lot of extra work but that should give me the correct one (assuming I dont refund one charge twice in the same second, which I hope not).

#

Just a quick side question, any way to get the application ID (ca_) that created a refund. I know they have it on the charge but was curious if something like that for refunds exists.

fathom oracle
#

Hmm no i don't think that would be exposed. Can you explain the use case?

#

One workaround you could explore, but which I don't really recommend, is setting up a webhook endpoint using an older API version (before 2022-11-15) to get charge.refunded events, since these would have refunds included and you can see the newest one in-line. This could be difficult or impossible depending on your integration, though.

tame notch
tame notch
# fathom oracle Hmm no i don't think that would be exposed. Can you explain the use case?

So we have multiple different sources for payments. Shopify, Terminal, and Twilio. We need all these to map with our Acumatica (ERP) transactions so we can ensure things get reconcilied. I use the application field on the payment intent right now to determine the source of a transaction. Sadly, our finance team is a bit special and sometimes on Shopify transactions, wont use Shopify to create the refund

#

So the refund could potentially not be reflected in Shopify.

#

Hence I was hoping the application ID was exposed as Shopify and Twilio both give an application ID on their transactions.

#
private function findReferencedRefund(Stripe\Event $stripeEvent, Stripe\Charge $stripeSdkCharge): ?Stripe\Refund
{
    $foundRefund = null;

    foreach ($stripeSdkCharge->refunds->autoPagingIterator() as $refund) {
        /** @var Stripe\Refund $refund */
        if (
            !$foundRefund ||
            abs($stripeEvent->created - $refund->created) < abs($stripeEvent->created - $foundRefund->created)
        ) {
            $foundRefund = $refund;
        }
    }

    return $foundRefund;
}
#

This is essentially what I ended up created. It just will have some issues with refunds that happen within the same second (which again, hopefully will be never)