Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marcolino922's avatar

After a failed payment, the subscription status remains "incomplete"

I'm approaching Stripe and Laravel for the first time. In my application I used the following code to manage payment rejections:

public function processSubscription(Request $request) {

        $this->validate($request, [
            'token' => 'required',
            'plan' => 'required'
        ]);
        
        try {
            
            $stripeCustomer = Auth::user()->createOrGetStripeCustomer([
                'description' => 'Example Example',
                'email' => Auth::user()->email,
                'name' => 'Example Example',
                'phone' => '322234455556',
                'address' => [
                    'city' => 'Alcatraz',
                    'line1' => 'Via Dalle Palle',
                    'postal_code' => '96011',
                    'state' => 'Italia'
                ]
            ]);
            
            Auth::user()->newSubscription('default', $request->input('plan'))->create($request->token);
            return redirect()->route('index')->with('success','Your subscription is active.');
            
        } catch (IncompletePayment $exception) {
            return redirect()->route(
                'cashier.payment',
                [$exception->payment->id, 'redirect' => route('index')]
            );
        }
        
        //catch(\Stripe\Exception\CardException $e) { 
            //return back()->withErrors(['message' => 'Error creating subscription. ' . $e->getMessage()]);    
        //}

}

During a test payment, using the card:

4000 0000 0000 0341

A page is opened to confirm the customer's data again, this time by inserting a valid card (4242 4242 4242 4242), the payment is correctly executed and unfortunately nothing has changed by returning to the home page.

The status of the customer's subscription remains "incomplete". I also attach the javascript code if anything could be useful.

const stripe = Stripe('{{ config('cashier.key') }}')

    const elements = stripe.elements()
    const cardElement = elements.create('card')

    cardElement.mount('#card-element')

    const form = document.getElementById('payment-form')
    const cardBtn = document.getElementById('card-button')
    //const cardHolderName = document.getElementById('card-holder-name')

    form.addEventListener('submit', async (e) => {
        e.preventDefault()

        // Disable the submit button to prevent repeated clicks
        document.getElementById('card-button').disabled = true
        
        const { setupIntent, error } = await stripe.confirmCardSetup(
            cardBtn.dataset.secret, {
                payment_method: {
                    card: cardElement,
                    //billing_details: {
                        //name: document.getElementById('name').value
                    //}
                }
            }
        )

        if(error) {
            document.getElementById('card-button').disabled = false
        } else {
            let token = document.createElement('input')
            
            token.setAttribute('type', 'hidden')
            token.setAttribute('name', 'token')
            token.setAttribute('value', setupIntent.payment_method)

            form.appendChild(token)

            form.submit();
        }
        
        
    })

Why is the subscription status in the database not updated after the first payment fails, but the second payment does?

0 likes
0 replies

Please or to participate in this conversation.