#evan_webhooks

1 messages ยท Page 1 of 1 (latest)

bright muskBOT
#

๐Ÿ‘‹ 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/1311362251508416522

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

vernal groveBOT
lusty hull
#

Hi there ๐Ÿ‘‹ taking a closer look. Just making sure I'm understanding correctly, the Events you shared are ones you want to be notified of, where times_redeemed is being updated, but you aren't receiving those?

surreal void
#

No, those were a couple of events where I modified metadata in the events and received updates

lusty hull
#

Hm, odd, I don't see metadata in the previous_attributes hash showing that value was updated.

surreal void
#

that one was the coupon becoming invalid, my mistake!

lusty hull
#

In the second event you shared, times_redeemed is the only field in the previous_attributes hash.

surreal void
#

oh sorry

lusty hull
#
surreal void
#

I may be losing my mind, let me retest

#

Okay, I just completed a checkout session with this promo code: promo_1QPnRIQ79oA3rs3e6V9QyOB2

Checkout session is this event: evt_1QPnwFQ79oA3rs3eAyNipdnc

#

I don't see any update events on the promo code for times redeemed

lusty hull
#

Hm, I'm still seeing times_redeemed on the Promo Code is 0, are you seeing the same?

surreal void
#

I see it as 1 in my dashboard!

lusty hull
#

I'm not sure offhand if that is because it takes a bit for us to aggregate the usage and generate events, or if it's because the promo code was provided in the session creation request rather than being input on the checkout UI.

surreal void
lusty hull
#

Hm, okay, let me refresh my side again

#

If you retrieve the Promo Code form the API, what is times_redeemed set to? Trying to sus out whether this could be a difference in dashboard behavior vs API behavior.

surreal void
#

Sorry stepped away for a moment, let me check that now

#

1 in the API as well!

#

I'm passing the promotion code to the checkout session, do you think it could be different if I pass the coupon to the checkout session instead?

#

time redeemed event just came through! evt_1QPoFcQ79oA3rs3eXNbv1djQ

#

did you give something a poke or is it potentially delayed 20 mins??

lusty hull
#

I didn't change anything

#

I'm asking teammates if there is a known delay for these

surreal void
#

thanks!

#

I also did not receive that event to my local webhook yet

#

I did actually

bright muskBOT
surreal void
#

FYI, I just tested a checkout session passing in a coupon instead of a promo code and the coupon.updated event fired immediately

civic arch
#

Hi there taking over

#

Catching up on context

surreal void
#

some more context ๐Ÿ™ˆ the coupon had only 1 max redemption and when I redeemed it the webhook fired immediately. I just tested using a coupon code where the max redemptions was 2, and the first redemption hasn't fired an updated webhook yet (~ 1 min ago)

#

so, I think the same thing is happening

lusty hull
#

Can you share the Event that was generated immediately? I'm finding that it's expected for there to be a delay in Events where just times_redeemed is upated, as those are handled asynchronously.

I suspect in the Event that fired immediately, valid also changed since the Coupon hit its max redemption limit.

surreal void
#

you're correct it updated the valid field, here's the event: evt_1QPoTcQ79oA3rs3euOvANfC4

lusty hull
#

Yup, I see the same. So in short, if times_redeemed is the only field being updated, coupon.updated and promotion_code.updated Events may not be generated immediately.

surreal void
#

frustrating, but thanks for clarifying

#

Can you clarify another behavior? When the final promo code is redeemed (which is also the final coupon code) only the coupon sends an updated event

#

Here's the promo code: promo_1QPohwQ79oA3rs3enDt9R8UD

#

It only has the created event (so far)

#

but the API is showing it as active: false

#

only the coupon got an updated event: evt_1QPoiyQ79oA3rs3eaRYdfWYx

lusty hull
#

I'm not sure what exaclty is expected to happen there

surreal void
#

no problem

#

one more question

#

Is there a way to figure out the coupon used in the checkout session completion? I can just pull the latest coupon information in those webhook events, but I don't see the data in the webhook event data

#

Here's an example where I used a couponId in the discounts: evt_1QPoiuQ79oA3rs3eso0pg3mg

lusty hull
#

That's exactly what I was looking into as well, but wasn't readily spotting the information.

Since line_items aren't included by default, you'll at least have to make a request to retrieve the Checkout Session's line items:
https://docs.stripe.com/api/checkout/sessions/line_items
or retrieve the session and use expand to expand line_items
https://docs.stripe.com/api/checkout/sessions/object
https://docs.stripe.com/api/expanding_objects

I'm working on running a test to see if discounts is included by default, or if you have to use expand to get those details as well.

#

Looks like you have to use expand for discounts too. Can you try retrieving that session, and use expand to expand line_items.data.discounts?

surreal void
#

got it!

lusty hull
#

Yess!!

surreal void
#

Okay, so I think I'm covered then:

  • Monitor coupon updates for "valid" to reflect in my database
  • On checkout sessions expand discounts to get the coupon ID, and retrieve the latest to check validity & times_redeemed
#

I suppose I could just always use the checkout session and skip the webhooks? Feels better to still handle the coupon webhooks though

lusty hull
#

Yup, if I were in your shoes, I'd ingest all of the Events. If the state of the coupon or promo code on your side already match, or are more recent, than those contained in the promotion_code.updated or coupon.updated Events then I'd just treat them as a no-op.

surreal void
#

If by no-op you mean blindly update the database with the latest data every time then we're on the same page

#

lol

#

Thanks for all the help!

#

This has been the first corner of the stripe API that didn't just work as I expected

lusty hull
#

Haha, I meant no-op = no operation, as in if the data you have in your db seems newer than what's in the Event, you just throw away the Event contents.

surreal void
#

do these convos flow into API feedback and is my use case clear?

lusty hull
#

They don't automatically, and my understanding is that this flow was actually updated from synchronous to asynchronous to close another gap, so I'm not sure we'd see it change back.

surreal void
#

yeah I'd guess large volumes of coupon redemptions would create quite a bit of load

#

but, I also don't seem to be getting promo_code.updated when it's no longer active

#

and it's not clearly documented

surreal void
#

ah, fair enough!

#

I think I'm solved for my integration so I'll let you get on with it lol