#cristy_code
1 messages ยท Page 1 of 1 (latest)
๐ 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/1331654251604217857
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi ๐ I would strongly recommend rolling that signing secret now that it's been shared publicly.
Taking a look at the rest of the post now.
Do you have an example of a Checkout Session you're using for your testing, can you share the ID of that?
Do you log out the contents of total_details.breakdown.discounts.discount? Is the promotion_code field populated?
if you are reffering to to the webhook id that listens to the checkout session is this
we_1Qk6NOGgYapbIODVqKaqfFS3
yes i did and the promotion_code retrun Null even though the client used a code
I'm not, I'm referring to a specific Checkout Session object. That object should have a cs_ prefix.
where do i get that?
Or if you have the ID of a specific Event (evt_ prefix) that you were trying to process, I can get the session ID from that.
just a sec i am trying to find one of them
evt_1Qk3hPGgYapbIODVDVJTiIeq
sorry
evt_1Qk6VzGgYapbIODVeiyXT1ff
Can you share the full contents of total_details.breakdown.discounts.discount that you see when you log its contents?
Thank you! I'll take a look at that Event
just a sec
The Checkout Session from this Event didn't have any discount.
This one did though, I'll look here instead.
"promotion_code": "promo_1QixULGgYapbIODVh9naj5pD",
Is that the ID you're looking for?
promo_1QixRmGgYapbIODVNyfPFOt2 this one
or that one if it s the case
they are both under the same cuppon
I'm sorry, I'm not sure I'm grasping what you're trying to ask. I was the under the impression that you were looking for the ID of the Promotion Code object that was used, but feel I've misunderstood. Are you looking for something different?
i was asking for the code istelf not the id but i can work with that too
still, why my promotion_code returns None?
Where? It's populated in the output you shared.
oh yes
i see it
but look at the final log
WARNING:root:Promotion code None not found in affiliatecodes table
and
WARNING:root:No promotion code found in the session.
Is that a table in your database? If so, I won't have any insight into its structure or contents and won't be able to answer why the Promotion Code isn't in that table.
It doesn't look like your code looks at discount.promotion_code, you dive into discount.coupon instead.
when i tryed to look in discount.promotion_code i got an error saying i can t get more then 4 breakedowns or something
# Extract discount and promotion code details
total_details = checkout_session.get('total_details', {})
breakdown = total_details.get('breakdown', {})
discounts = breakdown.get('discounts', [])
if not discounts:
logging.warning("No discounts applied to this session.")
for discount in discounts:
# Access discount object, which may contain a coupon
coupon = discount.get('discount', {}).get('coupon', None)
if coupon:
logging.info(f"Found coupon: {coupon}")
# Check if the coupon contains a promotion_code
promotion_code_obj = coupon.get('promotion_code', None)
if promotion_code_obj:
# Access the promotion code inside the coupon
promotion_code = promotion_code_obj.get('code', None)
if promotion_code:
logging.info(f"Found promotion code: {promotion_code}")
break # Found the promo code, break out of the loop
else:
logging.warning("Coupon does not have a promotion code.")
else:
logging.warning("Coupon does not have a promotion_code field.")
# Log additional details about the coupon
logging.info(f"Coupon details: {coupon}")
# For example, log the coupon ID or discount type
logging.info(f"Coupon ID: {coupon.get('id')}")
logging.info(f"Amount Off: {coupon.get('amount_off')}")
logging.info(f"Percent Off: {coupon.get('percent_off')}")
else:
logging.warning("Discount does not contain a coupon.")
if not promotion_code:
logging.warning("No promotion code found in the session.")```
You can't expand that field, because expand can only go four-levels deep. But the ID of the object should still be there.
who i need to modify this line then? coupon = discount.get('discount', {}).get('coupon', None)
You want the details from the promotion_code field, right?
https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-total_details-breakdown-discounts-discount-promotion_code
right
So I think you want to change coupon to promotion_code in that line.
and it should be fine?
That's something you should be able to test and confirm quickly. I'm not as familiar with your code as you are, so I'm not sure if it's that straight forward or if additional changes will need to be made.
i will test it right now
still the same
promotion_code = checkout_session.get('promotion_code', None)
That's not where we discussed looking. The ID of the Promotion Code is in checkout_session.total_details.breakdown.discounts.discount.promotion_code
can you please tell me what exact lines to modify i don t understand ๐ญ
Hello! I'm taking over and catching up...
We can't write your code for you, unfortunately, but Toby pointed out the exact line you need to modify.
This is the API reference for that property on the Checkout Session object: https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-total_details-breakdown-discounts-discount-promotion_code
wait don t close the ticket pls
Okay.
when i am trying to expend like this
total_details.breakdown.discounts.discount.promotion_code
i get this
Unexpected error in webhook: Request req_Ukd7yCirt9ROuS: You cannot expand more than 4 levels of a property. Property: total_details.breakdown.discounts.discount.promotion_code
INFO:werkzeug:127.0.0.1 - - [22/Jan/2025 18:48:43] "POST /webhook HTTP/1.1" 500 -
Right, the error is accurate. You can't expand that. You need to instead retrieve the Promotion Code in a separate request.
That property on the Checkout Session will have the Promotion Code's ID, which you can then use with this API: https://docs.stripe.com/api/promotion_codes/retrieve