Laravel 5.7 Stripe Payment Gateway Example From Scratch

Today, We want to share with you Laravel 5.7 Stripe Payment Gateway Example From Scratch.In this post we will show you Stripe Payment Gateway Integration using Laravel 5.7, hear for Laravel 5.7 – Stripe Payment Gateway Integration Example we will give you demo and example for implement.In this post, we will learn about Laravel Stripe Payment Gateway Integration Tutorial with an example.

Laravel 5.7 Stripe Payment Gateway Example From Scratch

There are the Following The simple About Laravel 5.7 Stripe Payment Gateway Example From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to integrate Stripe payment gateway in laravel 5.7, so the Integrate Laravel Stripe Gateway for Online Payments for this example is following below.

Phase 1: Install Laravel 5.7

composer create-project --prefer-dist laravel/laravel atmiya25

Phase 2: Install stripe-php Package

install stripe-php via the Composer package manager

composer require stripe/stripe-php

Phase 3: Set Stripe API Key and SECRET

.env files

STRIPE_KEY=pk_test_reFxwb98Js58diDf25TfxAR
STRIPE_SECRET=sk_test_oJSkdui85dJiPd4wDJsui5pY

Phase 4: Define a Laravel Routes

routes/api.php

name('stripe.post');

Phase 5: Create Controller File

app/Http/Controllers/CkPaymentStripeController.php

 100 * 100,
                "currency" => "usd",
                "source" => $request->liveTokenStripe,
                "description" => "Test payment from pakainfo.com." 
        ]);
  
        Session::flash('success', 'Your Payment successful!');
          
        return back();
    }
}

Phase 6: Make a Laravel Blade File

resources/views/stripe.blade.php



	<title>Laravel 5.7 Stripe Payment Gateway Example From Scratch - pakainfo.com</title>
	
    
    
        .panel-title {
        display: inline;
        font-weight: bold;
        }
        .display-table {
            display: table;
        }
        .display-tr {
            display: table-row;
        }
        .display-td {
            display: table-cell;
            vertical-align: middle;
            width: 61%;
        }
    


  
<div class="container">
  
    <h1>Laravel 5 - Stripe Payment Gateway Integration Example <br /> pakainfo.com</h1>
  <b>Laravel 5.7 Stripe Payment Gateway Example From Scratch</b>
    <div class="pakainfo row">
        <div class="col-md-6 col-md-offset-3">
            <div class="pakainfo panel panel-default credit-card-box">
                <div class="pakainfo panel-heading display-table">
                    <div class="row display-tr pakainfo">
                        <h3 class="panel-title display-td">Your Payment Details</h3>
                        <div class="display-td">                            
                            <img class="pakainfo img-responsive pull-right" src="http://i76.imgup.net/accepted_c22e0.png">
                        </div>
                    </div>                    
                </div>
                <div class="panel-body">
  
                    @if (Session::has('success'))
                        <div class="alert alert-success text-center">
                            <a href="#" class="pakainfo close">×</a>
                            <p>{{ Session::get('success') }}</p>
                        </div>
                    @endif
  
                    <form role="form" action="{{ route('stripe.post') }}" method="post" class="pakainfo require-validation" id="payment-form">
                        @csrf
  
                        <div class='pakainfo form-row pakainfo row'>
                            <div class='gst col-xs-12 live form-group required'>
                                <label class='control-label'>Name on Card</label> 
                            </div>
                        </div>
  
                        <div class='form-row pakainfo row'>
                            <div class='gst col-xs-12 live form-group card required'>
                                <label class='control-label'>Card Number</label> 
                            </div>
                        </div>
  
                        <div class='form-row pakainfo row'>
                            <div class='gst col-xs-12 live col-md-4 form-group cvc required'>
                                <label class='control-label'>CVC</label> 
                            </div>
                            <div class='gst col-xs-12 live col-md-4 form-group expiration required'>
                                <label class='control-label'>Expiration Month</label> 
                            </div>
                            <div class='gst col-xs-12 live col-md-4 form-group expiration required'>
                                <label class='control-label'>Expiration Year</label> 
                            </div>
                        </div>
  
                        <div class='form-row pakainfo row'>
                            <div class='col-md-12 error form-group hide'>
                                <div class='alert-danger alert'>Please Your correct the errors and try
                                    again.</div>
                            </div>
                        </div>
  
                        <div class="gst row">
                            <div class="gst col-xs-12 live">
                                <button class="btn btn-success btn-lg btn-block" type="submit">Pay Now ($100)</button>
                            </div>
                        </div>
                          
                    </form>
                </div>
            </div>        
        </div>
    </div>
      
</div>
  

  

  

$(function() {
    var $liveFrm         = $(".require-validation");
  $('form.require-validation').bind('submit', function(e) {
    var $liveFrm         = $(".require-validation"),
        inputSelector = ['input[type=email]', 'input[type=password]',
                         'input[type=text]', 'input[type=file]',
                         'textarea'].join(', '),
        $inputs       = $liveFrm.find('.required').find(inputSelector),
        $errorMessage = $liveFrm.find('div.error'),
        valid         = true;
        $errorMessage.addClass('hide');
 
        $('.has-error').removeClass('has-error');
    $inputs.each(function(i, el) {
      var $input = $(el);
      if ($input.val() === '') {
        $input.parent().addClass('has-error');
        $errorMessage.removeClass('hide');
        e.preventDefault();
      }
    });
  
    if (!$liveFrm.data('cc-on-file')) {
      e.preventDefault();
      Stripe.setPublishableKey($liveFrm.data('stripe-publishable-key'));
      Stripe.createToken({
        number: $('.card-number').val(),
        cvc: $('.card-cvc').val(),
        exp_month: $('.card-expiry-month').val(),
        exp_year: $('.card-expiry-year').val()
      }, stripeResponseHandler);
    }
  
  });
  
  function stripeResponseHandler(status, response) {
        if (response.error) {
            $('.error')
                .removeClass('hide')
                .find('.alert')
                .text(response.error.message);
        } else {
            var token = response['id'];
            $liveFrm.find('input[type=text]').empty();
            $liveFrm.append("");
            $liveFrm.get(0).submit();
        }
    }
  
});


Now We can check or testing purpose with following card Info:

//Testing Details
Your Name: Jaydeep Gondaliya
Number: 4242 4242 4242 4242
CSV: 715
Expiration Month: 12
Expiration Year: 2029

Angular 6 CRUD Operations Application Tutorials

Read :

Also Read :  jQuery Image slider with Next Button

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.7 Stripe Payment Gateway Example From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of