The stupendous.dev Blog

How to Install Cartalyst Stripe in Laravel 5.8

By Topher | April 2019

Are you looking to sell subscriptions to your website or web app? Chances are, you want to use Stripe to accept payments. Enter Cartalyst Stripe stage right. Cartalyst Stripe is a powerful package designed to give you a bit more customization over Laravel's Cashier. It has many functions. It is very easy to use. And, there is tons of documentation in case you ever get lost.

So let's get started. You have setup your Laravel project and signed up for Stripe. Now let's let the two play together.

Install Cartalyst Stripe

First, install the Cartalyst Stripe package with Composer. You can view the Cartalyst Stripe documentation you will need for Laravel 5.8 here. Add the following to your /composer.json file in Laravel.


  "cartalyst/stripe-laravel": "10.0.*"
  

Now run one of the following commands.


  php composer install
  

or


  php composer update
  

Integrate Cartalyst

Now add Cartalyst Stripe to your /config/app.php like so. First under the $providors array add the following line:


  Cartalyst\Stripe\Laravel\StripeServiceProvider::class,
  

And, under the $aliases array and this line:


  'Stripe' => Cartalyst\Stripe\Laravel\Facades\Stripe::class,
  

The API Codes

First we will figure out what your Stripe API codes are. Head over to stripe.com, login, and go to your dashboard. Navigate to Developers > API keys. Here you will see a publishable key and a secret key. You will need both. However, it is a good idea to use the testing keys so that you can feel things out before you are ready for production. To do this, simply click on View test data to switch the keys.

How to Install Cartalyst Stripe in Laravel 5.8

Next, add these two lines to your /.env file adding your keys after each of the "=" signs. We are adding these keys to your .env file to keep them out of the public space where prying eyes can see and use them.


  STRIPE_PUBLIC_KEY=your-stripe-api-key
  STRIPE_SECRET_KEY=your-stripe-api-key
  

Next add the following code to your /config/services.php file. Notice it will pull your keys from the environment file that we updated. Cool! Huh?


  'stripe' => [
    'key'   => env('STRIPE_PUBLIC_KEY'),
    'secret' => env('STRIPE_SECRET_KEY'),
  ],
  

Usage

Everytime you use Cartalyst Stripe, you will need the following three lines. Add this line to the top of your controller or wherever you're going to use the Cartalyst Stripe package:


  use Stripe;
  

Now create a new instance of the Cartalyst Stripe package by doing the following:


  $stripe = new Stripe('your-stripe-api-key');
  $stripe = Stripe::make('your-stripe-api-key');

Now you can do it all. Pretty much every time you want to capture credit card information or process a payment in Cartalyst Stripe, you will need to create a new customer. But Cartalyst Stripe does it all. You can create customers, cards, subscriptions, plans, and even make a one time charge. There is lots more. Check out the Stripe by Cartalyst page to learn more.

Let the web

Supercharge your project

Discover the awesome and affordable possiblities of web page and application design by stupendous.dev Web Design. I will deliver you the web design or ecommerce site you need to succeed. Say hello and let's talk more about your goals. I can't wait to see what you're cooking up! 👍

Say Hi!