Cannot get to "requires_action" path after "requires_payment_method"
I am going through the subscriptions integration. I am at the point of integrating 3D-secure authentication path outcome 4
If I input a 3D-secure card first time - it works fine.
However, If the first card I use fails (4000000000000341) and the subscription has status incomplete with requires_payment_method and THEN i try a 3D-secure card like 4000000000003220 - the invoice.pay method throws error instead of giving me an invoice object with a payment_intent.status of requires_action as its expected from the link provided hence I cannot show the user the modal to verify with 3D-secure.
The error thrown is the following (invoice_payment_intent_requires_action) - google can't find anything for the error
rawType: 'card_error',
code: 'invoice_payment_intent_requires_action',
param: undefined,
message:
'This payment requires additional user action before it can be completed successfully. Payment can be completed using the PaymentIntent associated with the invoice. For more details see: https://stripe.com/docs/billing/subscriptions/payment#handling-action-required',
detail: undefined,
raw:
{ code: 'invoice_payment_intent_requires_action',
message:
'This payment requires additional user action before it can be completed successfully. Payment can be completed using the PaymentIntent associated with the invoice. For more details see: https://stripe.com/docs/billing/subscriptions/payment#handling-action-required',
type: 'card_error',
...
stripes-node version: v7.0.0 node version: v11.13.0
Hi there, this looks like an integration issue with the Stripe API rather than a problem with the stripe-node bindings.
I suggest writing into Stripe support with details on your issue at https://support.stripe.com/contact
ok thank you
@pitops hey were you able to resolve this issue ? I'm facing the same issue.
@LabN36 I talked extensively with Stripe Support and they do not seem to understand this is an issue either with their documentation or in general, its like talking to robots.
The error invoice_payment_intent_requires_action is not documentedin their error codes. I told them so but to no avail so I gave up and rolled my own solution.
What I did was store the payment_intent in the db the first time I created the subscription. And try/catch the error invoice_payment_intent_requires_action and when that happens I pass the payment_intent to the frontend to bring back 3D security check modal.
Hope that helps
@pitops Hey thanks for reply i understand the pain with stripe support.
but on the frontend side in order to show the 3D modal we require client_secret which we pass to stripe.handleCardPayment(client_token) method isn't it ?
also when we create subscription which has payment failure then stripe does not provide any payment intent in response.
what i did on my side is i called stripe.paymentIntents.list({customer:'cust_XXX'}) and retrived client_secret.
let me know your thoughts, thanks for reply once again.
@LabN36 you can always get the payment intent even if the subscription failed using this piece of code (notice the expand)
const subscription = await stripe.subscriptions.create({
customer: customerID,
items: [{plan: plan[args.renewalType].id}],
expand: ['latest_invoice.payment_intent']
})
And yes I was talking about client_secret, just did not remember correct from the top of my head but its part of payment_intent
Hey @LabN36 , I noticed the same issue and also did not receive adequate support form stripe. Your suggestions helped me. However, I used a differenet method which did not require me to save the payment_intent in my database. Similarly to you, I also checked on the server if (err.raw.code === "invoice_payment_intent_requires_action").
The way I see it, there are two options to pass the subscription object including the payment_method to the client.
-
Fetch the proper payment method with this code:
stripe.paymentIntents.list({ customer: customer.id })and access the first payment_intent from the data array. Finally pass it to the client. -
If you have access to the customer's subscription.id, which I assume you do, you can use the following code to retrieve this subscription in full, even after having created it:
stripe.subscriptions.retrieve(previousSubscription.id, { expand: ["latest_invoice.payment_intent"] })
The benefit of the second option is that it works well with the resolvePayment(subscription) method on the client side as provided by stripe. However, my only concern would be that a not-up-to-date version of the subscription and is latest_invoice are sent to the client.
I'd be curious to hear your opinion!
@pitops `subscriptions.create dos not work for me, it always throws an error. The error says I can get a paymentIntent from the subscription, but this is impossible as it is always undefined. Docs and example projects are of no help. I'll try to get the payment intent from the customer, hopefully that works!
@danieldunderfelt Please talk to our support team for this kind of questions: https://support.stripe.com/contact. We're also on IRC in the #stripe channel on Freenode https://webchat.freenode.net/
@danieldunderfelt (and anyone else having this problem) It took me a couple of days to figure this out.
Although I am using the latest Stripe package version in node (8.140.0 at time of writing), Stripe locks your API version to whatever version your first API request was made with. In my case I was stuck on 2018-05-21, which meant when I create a subscription with one of the test cards that requires confirmation, it sends back an error response instead of the subscription object. You can see your current version and update it in the Stripe dashboard under Developers.
Given there are potentially breaking changes, I am specifying the new API version on stripe.subsriptions.create like so:
stripe.subscriptions.create(
{
customer: customerId,
items: [{ price: priceId }],
expand: ['latest_invoice.payment_intent'],
},
{
apiVersion: '2020-08-27',
},
)
And now it works.
Alternatively you can specify the API version when you instantiate your stripe object, as per the docs:
const stripe = new Stripe('sk_test_...', {
apiVersion: '2020-08-27',
});
@remi-stripe I did talk to support, but I found the missing piece of the puzzle myself through some digging: turns out that the subscription.create call needs payment_behavior: 'allow_incomplete' to actually succeed, something that this code example here as well as the example in the Stripe docs are lacking.
Creating a subscription won't work without that setting.
@daniel-stripe I think it's the same thing as what's mentioned above though. You have to force a recent enough API version for this to work because it changed in 2019-03-14