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

yougotnet's avatar

Laravel Cashier issues when setting up subscription with declined credit card

I'm having a problem with Cashier when using newSubscription and create method. If the credit card goes through fine then everything works fine but if the credit card is declined for any reason, then the Customer is setup with Stripe with no Subscription and no credit card on file (which is good, except I don't want any of it setup if the credit card fails).

Also, when the Customer is setup in Stripe, nothing is updated or returned in Laravel to show the connection between the User and their new Stripe customer id. Therefore I am getting empty customer accounts in Stripe

Any help is greatly appreciated!

0 likes
2 replies
shez1983's avatar

in a normal stripe you are supposed to use Stripe JS library to create a card - which if accepted returns you a card object, from which you just need to pass token to your backend - here you create a customer in stripe associating that card token to the customer which gets you a stripe_id for the user which u store in your backend...

with Cashier its similar flow.. (i will check at work but i have used cashier for subscription but cant remember what the JS library returns in that case.. )

yougotnet's avatar

Right, but by using the Stripe JS Library and getting a token; the token doesn't guarantee the charge will go through. Then when you submit the form to your backend and use newSubscription(), Cashier will create the Customer on Stripe and then try to create the Subscription, but if the payment fails, Stripe returns only an error and then you have no idea the Stripe Customer ID.

I spoke with the team of Cashier and they agree that the newSubscription() function is trying to do to much at once. They are hoping to fix this in the next release.

What I did in my code is override Cashier's createAsStripeCustomer() function because it was the function causing the issue. It was trying to create the customer and update the credit card together; updating the credit card was the issue.

Now, when I have a new customer with a new subscription; I first use createAsStripeCustomer() (that I overrode), which returns me the Stripe Customer Information, then I use newSubscription() in a try catch, this way if Stripe returns an error (most likely the card was declined for some reason) then I can delete the customer account in Stripe.

1 like

Please or to participate in this conversation.