{"id":1033,"date":"2024-05-26T07:33:54","date_gmt":"2024-05-26T07:33:54","guid":{"rendered":"https:\/\/www.appfinz.com\/blogs\/?p=1033"},"modified":"2025-05-15T05:02:30","modified_gmt":"2025-05-15T05:02:30","slug":"paypal-payment-gateway-integration-in-laravel-11","status":"publish","type":"post","link":"https:\/\/www.appfinz.com\/blogs\/paypal-payment-gateway-integration-in-laravel-11\/","title":{"rendered":"Paypal Payment Gateway Integration in Laravel 11"},"content":{"rendered":"\n<p>Hello everyone,<\/p>\n\n\n\n<p>In this post, we will guide you, how to implement <strong>Paypal Payment Gateway in Laravel 11<\/strong>. we will explain each step in detailed way that involves in implementing <strong>Paypal Payment Gateway in Laravel<\/strong>. if you are looking for any resources for Payment Gateway Implementation In Laravel 11 then you are right place.<\/p>\n\n\n\n<p>Let me quickly introduce you to implement payment gateway in laravel applications, To do this, we will utilize the <strong>srmklive\/paypal composer package.<\/strong>&nbsp;Firstly we will signup and generate Client ID and Secret ID, Then we will create an intent that capture payment, we will guide you through each and every steps of Paypal Payment Gateway Integration In laravel here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step for Laravel 10 PayPal Payment Gateway Integration<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Step 1:<\/strong>&nbsp;Install Laravel<\/li>\n\n\n\n<li><strong>Step 2:<\/strong>&nbsp;Install srmklive\/paypal Package<\/li>\n\n\n\n<li><strong>Step 3:<\/strong>&nbsp;Create PayPal Developer Account<\/li>\n\n\n\n<li><strong>Step 4:<\/strong>&nbsp;Create Route<\/li>\n\n\n\n<li><strong>Step 5:<\/strong>&nbsp;Create Controller<\/li>\n\n\n\n<li><strong>Step 6:<\/strong>&nbsp;Create Blade File<\/li>\n\n\n\n<li><strong>Run Laravel App<\/strong><\/li>\n<\/ul>\n\n\n\n<p>lets proceed to the step by step now:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"9b12\">1. Create a new project<\/h3>\n\n\n\n<p id=\"70f1\">Create a new project with the command as below.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer create-project laravel\/laravel paypal --prefer-dist<\/pre><\/div>\n\n\n\n<p>After the new project has been created, go to your project directory.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">cd paypal<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8cdb\">2. Install Packages for Paypal Payment Gateway Using Composer<\/h3>\n\n\n\n<p id=\"d434\">Run the following command.<\/p>\n\n\n\n<p id=\"5b28\">we will install&nbsp;<a href=\"https:\/\/srmklive.github.io\/laravel-paypal\/\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel-Paypal<\/a>&nbsp;for laravel 6,7, &amp; 8<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">composer require srmklive\/paypal:~3.0<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4b26\">3. Create PayPal credentials<\/h3>\n\n\n\n<p id=\"99bf\">After installing paypal package, we need client_id and secret_key for paypal integration, so we need to enter in paypal developer mode and create new sandbox account for the same. After login in paypal you need to get the client_id and secret_key as shown below. before getting client_id and secret_key we need to create application. So, check the screenshot below and build an app. Login to the&nbsp;<a href=\"https:\/\/www.paypal.com\/signin?returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications\" rel=\"noreferrer noopener\" target=\"_blank\">Developer Dashboard.<\/a><\/p>\n\n\n\n<p id=\"3de3\">Click Create Apps.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"828\" height=\"366\" src=\"https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2024\/05\/0_7ZGcg-bK_Q0ug28T.webp\" alt=\"\" class=\"wp-image-1035\" title=\"\" srcset=\"https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2024\/05\/0_7ZGcg-bK_Q0ug28T.webp 828w, https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2024\/05\/0_7ZGcg-bK_Q0ug28T-300x133.webp 300w, https:\/\/www.appfinz.com\/blogs\/wp-content\/uploads\/2024\/05\/0_7ZGcg-bK_Q0ug28T-768x339.webp 768w\" sizes=\"auto, (max-width: 828px) 100vw, 828px\" \/><\/figure>\n\n\n\n<p>Next you need to add PAYPAL_MODE, PAYPAL_SANDBOX_CLIENT_ID and PAYPAL_SANDBOX_CLIENT_SECRET on .env file as like bellow:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;.ENV&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">PAYPAL_MODE=sandbox\nPAYPAL_SANDBOX_CLIENT_ID=YourClientKey\nPAYPAL_SANDBOX_CLIENT_SECRET=YourClientSecret<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">4. Create Routes<\/h3>\n\n\n\n<p>Now we will add all neccessary routes in our web.php file which you can find under routes directory<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n  \nuse Illuminate\\Support\\Facades\\Route;\n  \nuse App\\Http\\Controllers\\PayPalController;\n  \n\/*\n|--------------------------------------------------------------------------\n| Web Routes\n|--------------------------------------------------------------------------\n|\n| Here is where you can register web routes for your application. These\n| routes are loaded by the RouteServiceProvider within a group which\n| contains the &quot;web&quot; middleware group. Now create something great!\n|\n*\/\n  \nRoute::get('paypal', [PayPalController::class, 'index'])-&gt;name('paypal');\nRoute::get('paypal\/payment', [PayPalController::class, 'payment'])-&gt;name('paypal.payment');\nRoute::get('paypal\/payment\/success', [PayPalController::class, 'paymentSuccess'])-&gt;name('paypal.payment.success');\nRoute::get('paypal\/payment\/cancel', [PayPalController::class, 'paymentCancel'])-&gt;name('paypal.payment\/cancel');<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">5. Create Controller <\/h3>\n\n\n\n<p>Now you need to make controller PaypalController using your default command console<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">php artisan make:controller PayPalController<\/pre><\/div>\n\n\n\n<p>and now open app\/Http\/Controllers\/PayPalController.php. and make functions working like this <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;?php\n  \nnamespace App\\Http\\Controllers;\n  \nuse Srmklive\\PayPal\\Services\\PayPal as PayPalClient;\nuse Illuminate\\Http\\Request;\n  \nclass PayPalController extends Controller\n{\n    \/**\n     * Write code on Method\n     *\n     * @return response()\n     *\/\n    public function index()\n    {\n        return view('paypal');\n    }\n  \n    \/**\n     * Write code on Method\n     *\n     * @return response()\n     *\/\n    public function payment(Request $request)\n    {\n        $provider = new PayPalClient;\n        $provider-&gt;setApiCredentials(config('paypal'));\n        $paypalToken = $provider-&gt;getAccessToken();\n  \n        $response = $provider-&gt;createOrder([\n            &quot;intent&quot; =&gt; &quot;CAPTURE&quot;,\n            &quot;application_context&quot; =&gt; [\n                &quot;return_url&quot; =&gt; route('paypal.payment.success'),\n                &quot;cancel_url&quot; =&gt; route('paypal.payment\/cancel'),\n            ],\n            &quot;purchase_units&quot; =&gt; [\n                0 =&gt; [\n                    &quot;amount&quot; =&gt; [\n                        &quot;currency_code&quot; =&gt; &quot;USD&quot;,\n                        &quot;value&quot; =&gt; &quot;100.00&quot;\n                    ]\n                ]\n            ]\n        ]);\n  \n        if (isset($response['id']) &amp;&amp; $response['id'] != null) {\n  \n            foreach ($response['links'] as $links) {\n                if ($links['rel'] == 'approve') {\n                    return redirect()-&gt;away($links['href']);\n                }\n            }\n  \n            return redirect()\n                -&gt;route('cancel.payment')\n                -&gt;with('error', 'Something went wrong.');\n  \n        } else {\n            return redirect()\n                -&gt;route('create.payment')\n                -&gt;with('error', $response['message'] ?? 'Something went wrong.');\n        }\n    \n    }\n  \n    \/**\n     * Write code on Method\n     *\n     * @return response()\n     *\/\n    public function paymentCancel()\n    {\n        return redirect()\n              -&gt;route('paypal')\n              -&gt;with('error', $response['message'] ?? 'You have canceled the transaction.');\n    }\n  \n    \/**\n     * Write code on Method \n     * Written by Appfinz Technologies\n     * @return response()\n     *\/\n    public function paymentSuccess(Request $request)\n    {\n        $provider = new PayPalClient;\n        $provider-&gt;setApiCredentials(config('paypal'));\n        $provider-&gt;getAccessToken();\n        $response = $provider-&gt;capturePaymentOrder($request['token']);\n  \n        if (isset($response['status']) &amp;&amp; $response['status'] == 'COMPLETED') {\n            return redirect()\n                -&gt;route('paypal')\n                -&gt;with('success', 'Transaction complete.');\n        } else {\n            return redirect()\n                -&gt;route('paypal')\n                -&gt;with('error', $response['message'] ?? 'Something went wrong.');\n        }\n    }\n}<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">6. Create View\/Blade File<\/h3>\n\n\n\n<p>here, we need to create paypal.blade.php file and update following code on it.<\/p>\n\n\n\n<p><strong>resources\/views\/paypal.blade.php<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text\/x-php&quot;,&quot;theme&quot;:&quot;midnight&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;PHP&quot;,&quot;language&quot;:&quot;PHP&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;php&quot;}\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;utf-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;\n    &lt;title&gt;Paypal Payment Gateway Integration in Laravel - Appfinz.com&lt;\/title&gt;\n    &lt;link href=&quot;https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.0.2\/dist\/css\/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;div class=&quot;container&quot;&gt;\n    &lt;div class=&quot;row mt-5 mb-5&quot;&gt;\n        &lt;div class=&quot;col-10 offset-1 mt-5&quot;&gt;\n            &lt;div class=&quot;card&quot;&gt;\n                &lt;div class=&quot;card-header bg-primary&quot;&gt;\n                    &lt;h3 class=&quot;text-white&quot;&gt;Laravel PayPal Payment Gateway Integration Example - www.appfinz.com&lt;\/h3&gt;\n                &lt;\/div&gt;\n                &lt;div class=&quot;card-body&quot;&gt;\n  \n                    @if ($message = Session::get('success'))\n                      &lt;div class=&quot;alert alert-success alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;\n                        &lt;strong&gt;{{ $message }}&lt;\/strong&gt;\n                        &lt;button type=&quot;button&quot; class=&quot;btn-close&quot; data-bs-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;&lt;\/button&gt;\n                      &lt;\/div&gt;\n                    @endif\n  \n                    @if ($message = Session::get('error'))\n                        &lt;div class=&quot;alert alert-danger alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;\n                          &lt;strong&gt;{{ $message }}&lt;\/strong&gt;\n                          &lt;button type=&quot;button&quot; class=&quot;btn-close&quot; data-bs-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;&lt;\/button&gt;\n                        &lt;\/div&gt;\n                    @endif\n                          \n                    &lt;center&gt;\n                        &lt;a href=&quot;{{ route('paypal.payment') }}&quot; class=&quot;btn btn-success&quot;&gt;Pay with PayPal &lt;\/a&gt;\n                    &lt;\/center&gt;\n  \n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Run Laravel App with Paypal Now<\/h2>\n\n\n\n<p>Open Command Console and hit PHP Artisan serve within the same directory of your laravel application<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan serve<\/code><\/pre>\n\n\n\n<p>Now, Go to your web browser, type the given URL and view the app output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;localhost:8000\/paypal<\/code><\/pre>\n\n\n\n<p>If you are looking for these tools <\/p>\n\n\n\n<p><a href=\"https:\/\/www.appfinz.com\/tools\/jpg-image-compressor\/\">JPEG Image Compressor<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/www.appfinz.com\/tools\/youtube-vimeo-thumbnail-downloader\/\">Youtube Thumbnail Grabber<\/a><\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:#e3ecf2\">If you\u2019re planning to revamp your online presence, don\u2019t miss exploring our\u00a0<a href=\"https:\/\/www.appfinz.com\/website-designing-company-in-delhi\"><strong>website designing services<\/strong><\/a>\u00a0and custom\u00a0<strong><a href=\"https:\/\/www.appfinz.com\/website-development-company-in-delhi\">website development<\/a><\/strong>\u00a0solutions tailored to your business needs.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone, In this post, we will guide you, how to implement Paypal Payment Gateway<\/p>\n","protected":false},"author":1,"featured_media":1036,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,211],"tags":[146,148,147],"class_list":["post-1033","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-payment-gateway","tag-paypal-integration","tag-paypal-integration-in-laravel","tag-paypal-payment-gateway-integration"],"_links":{"self":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1033"}],"version-history":[{"count":5,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1033\/revisions"}],"predecessor-version":[{"id":1367,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/posts\/1033\/revisions\/1367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media\/1036"}],"wp:attachment":[{"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appfinz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}