OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Stripe Checkout Subscription Payment failure redirects to Expire Link Page

  • Thread starter Thread starter Sabbir Ahmed Siddiquee
  • Start date Start date
S

Sabbir Ahmed Siddiquee

Guest
I'm trying to integrate Stripe One time and Subscription Payment using their Checkout API.

I have also enabled 3D secure payments. In one time payment when payment is successful it redirects to our success page. And when a payment is failed, it shows error message in checkout form. Which is as expected.

In Checkout subscription, when payment is successfully it perfectly redirects to success page. For failed payment it also shows error messages after 3D authentication, but when I try to pay with another card or the same card after a failed attempt, it redirects me to Expired link page.

I checked in stripe demo checkout page (https://checkout.stripe.dev/preview) where it works fine but don't know what I'm missing.

What I understand from the stripe docs is that, for failed payment I should handle error and tell users/redirects to use a different payment method.

I have registered the following webhook events:

  1. invoice.payment_action_required
  2. charge.failed
  3. customer.subscription.deleted
  4. customer.subscription.created
  5. checkout.session.completed
  6. invoice.paid

When invoice.payment_action_required event is triggered, I have to manually confirm the payment for 3D secure authentication (it's required for subscription). I have written the following code to confirm the payment.


Code:
if (paymentIntent.status === 'requires_action') {
   await stripe.paymentIntents.confirm(payment_intent);
}

Here is the code snippet to create a subscription session:


Code:
const session = await stripePrivate.checkout.sessions.create({
        mode: 'subscription',
        payment_method_types: ['card'],
        line_items: [
          {
            price: planId,
            quantity: 1
          }
        ],
        metadata: {
          transactionId
        },
        subscription_data: {
          metadata: {
            transactionId
          }
        },
        success_url: `${merchantCallbackURL}?sessionId={CHECKOUT_SESSION_ID}&status=success&orderId=${orderId}`,
        cancel_url: `${merchantCallbackURL}?sessionId={CHECKOUT_SESSION_ID}&status=canceled&orderId=${orderId}`
      });

  const callbackUrl = session.url;

And below is the page, I'm redirected to if a subscription payment is failed (from 2nd attempt):

enter image description here

Here I'm adding some checkout URL for testing:

Test card 1: 4000008260003178 (insufficient balance)

Test card 2: 4000002500003155


  1. https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl
  2. https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl
  3. https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl
  4. https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl
  5. https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl
Above URL will be expired within 24 hours. Please ask if you need another active url for testing.

How to test?

  1. Use the given test card 1 and complete 3D authentication
  2. Now use test card 1 or 2 and try to subscribe again, you'll be redirected to Expired link page

How do I fix this issue? What am I missing here?

<p>I'm trying to integrate Stripe One time and Subscription Payment using their <code>Checkout API</code>.</p>
<p>I have also enabled 3D secure payments.
In one time payment when payment is successful it redirects to our success page. And when a payment is failed, it shows error message in checkout form. Which is as expected.</p>
<p>In Checkout subscription, when payment is successfully it perfectly redirects to success page. For failed payment it also shows error messages after 3D authentication, but when I try to pay with another card or the same card after a failed attempt, it redirects me to <code>Expired link page</code>.</p>
<p>I checked in stripe demo checkout page (<a href="https://checkout.stripe.dev/preview" rel="nofollow noreferrer">https://checkout.stripe.dev/preview</a>) where it works fine but don't know what I'm missing.</p>
<p>What I understand from the stripe docs is that, for failed payment I should handle error and tell users/redirects to use a different payment method.</p>
<p>I have registered the following webhook events:</p>
<ol>
<li>invoice.payment_action_required</li>
<li>charge.failed</li>
<li>customer.subscription.deleted</li>
<li>customer.subscription.created</li>
<li>checkout.session.completed</li>
<li>invoice.paid</li>
</ol>
<p>When <code>invoice.payment_action_required</code> event is triggered, I have to manually confirm the payment for 3D secure authentication (it's required for subscription). I have written the following code to confirm the payment.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>if (paymentIntent.status === 'requires_action') {
await stripe.paymentIntents.confirm(payment_intent);
}</code></pre>
</div>
</div>
</p>
<p>Here is the code snippet to create a subscription session:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const session = await stripePrivate.checkout.sessions.create({
mode: 'subscription',
payment_method_types: ['card'],
line_items: [
{
price: planId,
quantity: 1
}
],
metadata: {
transactionId
},
subscription_data: {
metadata: {
transactionId
}
},
success_url: `${merchantCallbackURL}?sessionId={CHECKOUT_SESSION_ID}&status=success&orderId=${orderId}`,
cancel_url: `${merchantCallbackURL}?sessionId={CHECKOUT_SESSION_ID}&status=canceled&orderId=${orderId}`
});

const callbackUrl = session.url;</code></pre>
</div>
</div>
</p>
<p>And below is the page, I'm redirected to if a subscription payment is failed (from 2nd attempt):</p>
<p><a href="https://i.sstatic.net/JaUTj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JaUTj.png" alt="enter image description here" /></a></p>
<p>Here I'm adding some checkout URL for testing:</p>
<p><strong>Test card 1: 4000008260003178 (insufficient balance)</strong></p>
<p><strong>Test card 2: 4000002500003155</strong></p>
<ol>
<li><a href="https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl" rel="nofollow noreferrer">https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl</a></li>
<li><a href="https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl" rel="nofollow noreferrer">https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl</a></li>
<li><a href="https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl" rel="nofollow noreferrer">https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl</a></li>
<li><a href="https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl" rel="nofollow noreferrer">https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl</a></li>
<li><a href="https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl" rel="nofollow noreferrer">https://checkout.stripe.com/pay/cs_...abHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic/cXdwYHgl</a></li>
</ol>
<blockquote>
<p>Above URL will be expired within 24 hours. Please ask if you need
another active url for testing.</p>
</blockquote>
<p><strong>How to test?</strong></p>
<ol>
<li>Use the given test card 1 and complete 3D authentication</li>
<li>Now use test card 1 or 2 and try to subscribe again, you'll be redirected to <code>Expired link page</code></li>
</ol>
<p><strong>How do I fix this issue? What am I missing here?</strong></p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top