{"id":336,"date":"2025-08-27T19:59:23","date_gmt":"2025-08-27T19:59:23","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=336"},"modified":"2025-08-27T20:00:29","modified_gmt":"2025-08-27T20:00:29","slug":"how-to-integrate-stripe-payments-in-laravel","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/how-to-integrate-stripe-payments-in-laravel\/","title":{"rendered":"How to Integrate Stripe Payments in Laravel"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>How to Integrate Stripe Payments in Laravel<\/strong><\/h2>\n\n\n\n<p>Stripe is one of the most popular payment processors for web apps. Laravel makes it simple to integrate using the official <code>stripe\/stripe-php<\/code> SDK. In this guide, you\u2019ll set up Stripe, create checkout sessions, handle webhooks, and build a small UI to accept payments securely.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1 &#8211; Install Stripe SDK<\/strong><\/h2>\n\n\n\n<p>Start by requiring the Stripe PHP SDK with Composer.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">composer require stripe\/stripe-php<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This installs the official Stripe library, giving you access to Checkout Sessions, PaymentIntents, and webhooks.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 &#8211; Configure API Keys<\/strong><\/h2>\n\n\n\n<p>Add your Stripe keys to <code>.env<\/code> so you can access them securely in your code.<\/p>\n\n\n<!-- DomainException(0): Unknown language: \"dotenv\" -->STRIPE_KEY=pk_test_1234567890\nSTRIPE_SECRET=sk_test_1234567890\n\n\n<p><code>STRIPE_KEY<\/code> is the publishable key for the frontend, and <code>STRIPE_SECRET<\/code> is the secret key used on the backend. Never expose the secret key in your views.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3 &#8211; Checkout Controller<\/strong><\/h2>\n\n\n\n<p>Create a controller that initializes a Stripe Checkout Session when a user wants to make a purchase.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/CheckoutController.php<\/span>\n<span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>;\n\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Request<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Stripe<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Checkout<\/span>\\<span class=\"hljs-title\">Session<\/span> <span class=\"hljs-title\">as<\/span> <span class=\"hljs-title\">CheckoutSession<\/span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CheckoutController<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Controller<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">create<\/span><span class=\"hljs-params\">(Request $request)<\/span>\n    <\/span>{\n        Stripe::setApiKey(config(<span class=\"hljs-string\">'services.stripe.secret'<\/span>));\n\n        $session = CheckoutSession::create(&#91;\n            <span class=\"hljs-string\">'payment_method_types'<\/span> =&gt; &#91;<span class=\"hljs-string\">'card'<\/span>],\n            <span class=\"hljs-string\">'line_items'<\/span> =&gt; &#91;&#91;\n                <span class=\"hljs-string\">'price_data'<\/span> =&gt; &#91;\n                    <span class=\"hljs-string\">'currency'<\/span> =&gt; <span class=\"hljs-string\">'usd'<\/span>,\n                    <span class=\"hljs-string\">'unit_amount'<\/span> =&gt; <span class=\"hljs-number\">1999<\/span>, <span class=\"hljs-comment\">\/\/ $19.99<\/span>\n                    <span class=\"hljs-string\">'product_data'<\/span> =&gt; &#91;\n                        <span class=\"hljs-string\">'name'<\/span> =&gt; <span class=\"hljs-string\">'Pro Subscription'<\/span>,\n                    ],\n                ],\n                <span class=\"hljs-string\">'quantity'<\/span> =&gt; <span class=\"hljs-number\">1<\/span>,\n            ]],\n            <span class=\"hljs-string\">'mode'<\/span> =&gt; <span class=\"hljs-string\">'payment'<\/span>,\n            <span class=\"hljs-string\">'success_url'<\/span> =&gt; url(<span class=\"hljs-string\">'\/payment-success?session_id={CHECKOUT_SESSION_ID}'<\/span>),\n            <span class=\"hljs-string\">'cancel_url'<\/span> =&gt; url(<span class=\"hljs-string\">'\/payment-cancel'<\/span>),\n        ]);\n\n        <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'id'<\/span> =&gt; $session-&gt;id]);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This method creates a checkout session for one product (<code>Pro Subscription<\/code>) at $19.99. On success, Stripe redirects to <code>\/payment-success<\/code>; if canceled, to <code>\/payment-cancel<\/code>.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4 &#8211; Webhook Handling<\/strong><\/h2>\n\n\n\n<p>Stripe uses webhooks to notify your app about successful payments. Handle them to mark orders as paid.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/StripeWebhookController.php<\/span>\n<span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>;\n\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Request<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Webhook<\/span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">StripeWebhookController<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Controller<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">handle<\/span><span class=\"hljs-params\">(Request $request)<\/span>\n    <\/span>{\n        $endpointSecret = config(<span class=\"hljs-string\">'services.stripe.webhook_secret'<\/span>);\n        $sigHeader = $request-&gt;header(<span class=\"hljs-string\">'Stripe-Signature'<\/span>);\n        $payload = $request-&gt;getContent();\n\n        <span class=\"hljs-keyword\">try<\/span> {\n            $event = Webhook::constructEvent($payload, $sigHeader, $endpointSecret);\n        } <span class=\"hljs-keyword\">catch<\/span> (\\<span class=\"hljs-keyword\">Exception<\/span> $e) {\n            <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'error'<\/span> =&gt; $e-&gt;getMessage()], <span class=\"hljs-number\">400<\/span>);\n        }\n\n        <span class=\"hljs-keyword\">if<\/span> ($event-&gt;type === <span class=\"hljs-string\">'checkout.session.completed'<\/span>) {\n            $session = $event-&gt;data-&gt;object;\n            <span class=\"hljs-comment\">\/\/ Lookup order, mark as paid<\/span>\n        }\n\n        <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'status'<\/span> =&gt; <span class=\"hljs-string\">'success'<\/span>]);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The webhook verifies the signature with <code>webhook_secret<\/code>. On <code>checkout.session.completed<\/code>, update your DB to reflect a successful payment. Always validate events this way to prevent spoofing.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5 &#8211; API Routes<\/strong><\/h2>\n\n\n\n<p>Add routes for creating checkout sessions and handling Stripe webhooks.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ routes\/api.php<\/span>\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>\\<span class=\"hljs-title\">CheckoutController<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>\\<span class=\"hljs-title\">StripeWebhookController<\/span>;\n\nRoute::post(<span class=\"hljs-string\">'\/checkout'<\/span>, &#91;CheckoutController::class, <span class=\"hljs-string\">'create'<\/span>]);\nRoute::post(<span class=\"hljs-string\">'\/stripe\/webhook'<\/span>, &#91;StripeWebhookController::class, <span class=\"hljs-string\">'handle'<\/span>]);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Clients call <code>\/api\/checkout<\/code> to start a payment, and Stripe calls <code>\/api\/stripe\/webhook<\/code> when payments succeed or fail.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6 &#8211; UI: Payment Button with Stripe.js<\/strong><\/h2>\n\n\n\n<p>Use Stripe.js on the frontend to redirect customers to the hosted checkout page.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-comment\">&lt;!-- resources\/views\/payment.blade.php --&gt;<\/span>\n@extends('layouts.app')\n\n@section('content')\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"container\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Buy Pro Subscription<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"checkout-button\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"btn btn-theme\"<\/span>&gt;<\/span>Pay $19.99<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/js.stripe.com\/v3\/\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\">\n<span class=\"hljs-keyword\">const<\/span> stripe = Stripe(<span class=\"hljs-string\">\"{{ config('services.stripe.key') }}\"<\/span>);\n\n<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">\"checkout-button\"<\/span>).addEventListener(<span class=\"hljs-string\">\"click\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  fetch(<span class=\"hljs-string\">\"\/api\/checkout\"<\/span>, { <span class=\"hljs-attr\">method<\/span>: <span class=\"hljs-string\">\"POST\"<\/span> })\n    .then(<span class=\"hljs-function\"><span class=\"hljs-params\">res<\/span> =&gt;<\/span> res.json())\n    .then(<span class=\"hljs-function\"><span class=\"hljs-params\">data<\/span> =&gt;<\/span> {\n      stripe.redirectToCheckout({ <span class=\"hljs-attr\">sessionId<\/span>: data.id });\n    });\n});\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n@endsection<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This Blade file adds a payment button. When clicked, it requests a checkout session from Laravel, then redirects the user to Stripe Checkout securely.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>You just integrated Stripe with Laravel by installing the SDK, configuring keys, creating checkout sessions, handling webhooks, and building a UI with Stripe.js. This flow ensures secure payments and reliable updates to your database when charges succeed.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s Next<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/blog\/paypal-integration-in-laravel-step-by-step\">PayPal Integration in Laravel (Step by Step)<\/a><\/li>\n<li><a href=\"\/blog\/how-to-build-a-secure-file-upload-api-in-laravel\">How to Build a Secure File Upload API in Laravel<\/a><\/li>\n<li><a href=\"\/blog\/automating-laravel-deployments-with-deployer\">Automating Laravel Deployments with Deployer<\/a><\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Integrate Stripe Payments in Laravel<\/strong><\/h2>\n\n\n\n<p>Stripe is one of the most popular payment processors for web apps. Laravel makes it simple to integrate using the official <code>stripe\/stripe-php<\/code> SDK. In this guide, you\u2019ll set up Stripe, create checkout sessions, handle webhooks, and build a small UI to accept payments securely.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1 &#8211; Install Stripe SDK<\/strong><\/h2>\n\n\n\n<p>Start by requiring the Stripe PHP SDK with Composer.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">composer require stripe\/stripe-php<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This installs the official Stripe library, giving you access to Checkout Sessions, PaymentIntents, and webhooks.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 &#8211; Configure API Keys<\/strong><\/h2>\n\n\n\n<p>Add your Stripe keys to <code>.env<\/code> so you can access them securely in your code.<\/p>\n\n\n<!-- DomainException(0): Unknown language: \"dotenv\" -->STRIPE_KEY=pk_test_1234567890\nSTRIPE_SECRET=sk_test_1234567890\n\n\n<p><code>STRIPE_KEY<\/code> is the publishable key for the frontend, and <code>STRIPE_SECRET<\/code> is the secret key used on the backend. Never expose the secret key in your views.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3 &#8211; Checkout Controller<\/strong><\/h2>\n\n\n\n<p>Create a controller that initializes a Stripe Checkout Session when a user wants to make a purchase.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/CheckoutController.php<\/span>\n<span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>;\n\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Request<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Stripe<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Checkout<\/span>\\<span class=\"hljs-title\">Session<\/span> <span class=\"hljs-title\">as<\/span> <span class=\"hljs-title\">CheckoutSession<\/span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CheckoutController<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Controller<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">create<\/span><span class=\"hljs-params\">(Request $request)<\/span>\n    <\/span>{\n        Stripe::setApiKey(config(<span class=\"hljs-string\">'services.stripe.secret'<\/span>));\n\n        $session = CheckoutSession::create(&#91;\n            <span class=\"hljs-string\">'payment_method_types'<\/span> =&gt; &#91;<span class=\"hljs-string\">'card'<\/span>],\n            <span class=\"hljs-string\">'line_items'<\/span> =&gt; &#91;&#91;\n                <span class=\"hljs-string\">'price_data'<\/span> =&gt; &#91;\n                    <span class=\"hljs-string\">'currency'<\/span> =&gt; <span class=\"hljs-string\">'usd'<\/span>,\n                    <span class=\"hljs-string\">'unit_amount'<\/span> =&gt; <span class=\"hljs-number\">1999<\/span>, <span class=\"hljs-comment\">\/\/ $19.99<\/span>\n                    <span class=\"hljs-string\">'product_data'<\/span> =&gt; &#91;\n                        <span class=\"hljs-string\">'name'<\/span> =&gt; <span class=\"hljs-string\">'Pro Subscription'<\/span>,\n                    ],\n                ],\n                <span class=\"hljs-string\">'quantity'<\/span> =&gt; <span class=\"hljs-number\">1<\/span>,\n            ]],\n            <span class=\"hljs-string\">'mode'<\/span> =&gt; <span class=\"hljs-string\">'payment'<\/span>,\n            <span class=\"hljs-string\">'success_url'<\/span> =&gt; url(<span class=\"hljs-string\">'\/payment-success?session_id={CHECKOUT_SESSION_ID}'<\/span>),\n            <span class=\"hljs-string\">'cancel_url'<\/span> =&gt; url(<span class=\"hljs-string\">'\/payment-cancel'<\/span>),\n        ]);\n\n        <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'id'<\/span> =&gt; $session-&gt;id]);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This method creates a checkout session for one product (<code>Pro Subscription<\/code>) at $19.99. On success, Stripe redirects to <code>\/payment-success<\/code>; if canceled, to <code>\/payment-cancel<\/code>.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4 &#8211; Webhook Handling<\/strong><\/h2>\n\n\n\n<p>Stripe uses webhooks to notify your app about successful payments. Handle them to mark orders as paid.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Http\/Controllers\/StripeWebhookController.php<\/span>\n<span class=\"hljs-keyword\">namespace<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>;\n\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Illuminate<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Request<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">Stripe<\/span>\\<span class=\"hljs-title\">Webhook<\/span>;\n\n<span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">StripeWebhookController<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Controller<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">handle<\/span><span class=\"hljs-params\">(Request $request)<\/span>\n    <\/span>{\n        $endpointSecret = config(<span class=\"hljs-string\">'services.stripe.webhook_secret'<\/span>);\n        $sigHeader = $request-&gt;header(<span class=\"hljs-string\">'Stripe-Signature'<\/span>);\n        $payload = $request-&gt;getContent();\n\n        <span class=\"hljs-keyword\">try<\/span> {\n            $event = Webhook::constructEvent($payload, $sigHeader, $endpointSecret);\n        } <span class=\"hljs-keyword\">catch<\/span> (\\<span class=\"hljs-keyword\">Exception<\/span> $e) {\n            <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'error'<\/span> =&gt; $e-&gt;getMessage()], <span class=\"hljs-number\">400<\/span>);\n        }\n\n        <span class=\"hljs-keyword\">if<\/span> ($event-&gt;type === <span class=\"hljs-string\">'checkout.session.completed'<\/span>) {\n            $session = $event-&gt;data-&gt;object;\n            <span class=\"hljs-comment\">\/\/ Lookup order, mark as paid<\/span>\n        }\n\n        <span class=\"hljs-keyword\">return<\/span> response()-&gt;json(&#91;<span class=\"hljs-string\">'status'<\/span> =&gt; <span class=\"hljs-string\">'success'<\/span>]);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The webhook verifies the signature with <code>webhook_secret<\/code>. On <code>checkout.session.completed<\/code>, update your DB to reflect a successful payment. Always validate events this way to prevent spoofing.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5 &#8211; API Routes<\/strong><\/h2>\n\n\n\n<p>Add routes for creating checkout sessions and handling Stripe webhooks.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ routes\/api.php<\/span>\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>\\<span class=\"hljs-title\">CheckoutController<\/span>;\n<span class=\"hljs-keyword\">use<\/span> <span class=\"hljs-title\">App<\/span>\\<span class=\"hljs-title\">Http<\/span>\\<span class=\"hljs-title\">Controllers<\/span>\\<span class=\"hljs-title\">StripeWebhookController<\/span>;\n\nRoute::post(<span class=\"hljs-string\">'\/checkout'<\/span>, &#91;CheckoutController::class, <span class=\"hljs-string\">'create'<\/span>]);\nRoute::post(<span class=\"hljs-string\">'\/stripe\/webhook'<\/span>, &#91;StripeWebhookController::class, <span class=\"hljs-string\">'handle'<\/span>]);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Clients call <code>\/api\/checkout<\/code> to start a payment, and Stripe calls <code>\/api\/stripe\/webhook<\/code> when payments succeed or fail.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6 &#8211; UI: Payment Button with Stripe.js<\/strong><\/h2>\n\n\n\n<p>Use Stripe.js on the frontend to redirect customers to the hosted checkout page.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-comment\">&lt;!-- resources\/views\/payment.blade.php --&gt;<\/span>\n@extends('layouts.app')\n\n@section('content')\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"container\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Buy Pro Subscription<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"checkout-button\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"btn btn-theme\"<\/span>&gt;<\/span>Pay $19.99<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"https:\/\/js.stripe.com\/v3\/\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\">\n<span class=\"hljs-keyword\">const<\/span> stripe = Stripe(<span class=\"hljs-string\">\"{{ config('services.stripe.key') }}\"<\/span>);\n\n<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">\"checkout-button\"<\/span>).addEventListener(<span class=\"hljs-string\">\"click\"<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  fetch(<span class=\"hljs-string\">\"\/api\/checkout\"<\/span>, { <span class=\"hljs-attr\">method<\/span>: <span class=\"hljs-string\">\"POST\"<\/span> })\n    .then(<span class=\"hljs-function\"><span class=\"hljs-params\">res<\/span> =&gt;<\/span> res.json())\n    .then(<span class=\"hljs-function\"><span class=\"hljs-params\">data<\/span> =&gt;<\/span> {\n      stripe.redirectToCheckout({ <span class=\"hljs-attr\">sessionId<\/span>: data.id });\n    });\n});\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n@endsection<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This Blade file adds a payment button. When clicked, it requests a checkout session from Laravel, then redirects the user to Stripe Checkout securely.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>You just integrated Stripe with Laravel by installing the SDK, configuring keys, creating checkout sessions, handling webhooks, and building a UI with Stripe.js. This flow ensures secure payments and reliable updates to your database when charges succeed.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s Next<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/blog\/paypal-integration-in-laravel-step-by-step\">PayPal Integration in Laravel (Step by Step)<\/a><\/li>\n<li><a href=\"\/blog\/how-to-build-a-secure-file-upload-api-in-laravel\">How to Build a Secure File Upload API in Laravel<\/a><\/li>\n<li><a href=\"\/blog\/automating-laravel-deployments-with-deployer\">Automating Laravel Deployments with Deployer<\/a><\/li>\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>How to Integrate Stripe Payments in Laravel Stripe is one of the most popular payment processors for web apps. Laravel makes it simple to integrate using the official stripe\/stripe-php SDK. In this guide, you\u2019ll set up Stripe, create checkout sessions, handle webhooks, and build a small UI to accept payments securely. 1 &#8211; Install Stripe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":340,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[25,51,22,52],"class_list":["post-336","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-api","tag-payments","tag-security","tag-webhooks"],"_links":{"self":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/comments?post=336"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":339,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/336\/revisions\/339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/340"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}