Stripe subscription invoice remain as open after retry with valid payment method

Viewed 262

I'm implementing stripe subscription using stripe-php library, following this doc https://stripe.com/docs/billing/subscriptions/fixed-price

Simulating customer subscription with failed payment method, stripe subscription object generated successfully with invoice status open.

The issue is when implementing retry-invoice on my backend, my code as below:

        // retrieve new payment method (valid one)
        $payment_method = \Stripe\PaymentMethod::retrieve (
            $request->paymentMethodId
        );

        // attach customer to payment method
        $payment_method->attach([
            'customer' => $request->customerId,
        ]);

        // update customer default payment method
        \Stripe\Customer::update($request->customerId, [
            'invoice_settings' => [
                'default_payment_method' => $request->paymentMethodId
            ]
        ]);

        // retrieve invoice object
        $invoice = \Stripe\Invoice::retrieve($invoiceId, [
            'expand' => ['payment_intent']
        ]);

On stripe dashboard, customer default payment method has successfully updated with latest one (valid card), but the subscription invoice remain as open.

Please help, anyone also facing this issue? i'm afraid that i have missed some steps to follow from stripe docs.

1 Answers

As said in comments; attaching a new PaymentMehod doesn't re-attempt payment.

You need to:

  • Redirect the customer to your site's checkout-page (the page that allows customers to enter payment details and complete their order),
  • But this time, instead of creating a new PaymentIntent, pass the client_secret of the Invoice's PaymentIntent to said checkout-page.
  • Then using JavaScript (of said checkout-page), call Stripe.js' stripe.confirmCardPayment(...) method again.

Note that above may not be required for SetupIntent approach, which is useful for Subscriptions, and allows so-called "off-session" payments.

Related