Laravel and Braintree, Sitting in a Tree…
Subscriptions to services online are something extremely common – from subscribing to music streaming services to tutorial sites to access premium content.
With Laravel 5, we saw the introduction of Laravel Cashier, an official Laravel package to help developers manage Stripe’s and Braintree’s subscription billing services without writing most of the boilerplate subscription billing code.
Stripe and Braintree are payment platforms that make it easy to accept payments in your app or website.
In this tutorial, we will be building a dummy Courses site with Braintree subscriptions. In the process, we will learn how to use the various methods offered by
In the first part of this extensive two-part series, we are going to:
- Set up Laravel Cashier
- Sign up to the Braintree sandbox (For production apps we use the main Braintree service)
- Create plans on Braintree
- Create an artisan command to sync the online plans with our database
- Allow users to subscribe to a plan
In part two, we will:
- Add the ability to swap plans
- Create middleware to protect some routes based on the subscription status
- Protect premium courses from users with basic subscription
- Learn how to cancel and resume subscriptions
- Add Braintree notifications to a variety of the application’s events via webhooks
The complete code for part one can be found here.
Creating the Application
We will start with a fresh Laravel installation.
composer create-project laravel/laravel lara-billable
Preparing the Database
Next, we have to set up the database before running any migrations. Let’s use MySQL – it’s easy to use, easy to configure, and included in a well-built development environment like Homestead Improved. After setting up the database, I have my
.env file looking like this:
DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
The next step is adding authentication to our application.
Continue reading %Laravel and Braintree, Sitting in a Tree…%
LEAVE A REPLY
You must be logged in to post a comment.