#-7he-judge-_error

1 messages Β· Page 1 of 1 (latest)

karmic caveBOT
#

πŸ‘‹ 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/1423616248050094162

πŸ“ 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.

gilded widget
#

Here's my code, where I got an error

const subscription = await this.stripe.subscriptions.create({
        customer: stripeCustomer.id,
        items: subItems,
        add_invoice_items:
          addInvoiceItems.length > 0 ? addInvoiceItems : undefined,
        default_payment_method: defaultPaymentMethod,
        discounts: subscriptionDiscounts,
        payment_behavior: 'allow_incomplete', // Allow incomplete but try to charge immediately
        automatic_tax: { enabled: false },
        metadata: typeof dto.metadata === 'object' ? (dto.metadata as any) : {},
      });
#

It happens if I try to pay via Amazon Pay
With card/Gpay - is okay

barren crane
gilded widget
#

could I share Payment method ID instead of req ID?

#

ah, found it
req_65GQu9xW2iMkaV

barren crane
#

Thanks for sharing, checking...

#

Sorry for the late reply, we are still investigating

gilded widget
#

okay, waiting for any responses

barren crane
#

OK Amazon Pay is requiring a redirect url

#

2 Payment methods might require confirmation with return_url to indicate where Stripe should redirect your customer after they complete the payment.

#

What you can do actually, is to create the Subscription without the payment method

#

and then confirm the generated payment_intent using the saved AmazonPay PaymentMethod.

#

You may need to invite your customer on session to complete any required action.

gilded widget
#

did not catch it

barren crane
#

In your request req_65GQu9xW2iMkaV, remove the PaymentMethod Id you passed

#

The Subscription will be created with an open invoice

#

You then confirm the generated PaymentIntent with that Saved PaymentMethod with the return_url (to your frontend)

#

if the PaymentIntent's status is required_action, then you need to ask your customer to come on session (to your frontend) in order to handle the next action and confirm the payment

gilded widget
#

stop, I have frontend and backend
now how it works
frontend send request and backend do logic of creation subscription

let's start from begin

barren crane
#

The backend creates the Subscription without passing the PaymentMethod when it's Amazon pay. It's what you did in this request req_65GQu9xW2iMkaV.

#

Is this step ok ?

gilded widget
#

I think we should do it not only for amazon, but for all payments
cause there not only one amazon requires redirect_url?

#

am I right?

barren crane
#

I think we should do it not only for amazon, but for all payments
No not all payment methods requires return_url

gilded widget
#

okay, should I do it only for amazon, right?

barren crane
gilded widget
#

trying

#

I added off_session: true
but my subscription has status incomplete
but no errors there

Look at my request
req_PhBqu0rtLuakeZ

#

What AI responsed me

Adding `off_session: true` avoided the return_url error, but the subscription is now created as `incomplete` because the first payment isn’t processed.

For Amazon Pay subscriptions, we should:
- Omit `off_session` (or set it to false) so the first payment can be collected
- Provide a `return_url` when confirming the PaymentIntent
- Detect Amazon Pay and handle the return_url flow

Implementing this flow.


[5 tools called]

Checking whether `returnUrl` exists in `ConfirmCheckoutDto`.


[2 tools called]

The `returnUrl` field was removed from `ConfirmCheckoutDto`. Restoring it.


[3 tools called]

## Amazon Pay issue fixed

### The problem
- `off_session: true` prevented the return_url error but left subscriptions `incomplete`.
- Amazon Pay needs a return URL, but `off_session: true` blocks collecting the first payment.
#
### Solution

**1. Conditional off_session**
```typescript
off_session: !isAmazonPay, // Only use off_session for non-Amazon Pay methods

2. Amazon Pay detection and handling

// Check if payment method is Amazon Pay
let isAmazonPay = false;
if (defaultPaymentMethod) {
  const pm = await this.stripe.paymentMethods.retrieve(defaultPaymentMethod);
  if (pm.type === 'amazon_pay') {
    isAmazonPay = true;
  }
}

3. PaymentIntent confirmation with return URL

// Handle Amazon Pay return URL if needed
if (isAmazonPay && paymentIntent.status === 'requires_action' && dto.returnUrl) {
  const confirmedPaymentIntent = await this.stripe.paymentIntents.confirm(
    paymentIntent.id,
    {
      return_url: dto.returnUrl,
    }
  );
  paymentIntent = confirmedPaymentIntent;
}

How it works now

  1. Non-Amazon Pay: off_session: true β†’ subscription is active.
  2. Amazon Pay: off_session: false β†’ subscription can collect the first payment.
  3. Amazon Pay + return URL: PaymentIntent is confirmed with the return URL β†’ payment succeeds.

Expected results

  • No return_url errors.
  • Amazon Pay subscriptions complete.
  • Subscriptions are active (not incomplete).
  • Invoices are paid.
  • Other payment methods continue to work.

Amazon Pay subscriptions should now complete successfully.

#

but that returns me the same error

{
  "statusCode": 400,
  "message": "You must provide a `return_url` when confirming a PaymentIntent with the payment method type amazon_pay.",
  "error": "Checkout Error"
}
barren crane
#

off_session: !isAmazonPay, // Only use off_session for non-Amazon Pay methods
You can keep the off_session flag when you pass a saved PaymentMethod always, regardless of what PaymentMethod type you are using

gilded widget
#

okay, it was just AI wrong solution

barren crane
#

Not sure I understand you latest follow up message, sorry.

gilded widget
#

after I added off_session: true
request was 200
but my subscription has status incomplete, and it's not active

barren crane
#

Can you share the SubscriptionId ?

#

ok it should be this one sub_1SE6zTEFwYCC7pJUZOMW9f2o

#

Checking it

gilded widget
#

sure

barren crane
#

Can you try removing the parameter payment_behavior: "allow_incomplete", when you create the Subscription ?

gilded widget
#

removed
req_WUkeKBS2qtdx2s
subsription - not active
transaction - incomplete

#
const subscription = await this.stripe.subscriptions.create({
        customer: stripeCustomer.id,
        items: subItems,
        add_invoice_items:
          addInvoiceItems.length > 0 ? addInvoiceItems : undefined,
        default_payment_method: defaultPaymentMethod,
        discounts: subscriptionDiscounts,
        automatic_tax: { enabled: false },
        metadata: typeof dto.metadata === 'object' ? (dto.metadata as any) : {},
        off_session: true,
      });
karmic caveBOT
gilded widget
#

any ideas how to solve this problem?

tawdry flume
#

πŸ‘‹ taking over for my colleague. Let me catch up.

#

@gilded widget let's take a step back

#

would you mind sharing with me what are you trying to do, regardless of the implementation

gilded widget
#

Look, I have subscription product on checkout page
well, I use ```
const subscription = await this.stripe.subscriptions.create({
customer: stripeCustomer.id,
items: subItems,
add_invoice_items: addInvoiceItems.length > 0 ? addInvoiceItems : undefined,
default_payment_method: defaultPaymentMethod,
discounts: subscriptionDiscounts,
payment_behavior: 'allow_incomplete', // Allow incomplete but try to charge immediately
automatic_tax: { enabled: false },
metadata: typeof dto.metadata === 'object' ? (dto.metadata as any) : {},
});

with `card` and `Google Pay` methods it works okay
but with `Amazon Pay` I have an error

{
"statusCode": 400,
"message": "You must provide a return_url when confirming a PaymentIntent with the payment method type amazon_pay.",
"error": "Checkout Error"
}


I already find out, that some methods requires `redirect_url` (https://docs.stripe.com/payments/payment-methods/payment-method-support#wallets-api-support)
Okay, how could we solve my problem?
karmic caveBOT
golden phoenix
#

hi! I'm taking over this thread.

#

can you try adding off_session: true when you create the Subscription?

gilded widget
golden phoenix
#

yep. and then you need to handle any required action to move the subscription from incomplete to active.

gilded widget
#

do not catch this step
could help me with that?
What do I need to do?

golden phoenix
#

sure. can you share the Subscription ID (sub_xxx) with this issue?

gilded widget
#

sub_1SE6zTEFwYCC7pJUZOMW9f2o

golden phoenix
#

so the next steps is t ask your user to come back to your website/app, and to confirm the PaymentIntent on the frontend to trigger the action the user needs to complete.

#

then the PaymentIntent will become suceeded, and the Subscription active.

gilded widget
#

stop, I have frontend and backend
now how it works
frontend send request and backend do logic of creation subscription

What should I extend exept for off_session: true on backend?

golden phoenix
#

I'm sorry I don't understand your question.

gilded widget
#

so the next steps is t ask your user to come back to your website/app, and to confirm the PaymentIntent on the frontend to trigger the action the user needs to complete.

how it should be?
do you have an example?

golden phoenix
#

first, you need to retrive the Invoice and PaymentIntent from the Subscription. then, you get the client_secret of the PaymentIntent. finally you call handle_next_action on the frontend while passing the client_secret.

gilded widget
#

this logic must be for all methods?
or how could I catch that?
When it must redirect to /success page
and when come back to checkout page?

golden phoenix
#

it can sometimes happen yes, so that's something that you need to handle on your end when you see a PaymentIntent with reauires_action status.

gilded widget
#

let me try

karmic caveBOT
gilded widget
#

I do not understand, where should I get these fields requiresAction and actionClientSecret

spare jacinth
#

Hi there, taking over for @golden phoenix as they had to step away

gilded widget
#

okay, waiting for responses

spare jacinth