#eda_api

1 messages · Page 1 of 1 (latest)

lucid dockBOT
#

👋 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/1282861646364151862

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

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.

last magnet
#

Back to your question:

However, I am able to use the coupon multiple times as one user

Could you share the Checkout Session (cs_xxx) and the promotion code?

twilit tendon
#

I can't find the Checkout Session but here is a response log

#
{
  "object": {
    "id": "promo_1PxGtPRq1d245q3lmAPN64tA",
    "object": "promotion_code",
    "active": true,
    "code": "METACON24",
    "coupon": {
      "id": "o4P4vhZg",
      "object": "coupon",
      "amount_off": 10000,
      "created": 1725924071,
      "currency": "usd",
      "duration": "once",
      "duration_in_months": null,
      "livemode": true,
      "max_redemptions": 1000,
      "metadata": {},
      "name": "Meta Connection Promotion",
      "percent_off": null,
      "redeem_by": 1728543540,
      "times_redeemed": 3,
      "valid": true
    },
    "created": 1725924071,
    "customer": null,
    "expires_at": 1728543540,
    "livemode": true,
    "max_redemptions": null,
    "metadata": {},
    "restrictions": {
      "first_time_transaction": true,
      "minimum_amount": null,
      "minimum_amount_currency": null
    },
    "times_redeemed": 3
  },
  "previous_attributes": {
    "times_redeemed": 2
  }
}
last magnet
#

However, I am able to use the coupon multiple times as one user.
How did you find out the one user can use the promotion code multiple times? Could you share the payment intent ID (pi_xxx) or Checkout Session ID (cs_xxx) that the payments had discounts applied on the same customer?

twilit tendon
#

I am using the same customer_email and am able to redeem it multiple times, the log above will have the same redeem_by ID and increasing times_redeemed

#

Let me try to find it

last magnet
#

By looking at the promotion code, I could see that that promotion code were applied into these two Checkout Sessions:

twilit tendon
#

Where can I find the payment intent ID (pi_xxx) or Checkout Session ID (cs_xxx)? The promo amount covers the entire payment amount

#

Yes!

#

And they have the same customer_email but First-time order only: Yes should prevent the same user from using the promo code multiple times?

last magnet
#

As mentioned in https://docs.stripe.com/payments/checkout/discounts#limit-by-first-time-order:

If the customer isn’t defined, or if a defined customer has no prior payments or non-void invoices, it’s considered a first-time transaction.

In your Checkout Session, no customer property was defined in the creation request

Discounts in Checkout allow you to reduce the amount charged to a customer for one-time payments by discounting their subtotal with coupons and promotion codes.

#

customer and customer_email properties are two different things

#

Stripe only looks at customer property to determine whether the customer is eligible for first-time order

twilit tendon
#

But I can't set both?

last magnet
#

You can't have both! The request only allows customer OR customer_email, not both

twilit tendon
#

But setting customer means that the customer has to provide an email at checkout, correct?

#

That's a large point of friction for users

last magnet
#

Your system should ensure only one Stripe customer is created for each email address

#

If an email is set on the customer, Stripe will populate the email address in the Checkout Session

#

No explicit customer_email needs to be set if the customer is created with email address

twilit tendon
#

Ah I see, I didn't know we had to handle that on our side

last magnet
#

For first-time order promotion code, it only works when customer is set in the Checkout Session. Otherwise, Stripe will treat every new Checkout Session as a new customer if customer property isn't set

#

customer_email isn't the field that Stripe looks at for first-time order transactions

twilit tendon
#

Got it, so can I do something like this?

#
cust_search = stripe.Customer.search(query=f"email:'{user.email}'")
customer_id = ''
if not cust_search['data']: # Customer does not exist, create one
    customer_id = stripe.Customer.create(email=user.email)['id']
elif len(cust_search['data']) == 1:
    customer_id = cust_search['data'][0]['id']

session = stripe.checkout.Session.create(
    line_items=[
        {
            "price": config["st
ripe"]["price_id"],
            "quantity": 1,
        }
    ],
    mode="payment",
    client_reference_id=payload.account_id,
    customer=customer_id
    success_url=config["powerml"]["website"] + "/account",
    allow_promotion_codes=True,
)
last magnet
#

I'd recommend storing the customer ID (cus_xxx) in your database after creating one and search from your own database instead of using Stripe API to search

twilit tendon
#

Got it, so there isn't an easy solution to this 🥲