#-7he-judge-_error
1 messages Β· Page 1 of 1 (latest)
π 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.
- -7he-judge-_best-practices, 2 days ago, 27 messages
- -7he-judge-_error, 2 days ago, 36 messages
- -7he-judge-_error, 3 days ago, 12 messages
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
Hi there!
Can you share the ID (req_xxx) of the failing API request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
could I share Payment method ID instead of req ID?
ah, found it
req_65GQu9xW2iMkaV
Thanks for sharing, checking...
Sorry for the late reply, we are still investigating
okay, waiting for any responses
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.
did not catch it
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
When this happens, you'll need to call this JS function in oder to handle the next action:
https://docs.stripe.com/js/payment_intents/handle_next_action
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
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 ?
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?
I think we should do it not only for amazon, but for all payments
No not all payment methods requires return_url
okay, should I do it only for amazon, right?
Ah wait, can you try this same request req_65GQu9xW2iMkaV and add off_session: true ?
https://docs.stripe.com/billing/subscriptions/amazon-pay?api-integration=setupintents#create-subscription
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
- Non-Amazon Pay:
off_session: trueβ subscription is active. - Amazon Pay:
off_session: falseβ subscription can collect the first payment. - 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"
}
Checking this request Id
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
okay, it was just AI wrong solution
Not sure I understand you latest follow up message, sorry.
after I added off_session: true
request was 200
but my subscription has status incomplete, and it's not active
Can you share the SubscriptionId ?
ok it should be this one sub_1SE6zTEFwYCC7pJUZOMW9f2o
Checking it
sure
Can you try removing the parameter payment_behavior: "allow_incomplete", when you create the Subscription ?
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,
});
any ideas how to solve this problem?
π 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
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?
hi! I'm taking over this thread.
can you try adding off_session: true when you create the Subscription?
tried on that step
yep. and then you need to handle any required action to move the subscription from incomplete to active.
do not catch this step
could help me with that?
What do I need to do?
sure. can you share the Subscription ID (sub_xxx) with this issue?
sub_1SE6zTEFwYCC7pJUZOMW9f2o
if you check the PaymentIntent of the first Invoice, it has status: "requires_confirmation": https://dashboard.stripe.com/acct_1RX4mCEFwYCC7pJU/test/payments/pi_3SE6zUEFwYCC7pJU0RrkXKz3
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.
I think this is the function you should call on the frontend: https://docs.stripe.com/js/payment_intents/handle_next_action
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?
I'm sorry I don't understand your question.
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?
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.
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?
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.
let me try
I do not understand, where should I get these fields requiresAction and actionClientSecret
Hi there, taking over for @golden phoenix as they had to step away
okay, waiting for responses
It sounds like they were suggesting this sequence to handle requires action in a subscription
https://docs.stripe.com/billing/subscriptions/overview#requires-action
Can you look over this guide and let me know if it helps?