How to Integrate Laravel with Stripe
Hello, today I want to share about how to integrating our Laravel App with Stripe. We know that stripe is the best way to create a payment gateway system. Before we start this tutorial, we need to create a Stripe account first, because we will use a Stripe secreet key to call the API.
We’ll doing four step in this tutorial:
- Create Stripe account
- Create new Laravel project
- Implement the Stripe docs
- Testing
Step 1 — Create Stripe account
In the first step, let’s create Stripe account with enter on this page url https://dashboard.stripe.com/register. Just following the step of registration, and you’ll success to have the Stripe account.
Step 2 — Create new Laravel project
Second step, we will create new project with Laravel, enter to terminal, and we can create new project like this, for example
composer create-project — prefer-dist laravel/larave laravelstripe
After that, we need to enter into the main directory of our new project.
cd laravelstripe
Step 3 — Implement the Stripe docs
In this step, we need to add stripe package into our composer file, with typing in terminal like this
composer require stripe/stripe-php
After that, we need to go to routes/api.php file and set a new route like this
Then, we need to create new controller, called PaymentController, we can type in our terminal, like this to create new controller
Now, open the controller, and create new function in there, say “paymentProcess”. Your controller should look like this
Don’t forget to change the “Replace with your secreet key” with your test secreet key from your Stripe dashboard.
For the Stripe payment button, we’ll put in the welcome view for an example, now open resources/views/welcome.blade.php file, and now your welcome view should be like this
Now, we can try to running our app, go to terminal and type
php artisan serve
Please try to access http://127.0.0.1:8000 in the browser, and we should look like this
Step 4 — Testing
Now, we can try to click the Stripe payment button, and will show a popup like this
Try to fill all of form, fill email form with our email address, and card number form with “4242 4242 4242 4242”, then fill the month and year and then fill the CVC with any 3 digit numbers. Then click “Pay”. After that, we can check into our Stripe dashboard, and if the payment is successful, we will look at our dashboard like this
That mean, our payment integration between Laravel and Stripe are successful.
Thanks for read this tutorial, hopefully this tutorial help you all guys :)
Thanks