Today, We want to share with you stripe payment gateway integration in php.
In this post we will show you stripe login, stripe integration, hear for stripe custom checkout example we will give you demo and example for implement.
In this post, we will learn about php – How to generate token in stripe payment gateway with an example.
stripe payment gateway integration in php
There are the Following The simple About stripe payment gateway integration in php Full Information With Example and source code.
As I will cover this Post with live Working example to develop Stripe PHP simple example, so the some major files and Directory structures for this example is following below as well as more example Like stripe login, stripe integration, stripe sage integration, stripe custom checkout example, stripe checkout custom fields, stripe checkout demo, stripe checkout wordpress.
- config.php
- DBController.php
- index.php
- style.css
Stripe Payment Gateway Integration in PHP
Stripe Simple means Online Getway payment processing for Data internet businesses
Step 1 : PHP Stripe Payment Config File
config.php
Step 2 : Payment Database Structure
— Table structure for table `tbl_stripe_payments`
CREATE TABLE `tbl_stripe_payments` ( `id` int(11) NOT NULL, `email` varchar(255) NOT NULL, `item_number` varchar(255) NOT NULL, `amount` double(10,2) NOT NULL, `currency_code` varchar(55) NOT NULL, `txn_id` varchar(255) NOT NULL, `payment_status` varchar(255) NOT NULL, `payment_response` text NOT NULL, `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for table `tbl_stripe_payments` -- ALTER TABLE `tbl_stripe_payments` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for table `tbl_stripe_payments` -- ALTER TABLE `tbl_stripe_payments` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; COMMIT;
Step 3 : Get Stripe Payment API Keys
Make a Stripe account PHP devloper Stripe account and fetch API keys

HTML Stripe Payment Form
index.php
This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.
Client-Side Stripe Payment Form Card Validation and Response & Request Handler with Stripe JavaScript Library

Step 4 : Stripe Payment DBController
DBController.php
conn = $this->connectDB(); } function connectDB() { $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database); return $conn; } function runBaseQuery($query) { $result = $this->conn->query($query); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $resultset[] = $row; } } return $resultset; } function runQuery($query, $argu_type, $lbl_argu_array) { $sql = $this->conn->prepare($query); $this->bindQueryParams($sql, $argu_type, $lbl_argu_array); $sql->execute(); $result = $sql->get_result(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $resultset[] = $row; } } if(!empty($resultset)) { return $resultset; } } function bindQueryParams($sql, $argu_type, $lbl_argu_array) { $param_value_reference[] = & $argu_type; for($i=0; $iconn->prepare($query); $this->bindQueryParams($sql, $argu_type, $lbl_argu_array); $sql->execute(); } function update($query, $argu_type, $lbl_argu_array) { $sql = $this->conn->prepare($query); $this->bindQueryParams($sql, $argu_type, $lbl_argu_array); $sql->execute(); } } ?>
Step 5 : Get Response StripePayment
response.php
Thank You!Stripe Payment is Completed Successfully.Payment Failed!Problem in Processing Stripe Payment.
Step 6 : Save and Display Stripe Payment Response
sendPayment.php
chargeAmountFromCard($_POST); require_once "DBController.php"; $dbController = new DBController(); $amount = $liveResStripe["amount"] /100; $argu_type = 'ssdssss'; $lbl_argu_array = array( $_POST['email'], $_POST['item_number'], $amount, $liveResStripe["currency"], $liveResStripe["balance_transaction"], $liveResStripe["status"], json_encode($liveResStripe) ); $query = "INSERT INTO tbl_stripe_payments (email, item_number, amount, currency_code, txn_id, payment_status, payment_response) values (?, ?, ?, ?, ?, ?, ?)"; $id = $dbController->insert($query, $argu_type, $lbl_argu_array); if ($liveResStripe['amount_refunded'] == 0 && empty($liveResStripe['failure_code']) && $liveResStripe['paid'] == 1 && $liveResStripe['captured'] == 1 && $liveResStripe['status'] == 'succeeded') { $status = "success"; } else { $status = "error"; } header("Location: response.php?status=" .$status); } ?>
Step 7 : PHP Process Charges Stripe Payment Response
StripePayment.php
apiKey = STRIPE_YOUR_SECRET_KEY; $this->stripeService = new \Stripe\Stripe(); $this->stripeService->setVerifySslCerts(false); $this->stripeService->setApiKey($this->apiKey); } public function addCustomer($detailsCustArray) { $customer = new Customer(); $customerDetails = $customer->create($detailsCustArray); return $customerDetails; } public function chargeAmountFromCard($detailsCardCust) { $detailsCustArray = array( 'email' => $detailsCardCust['email'], 'source' => $detailsCardCust['token'] ); $customerResult = $this->addCustomer($detailsCustArray); $charge = new Charge(); $detailsCardArray = array( 'customer' => $customerResult->id, 'amount' => $detailsCardCust['amount']*100 , 'currency' => $detailsCardCust['currency_code'], 'description' => $detailsCardCust['item_name'], 'metadata' => array( 'order_id' => $detailsCardCust['item_number'] ) ); $result = $charge->create($detailsCardArray); return $result->jsonSerialize(); } }
Step 8 : Custom Stripe Payment CSS
style.css
#livePaymentFrmStripe { border-top: #a2d0c8 2px solid; background: #e0f7f3; padding: 25px; width: 270px; } #livePaymentFrmStripe .infinity-row { margin-bottom: 20px; } #livePaymentFrmStripe div label { margin: 5px 0px 0px 5px; color: #49615d; width: auto; } .lblInpBox { padding: 10px; border: #a5d2ca 1px solid; border-radius: 4px; background-color: #FFF; width: 100%; margin-top: 5px; box-sizing:border-box; } .liveCustomSelect { padding: 10px; border: #a5d2ca 1px solid; border-radius: 4px; background-color: #FFF; margin-top: 5px; } select.liveCustomSelect { height: 35px; margin-right: 10px; } .error { background-color: #FF6600; padding: 8px 10px; border-radius: 4px; font-size: 0.9em; } .success { background-color: #c3c791; padding: 8px 10px; border-radius: 4px; font-size: 0.9em; } .details { font-size: .8em; color: #FF6600; letter-spacing: 2px; padding-left: 5px; } .lblBtnCard { background-color: #82a9a2; padding: 10px 40px; color: #FFF; border: #739690 1px solid; border-radius: 4px; cursor:pointer; } .lblBtnCard:focus { outline: none; } .column-right { margin-right: 6px; } .myref-row { display: inline-block; } .lbl-cvv-card { width: 60px; } #preview-error-status { margin: 20px 0px 0px; background: #ffd6d6; padding: 10px; border-radius: 4px; line-height: 25px; font-size: 0.9em; color: #907575; display:none; } .display-none { display:none; } #results-card { padding: 40px 20px; width: 270px; text-align:center; } .status-ask-data { font-size: 1.5em; margin-bottom: 20px; } #results-card.success { border-top: #b0dad3 2px solid; background: #e9fdfa; } #results-card.error { border-top: #c3b4b4 2px solid; background: #f5e3e3; } .logo-img-results { margin-bottom: 30px; }
Stripe Payment Form Output
stripe checkout demo
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Stripe Payment gateway integration in PHP with DEMO Examples.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.