#Ruubeh - checkout promo code
1 messages · Page 1 of 1 (latest)
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?
evt_1LJNbKAAKu8uOGKrsI60meD6
Thank you
Am I doing something wrong?
Not necessarily but I do think that the promo code is supposed to show up somewhere else. Looking in to where that is...
i found this but not sure why its not showing
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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
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 😦
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
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:
-
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.
-
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
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
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
Right, that would be a way to do it if you wanted to simulate real-time updates
Alright, then I think ill just schedule the request for every hour👍
Thanks for the help, really appreciate the quick response!:)
@worldly nebula Thank you for asking this. I am in the exact same situation and thought I was losing my mind.
Hey @prime moat and @worldly nebula, apologies for the late reply. I was digging into this a bit more and found a field in the Checkout Session object that has exactly what you're looking for.
~~https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-discounts~~
I made the mistake of searching for "promotion" and "coupon" keywords, and completely overlooked the discounts hash on the Checkout Session
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"?
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.
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
I think you are right. Just came across this:
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-total_details-breakdown-discounts-discount
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I'll take a look at it in the morning
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'],
}
);
No problem👍 , did you manage to get it working?
HI 👋
This thread is somewhat confusing to me (in trying to parse out the conversation). Do you have any questions presently?