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

ixudra's avatar

Laravel Cashier issue

Hey guys

I have an an app in which I use Stripe and Laravel Cashier for billing. Creating new customers is easy and works perfectly. However, my app also makes it possible for users to cancel a subscription and restart it on a later date. I looked into the Stripe API on how to do this, but I can't seem to make it work in Cashier. The request is sent and as far as I can see the the subscription is restarted successfully, but for some reason the Stripe API throws an exception (invalid HTTP code) .

here is the code I'm using:

        if( $this->isBillable() ) {
            if( !is_null($token) ) {
                // Create new subscription if a token is provided
                $this->subscription( $plan )->create( $token );
            } else {
                // Renew the previous subscription if we already know the customer
                $newPlan = null;
                if( $plan != $this->stripe_plan ) {
                    $newPlan = $plan;
                }

                $stripeCustomer = $this->subscription()->getStripeCustomer( $this->stripe_id );

                $this->subscription()->create( $newPlan, array(), $stripeCustomer );
            }
        }

Is there anyone that has experience with this? What am I missing here?

0 likes
1 reply
ixudra's avatar
ixudra
OP
Best Answer
Level 4

So I found the issue, turns out I wasn't passing the parameters around like I should have. Here is the correct code:

        if( $this->user->isBillable() ) {
            if( !is_null($token) ) {
                $this->subscription( $plan )->create( $token );
            } else {
                $newPlan = $this->stripe_plan;
                if( $plan != $newPlan  && !is_null($plan) ) {
                    $newPlan = $plan;
                }

                $stripeCustomer = $this->subscription()->getStripeCustomer( $this->stripe_id );

                $this->subscription( $newPlan )->create( $token, array(), $stripeCustomer );
            }
        }

Hope this helps someone in the future

Please or to participate in this conversation.