How To Use Paypal Payment Gateway In Laravel Framework
In this tutorial, we will tell you how to use the Paypal payment gateway in Laravel Framework.
The Paypal payment gateway is a popular payment gateway method and it is easily used for the project. so many developers prefer that payment gateway method.
PayPal is a secure payment method and it’s work-based using API. it provides two environments for the user like a sandbox and live.
Now, we will go to the official PayPal site and after then log in, we have to need the Business email id and buyer email id. first, we will install the laravel, configuration of the database and migration database. after then we will get the cart of the product and that product data pass into PayPal form. but here we will use static form data. you can make a dynamic form of data.
HomeController.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Response; class HomeController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // return view('paypal'); } public function cancel() { // echo "Payment Transaction is Failed."; } public function success() { // echo "Payment Transaction is successfully"; } ?> |
app.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.js"></script> </head> <body> <div class="container"> @yield('content') </div> </body> </html> |
paypal.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | @extends('app') @section('content') <div class="row"> <div class="col-lg-12"> <h2>How To Use Paypal Payment Gateway In Laravel Framework</h2> </div> </div> <div class="row"> <div class="col-lg-4"> </div> <div class="col-lg-4"> <img src="https://images-na.ssl-images-amazon.com/images/I/315sKf9Qr5L.jpg" /> <p>Xiamoi Mi Smart Watch Phones with Camera</p> <p>$ 12</p> <?php $paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL ?> <form action="<?php echo $paypal_url; ?>" method="post" name="frmPayPal" id="frmPayPal"> @csrf <!-- Identify your business so that you can collect the payments. --> <input type="hidden" name="business" value="<?php echo $paypal_id; ?>"> <!-- Specify a PayPal Shopping Cart Add to Cart button. --> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <!-- Specify details about the item that buyers will purchase. --> <input type="hidden" name="item_name_1" value="Xiamoi Mi Smart Watch Phones with Camera"> <input type="hidden" name="amount_1" value="12"> <input type="hidden" name="quantity_1" value="2"> <input type="hidden" name="shipping_1" value="10"> <input type="hidden" name="currency_code" value="USD"> <!-- Display header page logo. --> <input type="hidden" name="cpp_header_image" value="https://xpertphp.com/assets/front/images/logoxp.png"> <!-- payment success or cancel then after show page. --> <input type="hidden" name="cancel_return" value=""> <input type="hidden" name="return" value=""> <input type='hidden' name='rm' value='2'> <!-- Display the payment button. --> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </div> </div> @endsection |
routes/web.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { // return view('welcome'); }); Route::get('paypal','StudentController@index'); Route::get('paypal/cancel','StudentController@cancel'); Route::get('paypal/success','StudentController@success'); ?> |