#Ruubeh - checkout promo code

1 messages · Page 1 of 1 (latest)

sharp dagger
#

Interesting, can you send me the ID of an event that you didn't see the promo code on so that I can check it out?

worldly nebula
#

evt_1LJNbKAAKu8uOGKrsI60meD6

sharp dagger
#

Thank you

worldly nebula
#

Am I doing something wrong?

sharp dagger
#

Not necessarily but I do think that the promo code is supposed to show up somewhere else. Looking in to where that is...

worldly nebula
#

i found this but not sure why its not showing

sharp dagger
#

I think that that is how to pre-set a promotion code but there is somewhere else to look for when the user puts in a promotion code while checking out

worldly nebula
#

ah yea thats right, I need to access the promotion-code in the webhook

#

thought it would be included if u set allow_promotion_codes: true

#

but it's not 😦

sharp dagger
#

Yeah apparently not. I unfortunately haven't been able to find this yet. Can you tell me more about what you are trying to do here? If this is something like logging how many times a specific code has been used we do have an event more directly for that.

#

Though I am sure we can find it based on Checkout Session as well. Just making sure we are answering the right question

#

Also I am stepping out but my colleague @limber oxide can help you from here

worldly nebula
#

I created a webapp that has one-time payments, for promotion purposes i created an Affiliate platform. A promoter gets an account and a promo-code, every time their promo-code is used i want to increase their counter in the dashboard with graphs etc

I had two options in mind:

  1. Get the promocode used from the webhook. This was I can get the specific code used and the timet that is has been used so that i can store it with the time.

  2. The other way might be to access the promocode from the stripe API and keep checking the "times_used" info. This could work but then i dont have the time

#

I wanted to use the time also so that I could give the promoters a nice graph with timeline and amounts

limber oxide
#

I don't think it's possible to get this data via the checkout.session.succeeded event. Since you only use Payment Intents. (not Invoices or Subscriptions) there is no field on any of the relevant objects that would associate with the promotion as far as I can tell

worldly nebula
#

ah oke, so the only way might be to access the promo-code object let's say once an hour or so and keep track of the "times_used" integer that way?

#

since im using one-time payments only

limber oxide
#

Right, that would be a way to do it if you wanted to simulate real-time updates

worldly nebula
#

Alright, then I think ill just schedule the request for every hour👍

#

Thanks for the help, really appreciate the quick response!:)

prime moat
#

@worldly nebula Thank you for asking this. I am in the exact same situation and thought I was losing my mind.

limber oxide
#

I made the mistake of searching for "promotion" and "coupon" keywords, and completely overlooked the discounts hash on the Checkout Session

worldly nebula
#

Heyy thanks for the reply:) I came across that one in the docs, but I thought it was only for setting it when creating a checkout session. Or does it only show in the checkout.session.completed if you set the promocode this way instead of only setting the "allow_promotion_codes: true"?

limber oxide
#

Ugh, I posted the wrong link.

So the total_details hash will auto-populate with discount information if a promotion code or coupon is used during the Checkout Session.

worldly nebula
#

The total_details does show some discount info. But it's pretty limited.

"total_details": {
"amount_discount": 449,
"amount_shipping": 0,
"amount_tax": 0
},
It only includes the amounts, but not the specific promo code id etc

worldly nebula
#

I'll take a look at it in the morning

worldly nebula
#

You can retrieve the promotion from the session object by expanding it. Actually this cannot be done in the checkout.session.completed object since the event objects are always as compact as possible.

To retrieve the promotion id you can retrieve the expanded session object by fetching it in your webhook handler.

const session = await stripe.checkout.sessions.retrieve(
'cs_test_KdjLtDPfAjT1gq374DMZ3rHmZ9OoSlGRhyz8yTypH76KpN4JXkQpD2G0',
{
expand: ['breakdown'],
}
);

worldly nebula
ionic current
#

HI 👋
This thread is somewhat confusing to me (in trying to parse out the conversation). Do you have any questions presently?

worldly nebula
#

No sorry, we had some problems retrieving the promocode that is used during checkout

#

I got everything working now, I was just wondering if Bjorn also managed it, if not I could show him how I did it