#laravelcashier
Explore tagged Tumblr posts
iqonicdesign · 2 months ago
Text
🎥🚀 Unlock the potential of your video content! Learn how to build a subscription-based platform with Laravel Cashier and start monetizing today.
Read More - https://tinyurl.com/b9bzasn4
0 notes
codesolutionsstuff · 3 years ago
Text
Laravel 8 Stripe Subscription Tutorial Using Cashier Example
Tumblr media
We'll examine how to establish a laravel subscription system utilising laravel cashier in this Laravel laravel 8 stripe subscription tutorial. In this laravel 8 cashier tutorial, I'll walk you through the steps so you can better understand and replicate the code for your project. You may be aware that Laravel provides us with their laravel cashier package, which allows us to conveniently handle the subscription system in Laravel. To make this laravel cashier stripe checkout page and laravel cashier subscription system, I'll utilise a Stripe payment gateway with Laravel cashier.
Table of Content
- Download Laravel - Make Auth - Install Cashier Package - Update User Model - Create Stripe Account to Get Stripe API Key and SECRET - Add Route - Create Controller - Create View File If we want to build a web application like Laracats or any other type of online application that requires a subscription system, we can utilise Laravel cashier to do so. We'll use Stripe and Laravel Billing subscriptions.
Step 1 : Download Laravel
We'll need a new Laravel application to make this laravel 8 stripe subscription tutorial. So run the following command to get it: composer create-project --prefer-dist laravel/laravel blog
Step 2 : Make Auth
In Laravel, we need users to create a subscription plan. As a result, we require authentication. To create an authentication system in Laravel, use the command below. composer require laravel/ui php artisan ui vue --auth We'll make advantage of the Laravel collective form. As a result, run the following command to install it: composer require laravelcollective/html
Step 3 : Install Cashier Package
You'll need the official Laravel cashier package for this stage. Using the command below, you can install the cashier package. So, open a terminal and type the following command: composer require laravel/cashier Then you should run. php artisan migrate You can publish them using the vendor: if we need to overwrite the migrations that come with the Cashier package. Artisan command: publish php artisan vendor:publish --tag="cashier-migrations"
Step 4 : Update User Model
Before implementing Cashier, we must first add the Billable trait to the User model, as seen below. appModelsUser.php use LaravelCashierBillable; class User extends Authenticatable { use Billable; } Cashier now thinks your Billable model is the AppModelsUser class that comes with Laravel once you add that Billable trait to the User model. You can modify this by specifying a different model in your.env file, such as: .env CASHIER_MODEL=AppModelsUser
Step 5 : Create Stripe Account to Get Stripe API Key and SECRET
If you don't already have a Stripe account, you'll need one to receive a Stripe API key and secret key at this step. So, open your browser and go to the Stripe official website to obtain your client secret code. .env STRIPE_KEY=pk_test***** STRIPE_SECRET=sk_test****** You'll need to construct all of your plans for your subscription plan system after that. As a result, make a comprehensive plan.
Step 6 : Add Route
We'll add a route to the route file in this stage, so open the web.php file and add two routes: the first is form, and the second is store stripe subscription. routes/web.php use IlluminateSupportFacadesRoute; use AppHttpControllersSubscriptionController; Route::get('/subscription/create', )->name('subscription.create'); Route::post('order-post', );
Step 7 : Create Controller
Now we must develop a SubscriptionController, which must be used above both methods. app/Http/Controllers/SubscriptionController.php namespace AppHttpControllers; use IlluminateHttpRequest; Use AppModelsUser; use Stripe; use Session; use Exception; class SubscriptionController extends Controller { public function index() { return view('subscription.create'); } public function orderPost(Request $request) { $user = auth()->user(); $input = $request->all(); $token = $request->stripeToken; $paymentMethod = $request->paymentMethod; try { StripeStripe::setApiKey(env('STRIPE_SECRET')); if (is_null($user->stripe_id)) { $stripeCustomer = $user->createAsStripeCustomer(); } StripeCustomer::createSource( $user->stripe_id, ); $user->newSubscription('test',$input) ->create($paymentMethod, ); return back()->with('success','Subscription is completed.'); } catch (Exception $e) { return back()->with('success',$e->getMessage()); } } }
Step 8: Create View File
Last but not least, you can make a view blade file by first making a subscription directory and then making the blade file in the subscription directory. resources/views/subscription/create.blade.php Laravel
Laravel 8 Stripe Subscription Example - CodeSolutionStuff
Laravel 8 Stripe Subscription Example - CodeSolutionStuff {!! Form::open() !!} @if ($message = Session::get('success')) × {{ $message }} @endif {!! Form::label('plane', 'Select Plan:') !!} {!! Form::select('plane', , 'Book', ) !!} {!! Form::label(null, 'Credit card number:') !!} {!! Form::text(null, null, ) !!} {!! Form::label(null, 'CVC (3 or 4 digit number):') !!} {!! Form::text(null, null, ) !!} {!! Form::label(null, 'Ex. Month') !!} {!! Form::selectMonth(null, null, , '%m') !!} {!! Form::label(null, 'Ex. Year') !!} {!! Form::selectYear(null, date('Y'), date('Y') + 10, null, ) !!} {!! Form::submit('Place order!', ) !!} {!! Form::close() !!} Everything is ready to go. You can try it out and let me know if there are any problems. I hope you will like the content and it will help you to learn Laravel 8 Stripe Subscription Tutorial Using Cashier Example If you like this content, do share. Read the full article
0 notes