#hoyong_webhooks
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- hoyong_webhooks, 1 day ago, 10 messages
- hoyong_webhooks, 2 days ago, 6 messages
- hoyong_webhooks, 3 days ago, 29 messages
๐ 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/1235695629066436629
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there!
Not quite sure I follow what you've already attempted. Any action taken against a Stripe object (regardless of whether it occurred via the API or the Dashboard) will trigger an event. It's not possible to turn off events for actions taken via the Dashboard
I see. there is no. way I can specify the source (either API or the dashboard).
Correct. I think you likely want to review your webhook handler code in this case.
When a refund happens through my website, it will call a backend service method to update my database and update Stripe
I'm interpreting this as when a customer requests a refund, you have some code to call the Stripe API to process that refund and also update your database.
Then, when stripe gets updated, it will trigger a webhook that will again try to update my db again.
I assume this means you have some webhook handler code that listens forcharge.refunded?
correct
So, I am currently delaying the webhook method for 10 seconds to make sure my db gets updated first. But, I don't think this is the best way to handle this
Also, there are partial payment options that it could possibly refund twice.
And to prevent, I am checking the updated_at to make sure this isn't being updated within 30 seconds
but, all these feels wrong as I am writing lol
SO, I want an expert's advice
๐
Gotcha. Yeah, I think you likely want to adjust your handler code a bit. Perhaps when you call the Stripe API, you use the Refund ID we return to update your database to include the Refund object ID and log its status. Then, when you receive the charge.refunded event, you make a separate call to retrieve the Charge and inspect its refunds list: https://docs.stripe.com/api/charges/object#charge_object-refunds
If the Refund in your database is found in that list and the status of that Refund is the same as in your database, no action is needed
Actually, a separate call to retrieve the Charge shouldn't be needed. You should just be able to inspect the contents of charge.refunds when you receive the Charge object in the charge.refunded event
Okay this is really helpful. So, I can retrieve the refund object from charge.refunded event.
And I should be able to directly compare the object
charge.refunds will contain Refund ID(s) if the Charge has been refunded before but if you need to retrieve some other details about the Refund objects, you'll need to make a follow-up call to retrieve each of those Refunds or make a follow-up call to retrieve the Charge and expand the items you need for the Refunds
Okay. Sounds good. Let me try that. Thanks a lot
I have another question regarding payment_intent object
Go for it
is there a way for me to get the payment method?
That is used to complete the PI?
Yep! If you're listening for payment_intent.succeeded events, that payload will include a PaymentIntent object
Yep, you found it! Within that event payload, you can inspect the PaymentIntent's payment_method. It'll just be a PaymentMethod ID so, if you need more details about that PaymentMethod, you will need to make a call to retrieve the PaymentIntent and expand the payment_method: https://docs.stripe.com/api/expanding_objects
What are you trying to do exactly? Can you share more of your screen/code?
I am just testing to see if I can get the refund ID or object from the charge.refunded event
and this is from a break point I made in the code
charge = event.data.object
and I got the noMethodError when I do charge.refunds
I think this is a syntax issue since refunds is a list that contains data, which is an array of objects
The event.data.object is the charge object from charge.refunded event. Right?
Correct
Can you share the Event ID you're looking at? I know we changed how we return refunds for a Charge in a recent API version
No, that shouldn't matter
Okay, I see what's going on.
Your local listener is receiving events using the API version 2023-10-16. This is your account's default version. In this version, we don't auto expand refunds on Charge objects. This means you'll need to make a follow-up call to retrieve the Charge from that charge.refunded event and expand refunds
oh.. do you know how I can access to the latest version then?
The latest version (2024-04-10) doesn't auto expand refunds on Charge objects either. This was a change we made in a much earlier version: https://docs.stripe.com/upgrades#2022-11-15
oh I see.. That's bummer. I feel like webhook is not the place to make followup api calls. Don't you think?
You can make a separate call if you need to retrieve additional information. I think a better approach would be to receive charge.refunded and inspect amount_refunded. If this amount is different than what you've stored in your database based on that Refund create call you made, you can make a follow-up call to list all Refunds for that specific Charge: https://docs.stripe.com/api/refunds/list