#cristy_code

1 messages ยท Page 1 of 1 (latest)

graceful thornBOT
#

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

jovial forum
#

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.

celest frost
#

is not the full code

jovial forum
#

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?

celest frost
celest frost
jovial forum
jovial forum
#

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.

celest frost
#

just a sec i am trying to find one of them

#

evt_1Qk3hPGgYapbIODVDVJTiIeq

#

sorry

#

evt_1Qk6VzGgYapbIODVeiyXT1ff

jovial forum
#

Thank you! I'll take a look at that Event

jovial forum
jovial forum
jovial forum
#

"promotion_code": "promo_1QixULGgYapbIODVh9naj5pD",
Is that the ID you're looking for?

celest frost
#

promo_1QixRmGgYapbIODVNyfPFOt2 this one

#

or that one if it s the case

#

they are both under the same cuppon

jovial forum
#

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?

celest frost
#

i was asking for the code istelf not the id but i can work with that too

#

still, why my promotion_code returns None?

jovial forum
#

Where? It's populated in the output you shared.

celest frost
#

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.

jovial forum
#

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.

celest frost
#

when i tryed to look in discount.promotion_code i got an error saying i can t get more then 4 breakedowns or something

jovial forum
#
        
        # 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.

celest frost
#

who i need to modify this line then? coupon = discount.get('discount', {}).get('coupon', None)

jovial forum
jovial forum
#

So I think you want to change coupon to promotion_code in that line.

celest frost
#

and it should be fine?

jovial forum
#

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.

celest frost
#

i will test it right now

graceful thornBOT
celest frost
jovial forum
#

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

celest frost
#

can you please tell me what exact lines to modify i don t understand ๐Ÿ˜ญ

cold acorn
#

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.

celest frost
#

wait don t close the ticket pls

cold acorn
#

Okay.

celest frost
#

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 -

cold acorn
#

Right, the error is accurate. You can't expand that. You need to instead retrieve the Promotion Code in a separate request.

celest frost
#

so:
stripe.PromotionCode.retrieve(" ")
?

#

nvm i made it work

#

finally

#

thank you so much