{"id":2942,"date":"2017-11-20T19:00:47","date_gmt":"2017-11-20T19:00:47","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=2942"},"modified":"2025-11-24T15:07:19","modified_gmt":"2025-11-24T15:07:19","slug":"stripe-payment-gateway-integration-php","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/","title":{"rendered":"Stripe Payment Gateway Integration in PHP"},"content":{"rendered":"<p>The <b>Stripe payment gateway<\/b> provides an easy and powerful way to accept credit cards directly on the web application. Stripe makes integrating the checkout system and collecting payment on the website easy. The <b>Stripe API<\/b> is a powerful solution to integrate the checkout system into the web application to provide a smooth payment experience.<\/p>\n<p>If you want to <b>accept credit card payments on your website<\/b>, Stripe will be the best option for that. You can easily integrate the checkout system into your PHP-based website, which allows the user to make payments through credit or debit cards without leaving your website. This tutorial will show you how to integrate the <b>Stripe payment gateway in PHP<\/b> for collecting payments online using credit or debit cards.<\/p>\n<p>In the example script, we will implement the following functionality to demonstrate the <b>Stripe payment gateway integration<\/b> process.<\/p>\n<ul>\n<li>Create an HTML form to collect credit card information.<\/li>\n<li>Create a PaymentIntent using the Stripe PHP library.<\/li>\n<li>Attach card input elements to HTML form using Stripe JS library.<\/li>\n<li>Securely transmit card information, validate, charge and confirm the payment using Stripe API.<\/li>\n<li>Retrieve PaymentIntent and customer information using Stripe API.<\/li>\n<li>Insert transaction details in the database and display the payment status.<\/li>\n<li>Integrate 3D Secure payment to support Strong Customer Authentication (SCA).<\/li>\n<\/ul>\n<h2>Stripe Test API Keys Data<\/h2>\n<p>Before making your Stripe payment gateway integration live, you need to test it thoroughly. To test the credit card payment process with Stripe, the test API Keys are required. You can generate and get the TEST DATA in your Stripe account.<\/p>\n<ul class=\"step_list\">\n<li>Login to your <a href=\"https:\/\/dashboard.stripe.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Stripe account<\/a> and navigate to the <b>Developers &raquo; API keys<\/b> page.<\/li>\n<li>In the TEST DATA, you&#8217;ll see the API keys (Publishable key and Secret key) are listed under the <b>Standard keys<\/b> section. To show the <b>Secret key<\/b>, click on <b>Reveal test key<\/b> button.\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-1024x566.png\" alt=\"stripe-developer-test-data-publishable-secret-api-keys-codexworld\" width=\"960\" height=\"531\" class=\"alignnone size-large wp-image-4048\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-1024x566.png 1024w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-300x166.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-768x424.png 768w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-200x111.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld-346x191.png 346w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-developer-test-data-publishable-secret-api-keys-codexworld.png 1263w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/div>\n<\/li>\n<\/ul>\n<p>Collect the <b>Publishable key<\/b> and <b>Secret key<\/b> to later use in the script.<\/p>\n<h2>\ud83d\udcc1 Folder Structure<\/h2>\n<p>Before getting started to integrate Stripe payment gateway in PHP, take a look at the file structure for this tutorial:<\/p>\n<pre class=\"file-struc\">stripe_integration_in_php<span style=\"color:#794938\">\/<\/span>\r\n\u251c\u2500\u2500 config.php\r\n\u251c\u2500\u2500 dbConnect.php\r\n\u251c\u2500\u2500 index.php\r\n\u251c\u2500\u2500 payment_init.php\r\n\u251c\u2500\u2500 payment-status.php\r\n\u251c\u2500\u2500 stripe-php<span style=\"color:#794938\">\/<\/span>\r\n\u251c\u2500\u2500 js<span style=\"color:#794938\">\/<\/span>\r\n|    \u2514\u2500\u2500 checkout.js\r\n\u2514\u2500\u2500 css<span style=\"color:#794938\">\/<\/span>\r\n    \u2514\u2500\u2500 style.css\r\n<\/pre>\n<p><b>Lets&#8217;s get started with the Stripe payment gateway integration in PHP and accept credit card payments on your website.<\/b><\/p>\n<h2>Stripe PHP library<\/h2>\n<p>This tutorial uses the Stripe PHP library to access the Stripe API from PHP applications. You can download it from its official <a href=\"https:\/\/github.com\/stripe\/stripe-php\" target=\"_blank\">GitHub repository<\/a> or install it via Composer:<\/p>\n<pre>composer require stripe\/stripe-php<\/pre>\n<p><u><b>Note:<\/b> All the required library files are already included in our ready-to-download source code ZIP package. You don\u2019t need to download or install it separately.<\/u><\/p>\n<h2>\u2699\ufe0f Create the Database and Table<\/h2>\n<p>First, create a MySQL database (e.g., <code>checkout_db<\/code>) and a table (e.g., <code>transactions<\/code>) to store the payment information. You can use phpMyAdmin or any MySQL client to run the following SQL commands:<\/p>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">CREATE<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">TABLE<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`transactions`<\/span> (\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">int<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">11<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span> AUTO_INCREMENT,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`customer_name`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`customer_email`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`item_name`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">255<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`item_price`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">float<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">10<\/span>,<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">2<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`item_price_currency`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">10<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`paid_amount`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">float<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">10<\/span>,<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">2<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`paid_amount_currency`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">10<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`txn_id`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">50<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`payment_status`<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">varchar<\/span>(<span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">25<\/span>) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">NOT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`created`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`modified`<\/span> datetime <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">NULL<\/span>,\r\n  PRIMARY <span class=\"hljs-keyword\" style=\"font-weight: 700;\">KEY<\/span> (<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">`id`<\/span>)\r\n) <span class=\"hljs-keyword\" style=\"font-weight: 700;\">ENGINE<\/span>=<span class=\"hljs-keyword\" style=\"font-weight: 700;\">InnoDB<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">DEFAULT<\/span> <span class=\"hljs-keyword\" style=\"font-weight: 700;\">CHARSET<\/span>=utf8mb4;<\/pre>\n<h2>Stripe API and Database Configuration (config.php)<\/h2>\n<p>Create a <code>config.php<\/code> file to store your database and stripe API configuration settings. Update the following configuration settings in the file: <\/p>\n<ul>\n<li>Define the product details (<code>$itemName<\/code>, <code>$itemPrice<\/code>, and <code>$currency<\/code>).<\/li>\n<li>Define your Stripe API <code>Publishable key<\/code> and <code>Secret key<\/code>.<\/li>\n<li>Define your database connection settings (<code>DB_HOST<\/code>, <code>DB_USERNAME<\/code>, <code>DB_PASSWORD<\/code>, and <code>DB_NAME<\/code>).<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Product&nbsp;Details <br \/>\/\/&nbsp;Minimum&nbsp;amount&nbsp;is&nbsp;$0.50&nbsp;US <br \/><\/span><span style=\"color: #0000BB\">$itemName&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"Demo&nbsp;Product\"<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$itemPrice&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">25<\/span><span style=\"color: #007700\">;&nbsp; <br \/><\/span><span style=\"color: #0000BB\">$currency&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"USD\"<\/span><span style=\"color: #007700\">;&nbsp; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/*&nbsp;Stripe&nbsp;API&nbsp;configuration <br \/>&nbsp;*&nbsp;Remember&nbsp;to&nbsp;switch&nbsp;to&nbsp;your&nbsp;live&nbsp;publishable&nbsp;and&nbsp;secret&nbsp;key&nbsp;in&nbsp;production! <br \/>&nbsp;*&nbsp;See&nbsp;your&nbsp;keys&nbsp;here:&nbsp;https:\/\/dashboard.stripe.com\/account\/apikeys <br \/>&nbsp;*\/ <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'STRIPE_PUBLISHABLE_KEY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'_Stripe_API_Publishable_key_HERE_'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'STRIPE_SECRET_KEY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'_Stripe_API_Secret_key_HERE_'<\/span><span style=\"color: #007700\">); <br \/>&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Database&nbsp;configuration&nbsp; <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_HOST'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'localhost'<\/span><span style=\"color: #007700\">);&nbsp; <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_USERNAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'root'<\/span><span style=\"color: #007700\">);&nbsp; <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_PASSWORD'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'root_pass'<\/span><span style=\"color: #007700\">);&nbsp; <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'DB_NAME'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'codexworld_db'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p><u><strong>Note:<\/strong> Make sure to replace the placeholder values of <code>STRIPE_PUBLISHABLE_KEY<\/code> and <code>STRIPE_SECRET_KEY<\/code> with your actual Stripe API keys, which you obtained from your Stripe account earlier (Developers > API keys).<\/u><\/p>\n<h2>Create Database Connection (dbConnect.php)<\/h2>\n<p>Create a <code>dbConnect.php<\/code> file to establish a connection to the MySQL database using MySQLi.<\/p>\n<pre><span style=\"color: #0000BB\">&lt;?php&nbsp; <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;database&nbsp;connection <br \/><\/span><span style=\"color: #0000BB\">$mysqli&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">mysqli<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">DB_HOST<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_USERNAME<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_PASSWORD<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">DB_NAME<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;connection <br \/><\/span><span style=\"color: #007700\">if&nbsp;(<\/span><span style=\"color: #0000BB\">$mysqli<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_errno<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #DD0000\">\"Failed&nbsp;to&nbsp;connect&nbsp;to&nbsp;MySQL:&nbsp;\"&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$mysqli<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">connect_error<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;exit(); <br \/>} <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<h2>Stripe Checkout Form (index.php)<\/h2>\n<p>Create an <code>index.php<\/code> file to display the product details and payment form to the user. The following code includes the necessary components for the Stripe checkout process.<\/p>\n<p><b>Configuration File:<\/b> Include the <code>config.php<\/code> file to access the configuration settings.<\/p>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;configuration&nbsp;file&nbsp; <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'config.php'<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<p><b>Stripe JS Library:<\/b> Include the <b>Stripe.js<\/b> v3 library that helps securely sending the sensitive information to Stripe directly from the browser.<\/p>\n<pre style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-comment\" style=\"color: rgb(108, 107, 90);\">&lt;!-- Stripe JS library --&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"https:\/\/js.stripe.com\/clover\/stripe.js\"<\/span>&gt;<\/span><span class=\"undefined\"><\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span>&gt;<\/span><\/pre>\n<p><b>Checkout JS Script:<\/b> Include the <code>checkout.js<\/code> script to handle the checkout process with Stripe API using JavaScript.<\/p>\n<ul>\n<li>Pass the <code>STRIPE_PUBLISHABLE_KEY<\/code> from the <code>config.php<\/code> file to the JavaScript file using a custom attribute.<\/li>\n<\/ul>\n<pre style=\"color: rgb(95, 94, 78);\"><span class=\"hljs-comment\" style=\"color: rgb(108, 107, 90);\">&lt;!-- Custom script to process checkout with Stripe API --&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"js\/checkout.js\"<\/span> <span class=\"hljs-attr\">STRIPE_PUBLISHABLE_KEY<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">STRIPE_PUBLISHABLE_KEY<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\"<\/span> <span class=\"hljs-attr\">defer<\/span>&gt;<\/span><span class=\"undefined\"><\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">script<\/span>&gt;<\/span><\/pre>\n<p><b>HTML Payment Form:<\/b> Create an HTML structure to display the product details and credit card payment form.<\/p>\n<ul>\n<li>Display product information (name and price).<\/li>\n<li>Define an HTML form (<code>paymentFrm<\/code>) to collect customer name, email and attach card input elements.<\/li>\n<li>Define a <code>paymentElement<\/code> div to mount the Stripe card input elements (card number, expiration date, CVS, etc.) using Stripe JS library.<\/li>\n<li>Define a <code>paymentResponse<\/code> div to display the payment status message.<\/li>\n<li>Add a submit button to initiate the payment process.<\/li>\n<\/ul>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"panel\"<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"panel-heading\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">h3<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"panel-title\"<\/span>&gt;<\/span>Charge <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #DD0000\">'$'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$itemPrice<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span> with Stripe<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">h3<\/span>&gt;<\/span>\r\n        \r\n        <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Product Info --&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">b<\/span>&gt;<\/span>Item Name:<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$itemName<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">p<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">b<\/span>&gt;<\/span>Price:<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #DD0000\">'$'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$itemPrice<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$currency<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"panel-body\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Display status message --&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"paymentResponse\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"hidden\"<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n        \r\n        <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Display a payment form --&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">form<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"paymentFrm\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"hidden\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"form-group\"<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">label<\/span>&gt;<\/span>NAME<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">label<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"text\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"field\"<\/span> <span class=\"hljs-attr\">placeholder<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"Enter name\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"\"<\/span> <span class=\"hljs-attr\">autofocus<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"form-group\"<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">label<\/span>&gt;<\/span>EMAIL<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">label<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"email\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"email\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"field\"<\/span> <span class=\"hljs-attr\">placeholder<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"Enter email\"<\/span> <span class=\"hljs-attr\">required<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n            \r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"paymentElement\"<\/span>&gt;<\/span>\r\n                <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!--Stripe.js injects the Payment Element--&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n            \r\n            <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Form submit button --&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">button<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"submitBtn\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"btn btn-success\"<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"spinner hidden\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"spinner\"<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n                <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">span<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"buttonText\"<\/span>&gt;<\/span>Pay Now<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">span<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">button<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">form<\/span>&gt;<\/span>\r\n        \r\n        <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Display processing notification --&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"frmProcess\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"hidden\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">span<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"ring\"<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">span<\/span>&gt;<\/span> Processing...\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n        \r\n        <span class=\"hljs-comment\" style=\"color: rgb(125, 122, 104);\">&lt;!-- Display re-initiate button --&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"payReinit\"<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"hidden\"<\/span>&gt;<\/span>\r\n            <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">button<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"btn btn-primary\"<\/span> <span class=\"hljs-attr\">onClick<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"window.location.href=window.location.href.split('?')[0]\"<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">i<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"rload\"<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">i<\/span>&gt;<\/span>Re-initiate Payment<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">button<\/span>&gt;<\/span>\r\n        <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\" style=\"color: rgb(215, 55, 55);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(215, 55, 55);\">div<\/span>&gt;<\/span><\/pre>\n<h2>Checkout Handler Script (checkout.js)<\/h2>\n<p>The <code>checkout.js<\/code> file contains the JavaScript code to handle the Stripe checkout process.<\/p>\n<ul>\n<li>Get the <code>STRIPE_PUBLISHABLE_KEY<\/code> from the custom attribute defined in the script tag of <code>index.php<\/code>.<\/li>\n<li>Create an instance of the Stripe object using the publishable API key.<\/li>\n<li>Define card elements and select the payment form element.<\/li>\n<li>Get the <code>payment_intent_client_secret<\/code> parameter from the URL.<\/li>\n<li>Check whether the <code>payment_intent_client_secret<\/code> is already present in the URL. If not, initialize the payment form by creating an instance of the Elements UI library and attaching the client secret.<\/li>\n<li><code>initialize()<\/code> function is used to,\n<ul>\n<li>Fetch a payment intent from server-side script (<code>payment_init.php<\/code>) and capture the client secret.<\/li>\n<li>Create an instance of the Elements UI library and attach the client secret.<\/li>\n<li>Mount payment elements to the HTML element (<code>#paymentElement<\/code>) defined in the payment form.<\/li>\n<\/ul>\n<\/li>\n<li><code>handleSubmit()<\/code> function is used to,\n<ul>\n<li>Post customer details to the server-side script (<code>payment_init.php<\/code>).<\/li>\n<li>Confirm a PaymentIntent using <code>stripe.confirmPayment<\/code> of Stripe Payment Intents JS API.<\/li>\n<\/ul>\n<\/li>\n<li><code>checkStatus()<\/code> function is used to,\n<ul>\n<li>Fetch the PaymentIntent status after payment submission using <code>stripe.retrievePaymentIntent<\/code> method of Stripe Payment Intents JS API.<\/li>\n<li>Post the transaction info to the server-side script (<code>payment_init.php<\/code>) and redirect to the payment status page (<code>payment-status.php<\/code>).<\/li>\n<\/ul>\n<\/li>\n<li><code>showMessage()<\/code> function helps to display status messages.<\/li>\n<li><code>setLoading()<\/code> function disable submit button and show a spinner on payment submission.<\/li>\n<li><code>setProcessing()<\/code> function disable the payment form and show the notification about payment processing.<\/li>\n<li><code>setReinit()<\/code> function help to disable the payment form and display the payment re-initiate button..<\/li>\n<\/ul>\n<pre style=\"color: rgb(68, 68, 68);\"><span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Retrieve the Stripe publishable key from the script tag attribute<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> STRIPE_PUBLISHABLE_KEY = <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.currentScript.getAttribute(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'STRIPE_PUBLISHABLE_KEY'<\/span>);\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Create an instance of the Stripe object using the publishable key<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> stripe = Stripe(STRIPE_PUBLISHABLE_KEY);\r\n\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> elements; <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Define card elements<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> paymentFrm = <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#paymentFrm\"<\/span>); <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Select payment form element<\/span>\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Get payment_intent_client_secret param from URL<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> clientSecretParam = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">new<\/span> URLSearchParams(<span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">window<\/span>.location.search).get(\r\n    <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment_intent_client_secret\"<\/span>\r\n);\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Check whether the payment_intent_client_secret is already exist in the URL<\/span>\r\nsetProcessing(<span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">true<\/span>);\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span>(!clientSecretParam){\r\n    setProcessing(<span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">false<\/span>);\r\n    \r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Create an instance of the Elements UI library and attach the client secret<\/span>\r\n    initialize();\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Check the PaymentIntent creation status<\/span>\r\ncheckStatus();\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Attach an event handler to payment form<\/span>\r\npaymentFrm.addEventListener(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"submit\"<\/span>, handleSubmit);\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Fetch a payment intent and capture the client secret<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> payment_intent_id;\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">async<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">initialize<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> { id, clientSecret } = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">await<\/span> fetch(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment_init.php\"<\/span>, {\r\n        method: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"POST\"<\/span>,\r\n        headers: { <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Content-Type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"application\/json\"<\/span> },\r\n        body: <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">JSON<\/span>.stringify({ request_type:<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'create_payment_intent'<\/span> }),\r\n    }).then((r) =&gt; r.json());\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> appearance = {\r\n        theme: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'stripe'<\/span>,\r\n        rules: {\r\n            <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'.Label'<\/span>: {\r\n                fontWeight: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'bold'<\/span>,\r\n                textTransform: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'uppercase'<\/span>,\r\n            }\r\n        }\r\n    };\r\n    \r\n    elements = stripe.elements({ clientSecret, appearance });\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> paymentElement = elements.create(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment\"<\/span>);\r\n    paymentElement.mount(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#paymentElement\"<\/span>);\r\n    \r\n    payment_intent_id = id;\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Card form submit handler<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">async<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">handleSubmit<\/span>(<span class=\"hljs-params\">e<\/span>) <\/span>{\r\n    e.preventDefault();\r\n    setLoading(<span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">true<\/span>);\r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Get customer details<\/span>\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> customer_name = <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.getElementById(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"name\"<\/span>).value;\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> customer_email = <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.getElementById(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"email\"<\/span>).value;\r\n\r\n     <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> createCustomerResp = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">await<\/span> fetch(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment_init.php\"<\/span>, {\r\n        method: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"POST\"<\/span>,\r\n        headers: { <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Content-Type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"application\/json\"<\/span> },\r\n        body: <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">JSON<\/span>.stringify({ request_type:<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'create_customer'<\/span>, payment_intent_id: payment_intent_id, name: customer_name, email: customer_email }),\r\n    }).then((r) =&gt; r.json());\r\n\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ If server returns validation errors, display them and do not proceed<\/span>\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (createCustomerResp) {\r\n        <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (createCustomerResp.error) {\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">let<\/span> messages = [];\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (createCustomerResp.error) {\r\n                messages.push(createCustomerResp.error);\r\n            }\r\n\r\n            <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Show combined message(s)<\/span>\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (messages.length) {\r\n                showMessage(messages.join(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">' '<\/span>));\r\n            } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n                showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'Validation failed.'<\/span>);\r\n            }\r\n\r\n            setLoading(<span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">false<\/span>);\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">return<\/span>;\r\n        }\r\n    }\r\n\r\n     <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> { id, customer_id } = createCustomerResp;\r\n\r\n     <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> { error } = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">await<\/span> stripe.confirmPayment({\r\n        elements,\r\n        confirmParams: {\r\n            <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Make sure to change this to your payment completion page<\/span>\r\n            return_url: <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">window<\/span>.location.href+<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'?customer_id='<\/span>+customer_id,\r\n        },\r\n    });\r\n    \r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ This point will only be reached if there is an immediate error when<\/span>\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ confirming the payment. Otherwise, your customer will be redirected to<\/span>\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ your `return_url`. For some payment methods like iDEAL, your customer will<\/span>\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ be redirected to an intermediate site first to authorize the payment, then<\/span>\r\n    <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ redirected to the `return_url`.<\/span>\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (error.type === <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"card_error\"<\/span> || error.type === <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"validation_error\"<\/span>) {\r\n        showMessage(error.message);\r\n    } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n        showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"An unexpected error occured.\"<\/span>);\r\n    }\r\n    \r\n    setLoading(<span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">false<\/span>);\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Fetch the PaymentIntent status after payment submission<\/span>\r\n<span class=\"hljs-keyword\" style=\"font-weight: 700;\">async<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">checkStatus<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> clientSecret = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">new<\/span> URLSearchParams(<span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">window<\/span>.location.search).get(\r\n        <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment_intent_client_secret\"<\/span>\r\n    );\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> customerID = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">new<\/span> URLSearchParams(<span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">window<\/span>.location.search).get(\r\n        <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"customer_id\"<\/span>\r\n    );\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (!clientSecret) {\r\n        <span class=\"hljs-keyword\" style=\"font-weight: 700;\">return<\/span>;\r\n    }\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> { paymentIntent } = <span class=\"hljs-keyword\" style=\"font-weight: 700;\">await<\/span> stripe.retrievePaymentIntent(clientSecret);\r\n    \r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (paymentIntent) {\r\n        <span class=\"hljs-keyword\" style=\"font-weight: 700;\">switch<\/span> (paymentIntent.status) { \r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">case<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"succeeded\"<\/span>:\r\n                <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/showMessage(\"Payment succeeded!\");<\/span>\r\n                \r\n                <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Post the transaction info to the server-side script and redirect to the payment status page<\/span>\r\n                fetch(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"payment_init.php\"<\/span>, {\r\n                    method: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"POST\"<\/span>,\r\n                    headers: { <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Content-Type\"<\/span>: <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"application\/json\"<\/span> },\r\n                    body: <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">JSON<\/span>.stringify({ request_type:<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'payment_insert'<\/span>, payment_intent: paymentIntent, customer_id: customerID }),\r\n                })\r\n                .then(response =&gt; response.json())\r\n                .then(data =&gt; {\r\n                    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (data.payment_txn_id) {\r\n                        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">window<\/span>.location.href = <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">'payment-status.php?pid='<\/span>+data.payment_txn_id;\r\n                    } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n                        showMessage(data.error);\r\n                        setReinit();\r\n                    }\r\n                })\r\n                .catch(<span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">console<\/span>.error);\r\n                \r\n                <span class=\"hljs-keyword\" style=\"font-weight: 700;\">break<\/span>;\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">case<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"processing\"<\/span>:\r\n                showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Your payment is processing.\"<\/span>);\r\n                setReinit();\r\n                <span class=\"hljs-keyword\" style=\"font-weight: 700;\">break<\/span>;\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">case<\/span> <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"requires_payment_method\"<\/span>:\r\n                showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Your payment was not successful, please try again.\"<\/span>);\r\n                setReinit();\r\n                <span class=\"hljs-keyword\" style=\"font-weight: 700;\">break<\/span>;\r\n            <span class=\"hljs-keyword\" style=\"font-weight: 700;\">default<\/span>:\r\n                showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Something went wrong, please try again.\"<\/span>);\r\n                setReinit();\r\n                <span class=\"hljs-keyword\" style=\"font-weight: 700;\">break<\/span>;\r\n        }\r\n    } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n        showMessage(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"Something went wrong, please try again.\"<\/span>);\r\n        setReinit();\r\n    }\r\n}\r\n\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Display message<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">showMessage<\/span>(<span class=\"hljs-params\">messageText<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">const<\/span> messageContainer = <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#paymentResponse\"<\/span>);\r\n    \r\n    messageContainer.classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    messageContainer.textContent = messageText;\r\n    \r\n    setTimeout(<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> (<span class=\"hljs-params\"><\/span>) <\/span>{\r\n        messageContainer.classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n        messageContainer.textContent = <span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"\"<\/span>;\r\n    }, <span class=\"hljs-number\" style=\"color: rgb(136, 0, 0);\">5000<\/span>);\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Show a spinner on payment submission<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">setLoading<\/span>(<span class=\"hljs-params\">isLoading<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (isLoading) {\r\n        <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Disable the button and show a spinner<\/span>\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#submitBtn\"<\/span>).disabled = <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">true<\/span>;\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#spinner\"<\/span>).classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#buttonText\"<\/span>).classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n        <span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Enable the button and hide spinner<\/span>\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#submitBtn\"<\/span>).disabled = <span class=\"hljs-literal\" style=\"color: rgb(120, 169, 96);\">false<\/span>;\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#spinner\"<\/span>).classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#buttonText\"<\/span>).classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    }\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Show a spinner on payment form processing<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">setProcessing<\/span>(<span class=\"hljs-params\">isProcessing<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"font-weight: 700;\">if<\/span> (isProcessing) {\r\n        paymentFrm.classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#frmProcess\"<\/span>).classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    } <span class=\"hljs-keyword\" style=\"font-weight: 700;\">else<\/span> {\r\n        paymentFrm.classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n        <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#frmProcess\"<\/span>).classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    }\r\n}\r\n\r\n<span class=\"hljs-comment\" style=\"color: rgb(136, 136, 136);\">\/\/ Show payment re-initiate button<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"font-weight: 700;\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(136, 0, 0); font-weight: 700;\">setReinit<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\r\n    <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#frmProcess\"<\/span>).classList.add(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n    <span class=\"hljs-built_in\" style=\"color: rgb(57, 115, 0);\">document<\/span>.querySelector(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"#payReinit\"<\/span>).classList.remove(<span class=\"hljs-string\" style=\"color: rgb(136, 0, 0);\">\"hidden\"<\/span>);\r\n}<\/pre>\n<h2>Process Payment and Charge Card (payment_init.php)<\/h2>\n<p>The following is the server-side code to process payment and charge credit card using Stripe API with PHP. The script handles three types of requests: creating a PaymentIntent, creating a Customer, and inserting payment transaction data into the database.<\/p>\n<ul>\n<li>Include the configuration file and database connection file.<\/li>\n<li>Include the Stripe PHP library and set the API key.<\/li>\n<li>Set the response content type to JSON.<\/li>\n<li>Retrieve JSON data from the POST body.<\/li>\n<li>Based on the request type, perform the corresponding action:\n<ul>\n<li><strong>create_payment_intent<\/strong>: Define the item price, convert it to cents, and create a PaymentIntent with the specified amount and currency. Return the PaymentIntent ID and client secret.<\/li>\n<li><strong>create_customer<\/strong>: Validate customer details, create a Customer in Stripe, and associate it with the PaymentIntent. Return the PaymentIntent ID and Customer ID.<\/li>\n<li><strong>payment_insert<\/strong>: Insert payment transaction data into the database and return the payment transaction ID.<\/li>\n<\/ul>\n<\/li>\n<li>Handle errors and return appropriate error messages in JSON format.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;the&nbsp;configuration&nbsp;file <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'config.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;the&nbsp;database&nbsp;connection&nbsp;file <br \/><\/span><span style=\"color: #007700\">include_once&nbsp;<\/span><span style=\"color: #DD0000\">'dbConnect.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;the&nbsp;Stripe&nbsp;PHP&nbsp;library <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'stripe-php\/init.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;an&nbsp;instance&nbsp;of&nbsp;the&nbsp;Stripe&nbsp;client <br \/><\/span><span style=\"color: #0000BB\">$stripe&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">\\Stripe\\StripeClient<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">STRIPE_SECRET_KEY<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Set&nbsp;response&nbsp;content&nbsp;type&nbsp;to&nbsp;JSON <br \/><\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'Content-Type:&nbsp;application\/json'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Retrieve&nbsp;JSON&nbsp;from&nbsp;POST&nbsp;body <br \/><\/span><span style=\"color: #0000BB\">$jsonStr&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">file_get_contents<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'php:\/\/input'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$jsonObj&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">json_decode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$jsonStr<\/span><span style=\"color: #007700\">); <br \/> <br \/>if(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">request_type&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">'create_payment_intent'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Define&nbsp;item&nbsp;price&nbsp;and&nbsp;convert&nbsp;to&nbsp;cents <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$itemPriceCents&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">round<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$itemPrice<\/span><span style=\"color: #007700\">*<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Create&nbsp;PaymentIntent&nbsp;with&nbsp;amount&nbsp;and&nbsp;currency <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">paymentIntents<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">create<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'amount'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$itemPriceCents<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'currency'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$currency<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;In&nbsp;the&nbsp;latest&nbsp;version&nbsp;of&nbsp;the&nbsp;API,&nbsp;specifying&nbsp;the&nbsp;`automatic_payment_methods`&nbsp;parameter&nbsp;is&nbsp;optional&nbsp;because&nbsp;Stripe&nbsp;enables&nbsp;its&nbsp;functionality&nbsp;by&nbsp;default. <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/*'automatic_payment_methods'&nbsp;=&gt;&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'enabled'&nbsp;=&gt;&nbsp;true, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],*\/ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'payment_method_types'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'card' <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">] <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'clientSecret'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">client_secret <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$output<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(<\/span><span style=\"color: #0000BB\">Error&nbsp;$e<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">http_response_code<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">500<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">([<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$e<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getMessage<\/span><span style=\"color: #007700\">()]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}elseif(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">request_type&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">'create_customer'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">payment_intent_id<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">payment_intent_id<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;sanitize&nbsp;user&nbsp;input <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">mb_substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">strip_tags<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">),&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">):<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$email&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">mb_substr<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">255<\/span><span style=\"color: #007700\">):<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Input&nbsp;validation <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(empty(<\/span><span style=\"color: #0000BB\">$payment_intent_id<\/span><span style=\"color: #007700\">)&nbsp;||&nbsp;empty(<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">)&nbsp;||&nbsp;empty(<\/span><span style=\"color: #0000BB\">$email<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">http_response_code<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">500<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">([<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Please&nbsp;fill&nbsp;all&nbsp;the&nbsp;required&nbsp;fields!'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;customer&nbsp;already&nbsp;exists&nbsp;with&nbsp;the&nbsp;given&nbsp;email <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">try&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;PaymentIntent&nbsp;for&nbsp;customer <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$payment_intent_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">paymentIntents<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">retrieve<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$payment_intent_id<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$paymentIntent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customer<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customer<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Search&nbsp;for&nbsp;existing&nbsp;customer&nbsp;by&nbsp;email <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(empty(<\/span><span style=\"color: #0000BB\">$customer_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customers&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">search<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'query'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'email:\\''&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #0000BB\">$email&nbsp;<\/span><span style=\"color: #007700\">.&nbsp;<\/span><span style=\"color: #DD0000\">'\\''<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(<\/span><span style=\"color: #0000BB\">$customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">data<\/span><span style=\"color: #007700\">))&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">data<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">; <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Update&nbsp;customer&nbsp;name&nbsp;if&nbsp;changed <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">update<\/span><span style=\"color: #007700\">( <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<\/span><span style=\"color: #DD0000\">'name'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">] <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(<\/span><span style=\"color: #0000BB\">\\Stripe\\Exception\\ApiErrorException&nbsp;$e<\/span><span style=\"color: #007700\">)&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$e<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getMessage<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Add&nbsp;customer&nbsp;to&nbsp;stripe&nbsp;if&nbsp;not&nbsp;created&nbsp;already <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(empty(<\/span><span style=\"color: #0000BB\">$customer_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">create<\/span><span style=\"color: #007700\">([ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'name'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$name<\/span><span style=\"color: #007700\">,&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'email'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$email <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">]);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(<\/span><span style=\"color: #0000BB\">Error&nbsp;$e<\/span><span style=\"color: #007700\">)&nbsp;{&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$e<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getMessage<\/span><span style=\"color: #007700\">();&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(empty(<\/span><span style=\"color: #0000BB\">$api_error<\/span><span style=\"color: #007700\">)&nbsp;&amp;&amp;&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$customer_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try&nbsp;{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Update&nbsp;PaymentIntent&nbsp;with&nbsp;the&nbsp;customer&nbsp;ID <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">paymentIntents<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">update<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$payment_intent_id<\/span><span style=\"color: #007700\">,&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'customer'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;catch&nbsp;(<\/span><span style=\"color: #0000BB\">Error&nbsp;$e<\/span><span style=\"color: #007700\">)&nbsp;{&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$e<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getMessage<\/span><span style=\"color: #007700\">();&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(empty(<\/span><span style=\"color: #0000BB\">$api_error<\/span><span style=\"color: #007700\">)&nbsp;&amp;&amp;&nbsp;<\/span><span style=\"color: #0000BB\">$paymentIntent<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent_id<\/span><span style=\"color: #007700\">, <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'customer_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$output<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">http_response_code<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">500<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">([<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">http_response_code<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">500<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">([<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}elseif(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">request_type&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">'payment_insert'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">payment_intent<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">payment_intent<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customer_id<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$jsonObj<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customer_id<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Retrieve&nbsp;customer&nbsp;info <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">try&nbsp;{&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stripe<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">customers<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">retrieve<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$customer_id<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}catch(<\/span><span style=\"color: #0000BB\">Error&nbsp;$e<\/span><span style=\"color: #007700\">)&nbsp;{&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$api_error&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$e<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">getMessage<\/span><span style=\"color: #007700\">();&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;whether&nbsp;the&nbsp;charge&nbsp;was&nbsp;successful <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">)&nbsp;&amp;&amp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">status&nbsp;<\/span><span style=\"color: #007700\">==&nbsp;<\/span><span style=\"color: #DD0000\">'succeeded'<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Transaction&nbsp;details&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$transaction_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">amount<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$paid_amount<\/span><span style=\"color: #007700\">\/<\/span><span style=\"color: #0000BB\">100<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$paid_currency&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">currency<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$payment_intent<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">status<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$customer_email&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_name&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">name<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$customer_email&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;!empty(<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">)?<\/span><span style=\"color: #0000BB\">$customer<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">email<\/span><span style=\"color: #007700\">:<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;if&nbsp;any&nbsp;transaction&nbsp;data&nbsp;exists&nbsp;already&nbsp;with&nbsp;the&nbsp;same&nbsp;TXN&nbsp;ID <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sqlQ&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;id&nbsp;FROM&nbsp;transactions&nbsp;WHERE&nbsp;txn_id&nbsp;=&nbsp;?\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$mysqli<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">prepare<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sqlQ<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">bind_param<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"s\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$transaction_id<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">execute<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">bind_result<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$row_id<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(<\/span><span style=\"color: #0000BB\">$row_id<\/span><span style=\"color: #007700\">)){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$row_id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Insert&nbsp;transaction&nbsp;data&nbsp;into&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sqlQ&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"INSERT&nbsp;INTO&nbsp;transactions&nbsp;(customer_name,customer_email,item_name,item_price,item_price_currency,paid_amount,paid_amount_currency,txn_id,payment_status,created,modified)&nbsp;VALUES&nbsp;(?,?,?,?,?,?,?,?,?,NOW(),NOW())\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$mysqli<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">prepare<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sqlQ<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">bind_param<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"sssdsdsss\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$customer_name<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$customer_email<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$itemName<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$itemPrice<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$currency<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$paid_currency<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$transaction_id<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$payment_status<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$insert&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">execute<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$insert<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">insert_id<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$output&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;[ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'payment_txn_id'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">base64_encode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$transaction_id<\/span><span style=\"color: #007700\">) <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$output<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">http_response_code<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">500<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<\/span><span style=\"color: #0000BB\">json_encode<\/span><span style=\"color: #007700\">([<\/span><span style=\"color: #DD0000\">'error'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'Transaction&nbsp;has&nbsp;been&nbsp;failed!'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>} <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/pre>\n<h2>Payment Status (payment-status.php)<\/h2>\n<p>Based on the payment response from Stripe (paymentIntent.status), the user will be redirected to this page. This page fetches the transaction details from the database and displays the payment status message to the user.<\/p>\n<ul>\n<li>Include the configuration and database connection file.<\/li>\n<li>Check whether the payment ID is not empty.<\/li>\n<li>Fetch the transaction data from the database using the payment ID.<\/li>\n<li>Display the payment status message based on the payment status.<\/li>\n<\/ul>\n<pre><span style=\"color: #0000BB\">&lt;?php <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;the&nbsp;configuration&nbsp;file&nbsp; <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'config.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;the&nbsp;database&nbsp;connection&nbsp;file&nbsp; <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'dbConnect.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #0000BB\">$payment_ref_id&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">''<\/span><span style=\"color: #007700\">; <br \/><\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'error'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Check&nbsp;whether&nbsp;the&nbsp;payment&nbsp;ID&nbsp;is&nbsp;not&nbsp;empty <br \/><\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'pid'<\/span><span style=\"color: #007700\">])){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$payment_txn_id&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">base64_decode<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_GET<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'pid'<\/span><span style=\"color: #007700\">]); <br \/>&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Fetch&nbsp;transaction&nbsp;data&nbsp;from&nbsp;the&nbsp;database <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$sqlQ&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"SELECT&nbsp;id,txn_id,paid_amount,paid_amount_currency,payment_status,customer_name,customer_email&nbsp;FROM&nbsp;transactions&nbsp;WHERE&nbsp;txn_id&nbsp;=&nbsp;?\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$db<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">prepare<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$sqlQ<\/span><span style=\"color: #007700\">);&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">bind_param<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"s\"<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$payment_txn_id<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">execute<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">store_result<\/span><span style=\"color: #007700\">(); <br \/> <br \/>&nbsp;&nbsp;&nbsp;&nbsp;if(<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">num_rows&nbsp;<\/span><span style=\"color: #007700\">&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">){ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #FF8000\">\/\/&nbsp;Get&nbsp;transaction&nbsp;details <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">bind_result<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$payment_ref_id<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$txn_id<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount_currency<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$payment_status<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$customer_name<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$customer_email<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$stmt<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">fetch<\/span><span style=\"color: #007700\">(); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$status&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'success'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">'Your&nbsp;Payment&nbsp;has&nbsp;been&nbsp;Successful!'<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"Transaction&nbsp;has&nbsp;been&nbsp;failed!\"<\/span><span style=\"color: #007700\">; <br \/>&nbsp;&nbsp;&nbsp;&nbsp;} <br \/>}else{ <br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">header<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"Location:&nbsp;index.php\"<\/span><span style=\"color: #007700\">); <br \/>&nbsp;&nbsp;&nbsp;&nbsp;exit; <br \/>} <br \/><\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n\r\n<span style=\"color: rgb(95, 94, 78);\"><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">if(!empty(<\/span><span style=\"color: #0000BB\">$payment_ref_id<\/span><span style=\"color: #007700\">)){&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h1<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$status<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\"<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h1<\/span>&gt;<\/span>\r\n    \r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>Payment Information<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Reference Number:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$payment_ref_id<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Transaction ID:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$txn_id<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Paid Amount:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$paid_amount<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$paid_amount_currency<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Payment Status:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$payment_status<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    \r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>Customer Information<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Name:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$customer_name<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Email:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$customer_email<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    \r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>Product Information<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h4<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Name:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$itemName<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span>Price:<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">b<\/span>&gt;<\/span> <span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$itemPrice<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #DD0000\">'&nbsp;'<\/span><span style=\"color: #007700\">.<\/span><span style=\"color: #0000BB\">$currency<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">}else{&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h1<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"error\"<\/span>&gt;<\/span>Your Payment been failed!<span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">h1<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\" style=\"color: rgb(125, 151, 38);\">\"error\"<\/span>&gt;<\/span><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">echo&nbsp;<\/span><span style=\"color: #0000BB\">$statusMsg<\/span><span style=\"color: #007700\">;&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><span class=\"hljs-tag\" style=\"color: rgb(186, 98, 54);\">&lt;\/<span class=\"hljs-name\" style=\"color: rgb(186, 98, 54);\">p<\/span>&gt;<\/span>\r\n<span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">}&nbsp;<\/span><span style=\"color: #0000BB\">?&gt;<\/span><\/span>\r\n<\/pre>\n<h2>Test Card Details<\/h2>\n<p>To test the payment process, you need test card details. Use any of the following test card numbers, a valid future expiration date, and any random CVC number, to test <b>Stripe payment gateway integration in PHP<\/b>.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>4242 4242 4242 4242 &#8211; Visa<\/li>\n<li>4000 0566 5566 5556 &#8211; Visa (debit)<\/li>\n<li>5555 5555 5555 4444 &#8211; Mastercard<\/li>\n<li>5200 8282 8282 8210 &#8211; Mastercard (debit)<\/li>\n<li>3782 822463 10005 &#8211; American Express<\/li>\n<li>6011 1111 1111 1117 &#8211; Discover<\/li>\n<li>3566 0020 2036 0505 &#8211; JCB<\/li>\n<li>6200 0000 0000 0005 &#8211; UnionPay<\/li>\n<\/ul>\n<h2>3D Secure Authentication<\/h2>\n<p>The 3D Secure feature requires additional authentication for credit card transactions. Use the following test cards to simulate the payment process that involves 3D Secure authentication.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>4000 0027 6000 3184<\/li>\n<li>4000 0000 0000 3063<\/li>\n<\/ul>\n<h2>Make Stripe Payment Gateway Live<\/h2>\n<p>Once the integration is completed and the payment process is working properly, follow the below steps to make Stripe payment gateway live.<\/p>\n<ul class=\"step_list\">\n<li>Login to your <a href=\"https:\/\/dashboard.stripe.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Stripe account<\/a> and navigate to the <b>Developers &raquo; API keys<\/b> page.<\/li>\n<li>Collect the API keys (<b>Publishable key<\/b> and <b>Secret key<\/b>) from Live Data.<\/li>\n<li>In the <code>config.php<\/code> file, replace the Test API keys (Publishable key and Secret key) with the Live API keys (Publishable key and Secret key).\n<pre><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'STRIPE_PUBLISHABLE_KEY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'LIVE_API_Publishable_key'<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">define<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'STRIPE_SECRET_KEY'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'LIVE_API_Secret_key'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<\/li>\n<\/ul>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/paypal-standard-payment-gateway-integration-php\/\">PayPal Payment Gateway Integration in PHP<\/a><\/span><\/p>\n<h2>\ud83c\udf89 Conclusion<\/h2>\n<p>With this tutorial, you have learned how to integrate Stripe payment gateway in PHP web application to accept credit\/debit card payments. The Stripe payment gateway is the easiest way to accept credit card payments on the web application. Our example code uses the Stripe PHP library to create a charge and make payment with a credit\/debit card. The <b>3D Secure<\/b> authentication is integrated to make this Stripe integration script ready for SCA (Strong Customer Authentication). If you want to use Stripe hosted checkout system, integrate redirect-based <a href=\"https:\/\/www.codexworld.com\/stripe-checkout-payment-gateway-integration-php\/\">Stripe Checkout in PHP<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Stripe payment gateway provides an easy and powerful way to accept credit cards directly on the web application. Stripe makes integrating the checkout system and collecting payment on the website easy. The Stripe API <\/p>\n","protected":false},"author":1,"featured_media":5955,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[250,166,76,14,307],"class_list":["post-2942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-api","tag-library","tag-payment-gateway","tag-php","tag-stripe","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stripe Payment Gateway Integration in PHP - CodexWorld<\/title>\n<meta name=\"description\" content=\"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stripe Payment Gateway Integration in PHP - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-20T19:00:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-24T15:07:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Stripe Payment Gateway Integration in PHP\",\"datePublished\":\"2017-11-20T19:00:47+00:00\",\"dateModified\":\"2025-11-24T15:07:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/\"},\"wordCount\":1438,\"commentCount\":56,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg\",\"keywords\":[\"API\",\"Library\",\"Payment Gateway\",\"PHP\",\"Stripe\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/\",\"name\":\"Stripe Payment Gateway Integration in PHP - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg\",\"datePublished\":\"2017-11-20T19:00:47+00:00\",\"dateModified\":\"2025-11-24T15:07:19+00:00\",\"description\":\"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg\",\"width\":1920,\"height\":1080,\"caption\":\"stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/stripe-payment-gateway-integration-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stripe Payment Gateway Integration in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Stripe Payment Gateway Integration in PHP - CodexWorld","description":"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/","og_locale":"en_US","og_type":"article","og_title":"Stripe Payment Gateway Integration in PHP - CodexWorld","og_description":"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.","og_url":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2017-11-20T19:00:47+00:00","article_modified_time":"2025-11-24T15:07:19+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","type":"image\/jpeg"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Stripe Payment Gateway Integration in PHP","datePublished":"2017-11-20T19:00:47+00:00","dateModified":"2025-11-24T15:07:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/"},"wordCount":1438,"commentCount":56,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","keywords":["API","Library","Payment Gateway","PHP","Stripe"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/","url":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/","name":"Stripe Payment Gateway Integration in PHP - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","datePublished":"2017-11-20T19:00:47+00:00","dateModified":"2025-11-24T15:07:19+00:00","description":"Stripe API integration in PHP - Example code to integrate Stripe payment gateway in PHP. Stripe PHP and JavaScript library to implement credit card payment checkout on the website.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","width":1920,"height":1080,"caption":"stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/stripe-payment-gateway-integration-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Stripe Payment Gateway Integration in PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2017\/11\/stripe-payment-gateway-integration-credit-card-payments-api-php-codexworld.jpg","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-Ls","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=2942"}],"version-history":[{"count":34,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2942\/revisions"}],"predecessor-version":[{"id":5957,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/2942\/revisions\/5957"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5955"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=2942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=2942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=2942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}