- Single payment: A single payment is what needs to be made only once. For example, making a payment to purchase through an ecommerce website.
- Recurring requital :
A recurring payment is that which you have to make more than once in a particular period of time. For example, subscribing to web hosting services for a web site.
In this web log, I will tell you how you can implement the recurring requital process in laravel. The blog will focus on implementing the stripe requital .
If you are into web development, this web log will be a very handy usher. You might besides want to check out how you can s et up chevron connect market score .
Let ‘s get started .
Implementing recurring payment with stripe
Step 1: Install Laravel Fresh Project
To begin, use the command below to install Laravel as a newly application, then open your command prompt and run it :
composer create-project — prefer-dist laravel/laravel stripeRecurringPayment
Step 2: Install Stripe box
composer require cartalyst/stripe-laravel
After that, you need to register the provider and aliases. Go to the app/config/app.php and enter the lines below :
‘ providers ’ = > [
… … … .
Cartalyst\Stripe\Laravel\StripeServiceProvider : :class
] ,
‘ aliases ’ = > [
… … … .
‘Stripe ‘ = > Cartalyst\Stripe\Laravel\Facades\Stripe : :class
] ,
Step 3: Set Secret Credential
now open .env file and set the secret certificate provided by a stripe payment gateway
STRIPE_KEY=pk_test_xxxxxxxxxxxxxxxxxxx
STRIPE_SECRET=sk_test_xxxxxxxxxxxxxx
adjacent step, you need to set up the Stripe API key, to do this open or create the config/services.php file, and add or update the ‘stripe ‘ array :
1
2
3
‘stripe ‘ = > [
‘secret ‘ = > env ( ‘STRIPE_SECRET ‘ ) ,
] ,
Step 4: Make route
route : :get ( ‘stripe ‘, ‘StripeController @ index ‘ ) ;
route : :post ( ‘store ‘, ‘StripeController @ shop ‘ ) ;
Step 5: Create Controller
In this tone, you need to create the accountant diagnose StripeController using the below dominate .
php artisan make : restrainer StripeController
Go to app/Http/Controller/StripeController and enter the below code :
php < /p
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Session;
use Stripe;
class StripeController extends Controller
{
/**
* success response method.
*
* @return \Illuminate\Http\Response
*/
public function stripe()
{
return view(‘stripe’);
}
/**
* success response method.
*
* @return \Illuminate\Http\Response
*/
public function stripePost(Request $request)
{
Stripe\Stripe::setApiKey(env(‘STRIPE_SECRET’));
//create customer
$customer = \Stripe\Customer::create([
‘name’ => ‘your name’,
‘address’ => [
‘line1’ => ‘your address’,
‘postal_code’ => ‘your postal code’,
‘city’ => ‘Your City,
‘state’ => ‘Your State Code’,
‘country’ => ‘Your Country Code’,
],
’email’ => ‘your email’,
‘source’ => $request->stripeToken
]);
$stripe = new \Stripe\StripeClient(
env(‘STRIPE_SECRET’)
);
$customer_id = $customer->id;
//create product
$product = $stripe->products->create([
‘name’ => ‘Diamond’,
‘id’ => ‘123’,
‘metadata’ => [
‘name’ => “silver”,
‘last-date’ => ’30-7-2021′
]
]);
$product_id = $product->id;
//define product price and recurring interval
$price = $stripe->prices->create([
‘unit_amount’ => 2000,
‘currency’ => ‘usd’,
‘recurring’ => [‘interval’ => ‘month’],
‘product’ => $product_id,
]);
Read more: What Is a PO Number?
$price_id = $price->id;
//CREATE SUBSCRIPTION
$subscription = $stripe->subscriptions->create([
‘customer’ => $customer_id,
‘items’ => [
[‘price’ => $price_id],
],
‘metadata’ => [
‘start_date’ => ’30-7-2021′,
‘total_months’ => ’11’,
‘end_date’ => ’30-5-2022′
]
]);
Session::flash(‘success’, ‘Payment successful!’);
return back();
}
}
In the above example, you can see that there are basically three things that are done with the stripe code.
- Creating customers
- Creating a recurring product
- Creating a subscription and assigning that subscription to the above created customer with the above created product.
How to create blade view file?
To create a frontend view you can simply use the Stripe code which shows the popup form and a form to store all the required information.
To create a blade views file, go to app/resources/views/ and create one file name stripe.blade.php
Pay for Event
@ if ( $ errors- > any ( ) )
Whoops! Something went incorrect
@ foreach ( $ errors- > all ( ) as $ error )
@ endforeach
@ endif
autocomplete=’off’ class=’form-control’ size=’20’
type=’text’ name=”card_no”>
class=’form-control’ placeholder=’ex. 311′ size=’3′
type=’text’ name=”ccv”>
class=’form-control’ placeholder=’MM’ size=’2′
type=’text’ name=”expiry_month”>
class=’form-control’ placeholder=’YYYY’ size=’4′
type=’text’ name=”expiry_year”>
total : $20
type=’submit’ style=”margin-top: 10px;”>Pay »
How to start exploitation server ?
In this footfall, you can use the php craftsman serve command. It will start your server locally .
php artisan serve
Testing Card Credential
Card No : 4242424242424242
Month : any future calendar month
class : any future year
CVV : 123
And there you have it. Use your show stripe keys to test the requital process .
nowadays, you can use these simple steps and implement this recurring requital action on your own .
To access the full code you can download it from my rotter repo .
hypertext transfer protocol : //github.com/iqbaldhillon116/laravelStripePayment.git
Wrapping Up
In this web log, I showed you how to do recurring deposits with Stripe. I believe the steps mentioned above are open and will assist you in achieving your objectives .
silent, if you require aid with web site development or the creation of a professional web site, Contact Us !
editor : Amrutha