#jaunt - Checkout Coupons

1 messages · Page 1 of 1 (latest)

young scaffold
near marten
#

Thanks! Working on it. So far I've got the request id for the coupon creation. Now finding the one for the checkout session.

coupon create request id: req_FRnBUZrl6WVLCX

#

Here it is: req_z5DQkn0SQZqJfi

young scaffold
#

Looking...

#

Our system received the GET request to retrieve the coupon before the request to create it.

#

We received the GET request at 1641504909.169225 and the Coupon creation request at 1641504909.3661966

near marten
#

Wonder how that is possible.

young scaffold
#

It seems like you're running these requests in parallel instead of serially?

near marten
#

I"m using the go api...

young scaffold
#

Can you show me the code you're using?

near marten
#

Sure...

#
    discounts := []*stripe.CheckoutSessionDiscountParams{}

    if offerLevel != "" && offer != nil && percentOff != 0 {
        couponID := cart.ApplyOffer + "_" + offerLevel + "_" + userKey.Name
        useCoupon, err := coupon.Get(couponID, nil)
        if err != nil {

            var dm *int64
            if duration != "once" {
                dm = stripe.Int64(int64(durationInMonths))
            }

            params := &stripe.CouponParams{
                Duration:         stripe.String(duration),
                DurationInMonths: dm,
                PercentOff:       stripe.Float64(float64(percentOff)),
                ID:               stripe.String(couponID),
            }

            useCoupon, err = coupon.New(params)
            if err != nil {
                Logger(c, logrus.Fields{}, ERROR, "createCheckoutSubscriptionSessionHandler could not create stripe coupon.  Skipping.  %v", err)
            }
        }
        discounts = append(discounts, &stripe.CheckoutSessionDiscountParams{
            Coupon: &useCoupon.ID,
        })
    }

    var ap *bool
    if len(discounts) == 0 {
        ap = stripe.Bool(true)
        discounts = nil
    }

    domain := os.Getenv("WEB_APP_ADDRESS") + "/confirming"
    params := &stripe.CheckoutSessionParams{
        Customer: stripe.String(stripeAccount.StripeID),
        //SubmitType:               stripe.String("pay"),
        BillingAddressCollection: stripe.String("auto"),
        PaymentMethodTypes: stripe.StringSlice([]string{
            "card",
        }),
        LineItems:           items,
        Mode:                stripe.String(string(stripe.CheckoutSessionModeSubscription)),
        SuccessURL:          stripe.String(domain + "?purchaseSuccess=true&session_id={CHECKOUT_SESSION_ID}"),
        CancelURL:           stripe.String(domain + "?purchaseCanceled=true&session_id={CHECKOUT_SESSION_ID}"),
        AllowPromotionCodes: ap,
        Discounts:           discounts,
    }
young scaffold
#

On this line: useCoupon, err := coupon.Get(couponID, nil) where is coupon coming from/created?

near marten
young scaffold
#

So, yeah, you're fetching it there before you create it below.

near marten
#

Well checking to see if it exists

young scaffold
#

You don't create it until later, down here: useCoupon, err = coupon.New(params)

#

Right, that generates an API request and results in the 404 request you linked to earlier.

near marten
#

The creation of the coupon didn't create an error?

young scaffold
#

No, that worked just fine.

near marten
#

So you're saying the error came from the coupon.Get request.

#

But the checkout session failed to use the coupon, and the customer ended up without the coupon. This is the first time I've ever seen it happen.

young scaffold
#

Can you provide the request ID for creation of the Checkout Session where the coupon didn't work?

near marten
#

Trying to figure that out. There are a string of events

#

Looks like there were three calls to checkout/sessions in a row.. weird.

req_ZTMSx6g7nWI5V9
req_8FmukdwFzX1Bsy
req_6faGNB0RTPVDrx

The first two reference the coupon but the third doesn't for some reason.

young scaffold
#

Ah, well, at least that explains why the coupon was missing! 😅

#

Is there anything else I can do to help?

near marten
#

I guess not!

young scaffold
#

Hopefully using the request detail you can determine what's causing the issue!

near marten
#

I wonder if the user reefed on browser refresh. Still makes no sense why the third time there was no coupon. Will investigate.

#

Thanks for the help!