#some1-coupon-error

1 messages · Page 1 of 1 (latest)

autumn solarBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

ionic venture
#

Sorry discord got busy suddenly but looking

rough cobalt
#

no worries

ionic venture
#

Okay do you have a request id req_123 or the Coupon id co_123 for me to look at it?

rough cobalt
#

req_KfI2HH60AfEaCl

ionic venture
#

some1-coupon-error

#

Hum that is not a PromotionCode creation request at all right? That is a request id for an API Request made by Checkout

rough cobalt
#

yes which i thought that was strange too. But it originates from my webhook. Here is the coupons I am using: D1JjuzlM and hS1WFhyv

autumn solarBOT
ionic venture
#

I'm sorry what does "it originates from my webhook" mean?
Can you please try and provide a lot more details?

rough cobalt
#

if event.type == 'payment_intent.succeeded':

customer_id = event.data.object.customer
customer_email = event.data.object.receipt_email
payment_intent_id =  event.data.object.id
checkout_session = stripe.checkout.Session.list(payment_intent=payment_intent_id,expand=["data.line_items",]).auto_paging_iter()

    if product_description == 'Monthly Gift Card':

        promotion_codes = []

        for y in range(quantity):
            promotion_code = stripe.PromotionCode.create(
                coupon=settings.STRIPE_MONTHLY_COUPON_ID,
                customer=None, #customer=customer_id,  
                active=True,  
                max_redemptions=1,
                metadata={
                    'monthly_price_id': settings.STRIPE_MONTHLY_PRICE_ID, 
                    'product_type': 'Monthly', 
                },
            )
            print(promotion_code.code)
#

checkout_session = stripe.checkout.Session.create(
success_url=request.build_absolute_uri(reverse('giftcards:stripe_success')) + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=request.build_absolute_uri(reverse('giftcards:stripe_cancelled')),
payment_method_options={
"us_bank_account": {
"financial_connections": {"permissions": ["payment_method", "balances", "ownership", "transactions"]},
},
},
customer=customer_id,
mode='payment',
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': yearly_price_amount,
'product_data': {
'name': 'Yearly Gift Card',
},
},
'quantity':quantity,
}],
phone_number_collection={
'enabled': True,
},
)

sleek wing
#

And which request in that code is getting an error?

rough cobalt
#

a successful checkout session. I want to create a promo code to give the user since they are buying it

#

my terminal says it fails here:

stripe_payment_intent_success_webhook
promotion_code = stripe.PromotionCode.create(

sleek wing
#

What error do you get from that call?

#

Can you send the request ID of one of those calls where you are getting this error?

rough cobalt
#

see my first message in the thread, it is an unclear message

#

all it says is contact stripe in the terminal. I had to do digging in the dashboard to find any request id

sleek wing
#

That isn't the stripe error code though, looking for the message that our API sends back.

rough cobalt
#

Do i look in developer logs or under webhooks?

sleek wing
#

developer logs

#

Specifically look for a call to /v1/promotion_codes

rough cobalt
#

i don't see one at all...

#
#

i just re-ran it again so those are the most recent

sleek wing
#

Can you give me the exact parameters that you are setting when making that call? The code looks like it is properly formatted at first glance. If you aren't seeing any calls to that endpoint, the call may be failing on your server before it even reaches out to Stripe

rough cobalt
#

stripe.PromotionCode.create(
coupon=settings.STRIPE_MONTHLY_COUPON_ID,
#customer=None, #customer=customer_id,
active=True,
max_redemptions=1,
metadata={
'monthly_price_id': settings.STRIPE_MONTHLY_PRICE_ID,
'product_type': 'Monthly',
},
)

sleek wing
#

If you copy that API call out in to a different file, hardcode the coupon ID, and run it, do you still get the same error?

rough cobalt
#

ok hold on

#

yes, it worked just fine:

import stripe

stripe.api_key = <KEY>

stripe.PromotionCode.create(
coupon="D1JjuzlM",
#customer=None, #customer=customer_id,
active=True,
max_redemptions=1,
metadata={
'yearly_price_id': "price_1HNYoqIeTJrsS1repAcV42H2",
'product_type': 'Yearly',
},
)

sleek wing
#

Strange. Can you try hard-coding this in your original code?

#

If it starts working there, either your coupon ID or price ID variables may not be populated

rough cobalt
#

Sure.

#

oh man my fault completely

#

i am setting it as base64 since i was lazy when copying and pasting from my other environment variable

#

thanks for the help.. that was the problem

sleek wing
#

Good find! Glad this helped you fix it