Laravel Cashier v10 Example
Example Laravel application to show how Cashier v10 can be implemented for subscription apps
Cashier v10 is the lastest version of Laravel Cashier. It has support for Strong Customer Authentication (SCA) which is a new payment flow that will be required for online payments from mid-September 2019.
I created this sample application because I wanted a place to test Cashier v10 before implementing it in my production Saas application. This example app is a fake subscription Saas type app where you enter your billing inofmrtaion at user registration.
I'm guessing you know how Laravel apps are installed so I'll miss out the basics. Just a few notes though:
- Remember to enter Stripe keys into
.envfile (remember to copy that from
- Remember to compile assets from Mix
npm run watchor
yarn run watch(and install the node deps)
resources/js directory and it is all compiled by Laravel Mix.
And then in your Vue files, you can refrence the Stripe key like this:
The backend is fairly basic, the only place where there is any real custom logic is in the
create method is one Laravel gives you where you can put any custom logic you need to do after a user has been registered.
In there, we just go ahead and create the user and subscribe them to a new plan, in our case the plan is called
If the payment is successful after registration the user will be redirected to the home, if not they will be directed to a 'Complete Payment' screen (Provided by Cashier) to do any additional verification steps required by the customer's bank.
If you need to create real customers in Stripe while running your tests (please do this in test mode), I've included a little helper class which will generate a Stripe Payment Method for you to use when creating a subscription in your tests.
... use App\Services\GeneratePaymentMethod; ... $paymentMethod = (new GeneratePaymentMethod())->generate(); $user = factory(\App\User::class)->create(); $user->newSubscription('stripe_plan', 'app_plan') ->create($paymentMethod); ...
If you have any issues regarding this example or are a bit confused, please create an issue and I'll try and help the best I can.