Stripe Payment Gateway Integration in Codeigniter using cURL
Stripe is the popular payment Gateway. Stripe Payment Gateway clean, fast, secure payments services and a powerful way to accept credit cards directly on the web application and Developer Friendly API.
In this post, We have share how to integrate Stripe payment gateway using Codeigniter. This is a very simple example, you can just copy paste, and change according to your requirement.
Follow some basic Steps Stripe payment gateway
- Create a Form to fill credit card information.
- Stripe JavaScript library to validate card details
- Submit the form with card details and card and process charges
- Update details in database with payment status
Step-1: Create a Stripe account and get API keys
- Create a Stripe account and login to the dashboard.
- Navigate to the Developers » API keys page.
- There is two type of standard API keys named secret key and publishable key.To show the Secret key, click on Reveal test key token button.
Before started to implement the Stripe Payment Gateway Integration in Codeigniter, look files structure:
- stripe-payment-gateway-integration-in-codeigniter
- application
- config
- autoload.php
- database.php
- constants.php
- routes.php
- controllers
- StripePayment.php
- models
- Payment_model.php
- views
- stripe
- index.php
- checkout.php
- success.php
- templates
- header.php
- footer.php
- stripe
- config
- system
- index.php
- vendor
- assets
- css
- style.css
- js
- custom.css
- application
Step-2: Create MySQL Database and Table
1- product table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
CREATE TABLE `product` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` text NOT NULL, `image` varchar(255) NOT NULL, `price` float(10,2) NOT NULL, `status` int(1) NOT NULL, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; INSERT INTO `product` VALUES (1,'Product One','Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy','http://placehold.it/700x400',10.00,1), (2,'Product Two','Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy','http://placehold.it/700x400',20.00,1), (3,'Product Three','Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy','http://placehold.it/700x400',30.00,1), (4,'Product Four','Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy','http://placehold.it/700x400',40.00,1); |
2- orders table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php CREATE TABLE `orders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `transaction_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `address` text COLLATE utf8_unicode_ci, `product_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `product_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `product_price` float(10,2) NOT NULL, `total` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `currency` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `created_date` varchar(12) COLLATE utf8_unicode_ci NOT NULL, `modified_date` varchar(12) COLLATE utf8_unicode_ci NOT NULL, `status` varchar(25) COLLATE utf8_unicode_ci NOT NULL COMMENT '0=Failed, 1=Success', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ?> |
Open
application/config/autoload.php
file and add/update code like as bellow:
1 2 3 4 5 |
<?php // load library and helper $autoload['libraries'] = array('database', 'session', 'table', 'upload'); $autoload['helper'] = array('url', 'form', 'html', 'date', 'text'); ?> |
Step-3: Define constants
Update file named constants.php inside “application/config/” folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php $root = "http://" . $_SERVER['HTTP_HOST']; $currentDir = str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']); $root .= $currentDir; $constants['base_url'] = $root; define('DB_HOSTNAME', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', 'root'); define('DB_NAME', 'demo_DB'); // windows path //define('BASH_PATH', 'C:/xampp/htdocs'.$currentDir); // Ubuntu path define('BASH_PATH', '/var/www'.$currentDir); // Mac Path //define('BASH_PATH', '/Applications/XAMPP/htdocs'.$currentDir); define('HTTP_CSS_PATH', $constants['base_url'] . 'assets/css/'); define('HTTP_JS_PATH', $constants['base_url'] . 'assets/js/'); define('HTTP_IMAGE_PATH', $constants['base_url'] . 'assets/images/'); define('STRIPE_PUBLISHABLE_KEY', 'pk_test_xxxxxxxx'); define('STRIPE_SECRET_KEY', 'sk_test_xxxxxxxx'); define('CURRENCY_CODE', 'usd'); ?> |
Open
application/config/database.php
file and add constants like as bellow:
1 2 3 4 5 6 7 |
<?php // database credentials 'hostname' => DB_HOSTNAME, 'username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_NAME, ?> |
Step-4: Create a controller file
Create a controller file named StripePayment.php inside “application/controllers” folder.
- The StripePayment controller handles the calendar process.
__construct()
– Loads the required library, helper and model.index()
– load index product list.checkout()
– load checkout form and card detailscallback()
– charges process.get_curl_handle()
– handle curl processsuccess()
– success information .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
<?php /* * *** * Version: 1.0.0 * * Description of Stripe Payment Controller * * @author TechArise Team * * @email info@techarise.com * * *** */ if (!defined('BASEPATH')) exit('No direct script access allowed'); class StripePayment extends CI_Controller { public function __construct() { parent::__construct(); //load library $this->load->model('Payment_model', 'payment'); } // index method public function index() { $data = array(); $data['metaDescription'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['metaKeywords'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['title'] = "Stripe Payment Gateway Integration in Codeigniter - TechArise"; $data['breadcrumbs'] = array('Stripe Payment Gateway' => '#'); $data['productInfo'] = $this->payment->getProduct(); $this->load->view('stripe/index', $data); } // checkout page public function checkout($id) { $data = array(); $data['metaDescription'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['metaKeywords'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['title'] = "Stripe Payment Gateway Integration in Codeigniter - TechArise"; $this->payment->setProductID($id); $data['itemInfo'] = $this->payment->getProductDetails(); $this->load->view('stripe/checkout', $data); } // callback method public function callback() { $data = array(); $statusMsg =''; if(!empty($this->input->post('stripeToken'))) { $amount = $this->input->post('amount'); $product_id = $this->input->post('product_id'); $product_name = $this->input->post('product_name'); $name = $this->input->post('stripe_name'); $email = $this->input->post('stripe_email'); $address = 'Test 15 Street, New York, USA'; $params = array( 'amount' => $amount * 100, 'currency' => CURRENCY_CODE, 'description' => 'Charge for '.$email, 'source' => 'tok_visa', 'metadata' => array( 'product_id' => $product_id, ) ); $jsonData = $this->get_curl_handle($params); $resultJson = json_decode($jsonData, true); if($resultJson['amount_refunded'] == 0 && empty($resultJson['failure_code']) && $resultJson['paid'] == 1 && $resultJson['captured'] == 1){ // Order details $transactionID = $resultJson['balance_transaction']; $currency = $resultJson['currency']; $payment_status = $resultJson['status']; // Insert tansaction data into the database $this->payment->setTransactionID($transactionID); $this->payment->setProductID($product_id); $this->payment->setProductName($product_name); $this->payment->setName($name); $this->payment->setEmail($email); $this->payment->setAddress($address); $this->payment->setPrice($amount); $this->payment->setTotal($amount); $this->payment->setCurrency($currency); $this->payment->setCreatedDate(time()); $this->payment->setModifiedDate(time()); $this->payment->setStatus($payment_status); $orderID = $this->payment->createOrder(); // If the order is successful if($payment_status == 'succeeded') { $statusMsg .= '<h2>Thanks for your Order!</h2>'; $statusMsg .= '<h4>The transaction was successful. Order details are given below:</h4>'; $statusMsg .= "<p>Order Number: {$orderID}</p>"; $statusMsg .= "<p>Transaction ID: {$transactionID}</p>"; $statusMsg .= "<p>Order Total: {$amount} {$currency}</p>"; }else{ $statusMsg = "Your Payment has Failed!"; } } else { $statusMsg = "Transaction has been failed!"; } } else { $statusMsg = "Error on form submission."; } $this->session->set_flashdata('paymentMsg', $statusMsg); redirect('stripe/success'); } // success method public function success() { $data = array(); $data['metaDescription'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['metaKeywords'] = 'Stripe Payment Gateway Integration in Codeigniter'; $data['title'] = "Stripe Payment Gateway Integration in Codeigniter - TechArise"; $data['msg'] = $this->session->flashdata('paymentMsg'); $this->load->view('stripe/success', $data); } // get curl handle method private function get_curl_handle($data) { $url = 'https://api.stripe.com/v1/charges'; $key_secret = STRIPE_SECRET_KEY; //cURL Request $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERPWD, $key_secret); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_POST, 1); $params = http_build_query($data); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); $output = curl_exec ($ch); return $output; } } ?> |
Step 2: Create a model file
Create a model file named Payment_model.php” inside “application/models” folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
<?php /** * @package Stripe : CodeIgniter Stripe Gateway * * @author TechArise Team * * @email info@techarise.com * * Description of Contact Controller */ if (!defined('BASEPATH')) exit('No direct script access allowed'); class Payment_model extends CI_Model { private $_productID; private $_transactionID; private $_name; private $_email; private $_address; private $_productName; private $_price; private $_total; private $_currency; private $_createdDate; private $_modifiedDate; private $_status; public function setProductID($productID) { $this->_productID = $productID; } public function setTransactionID($transactionID) { $this->_transactionID = $transactionID; } public function setName($name) { $this->_name = $name; } public function setEmail($email) { $this->_email = $email; } public function setAddress($address) { $this->_address = $address; } public function setProductName($productName) { $this->_productName = $productName; } public function setPrice($price) { $this->_price = $price; } public function setTotal($total) { $this->_total = $total; } public function setCurrency($currency) { $this->_currency = $currency; } public function setCreatedDate($createdDate) { $this->_createdDate = $createdDate; } public function setModifiedDate($modifiedDate) { $this->_modifiedDate = $modifiedDate; } public function setStatus($status) { $this->_status = $status; } public function getProduct() { $this->db->select(array('p.product_id', 'p.name', 'p.description', 'p.price', 'p.image')); $this->db->from('product as p'); $query = $this->db->get(); return $query->result_array(); } // getProduct Details public function getProductDetails() { $this->db->select(array('p.product_id', 'p.name', 'p.description', 'p.price', 'p.image')); $this->db->from('product as p'); $this->db->where('p.product_id', $this->_productID); $query = $this->db->get(); return $query->row_array(); } // create Order public function createOrder() { $data = array( 'transaction_id' => $this->_transactionID, 'name' => $this->_name, 'email' => $this->_email, 'address' => $this->_address, 'product_id' => $this->_productID, 'product_name' => $this->_productName, 'product_price' => $this->_price, 'total' => $this->_total, 'currency' => $this->_currency, 'created_date' => $this->_createdDate, 'modified_date' => $this->_modifiedDate, 'status' => $this->_status, ); $this->db->insert('orders', $data); return $last_id = $this->db->insert_id(); } } ?> |
Open
application/config/routes.php
file and add code like as bellow:
1 2 3 4 5 6 7 |
<?php // create routes path $route['default_controller'] = 'StripePayment/index'; $route['stripe/callback'] = 'StripePayment/callback'; $route['stripe/checkout/(:any)'] = 'StripePayment/checkout/$1'; $route['stripe/success'] = 'StripePayment/success'; ?> |
Step-5: Stripe Token and Validate Card with Stripe.js:
1 |
<script type="text/javascript" src="https://js.stripe.com/v2/"></script> |
Step-6: The following JavaScript code is used to generate token with “Stripe.js” library.
- Set publishable API key that identifies.
- The
stripeResponseHandler()
method creates a single-use token and insert a token field in the payment form. - Card details are submitted to the server-side. the success/error message is shown.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<script type="text/javascript"> //set your publishable key Stripe.setPublishableKey('<?php print STRIPE_PUBLISHABLE_KEY; ?>'); //callback to handle the response from stripe function stripeResponseHandler(status, response) { if (response.error) { //enable the submit button $('#payBtn').removeAttr("disabled"); //display the errors on the form $(".payment-errors").html('<div class="alert alert-danger">'+response.error.message+'</div>'); } else { var form$ = $("#paymentFrm"); //get token id var token = response['id']; //insert the token into the form form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />"); //submit form to the server form$.get(0).submit(); } } $(document).ready(function() { //on form submit $("#paymentFrm").submit(function(event) { //disable the submit button to prevent repeated clicks $('#payBtn').attr("disabled", "disabled"); //create single-use token to charge the user Stripe.createToken({ number: $('#stripe-card-number').val(), cvc: $('#stripe-card-cvc').val(), exp_month: $('#stripe-card-expiry-month').val(), exp_year: $('#stripe-card-expiry-year').val() }, stripeResponseHandler); //submit from callback return false; }); }); </script> |
Step 7: Create a view(header)
Create a view file named header.php inside “application/views/templates” folder
This view contains the header section of the webpage. The Bootstrap library is used to provide a better UI, so, include it in the header section.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content=""> <title><?php print $title; ?></title> <link rel="icon" type="image/ico" href="<?php print HTTP_IMAGE_PATH; ?>favicon.ico"> <!-- Bootstrap core CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" /> <!-- Custom fonts for this template --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.2/css/all.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" /> <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css"> <!-- Custom styles for this template --> <link href="<?php print HTTP_CSS_PATH; ?>style.css" rel="stylesheet"> </head> <body> <!-- Navigation --> <nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top header-bg-dark" style="background: ##FFFFFF!;"> <div class="container"> <a class="navbar-brand font-weight-bold" href="https://techarise.com"><h1>Tech Arise</h1></a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarResponsive"> <ul class="navbar-nav ml-auto"> <li class="nav-item active"> <a class="nav-link" href="https://techarise.com">Home <span class="sr-only">(current)</span> </a> </li> <li class="nav-item"> <a class="nav-link" href="https://techarise.com/php-free-script-demos/">Live Demo</a> </li> </ul> </div> </div> </nav> |
Step 8: Create a view(footer)
Create a view file named footer.php inside “application/views/templates” folder
This view contains the footer section of the webpage.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<!-- Footer --> <footer class="footer bg-light footer-bg-dark"> <div class="container"> <div class="row"> <div class="col-lg-6 h-100 text-center text-lg-left my-auto"> <ul class="list-inline mb-2"> <li class="list-inline-item"> <a href="#">About</a> </li> <li class="list-inline-item">⋅</li> <li class="list-inline-item"> <a href="#">Contact</a> </li> <li class="list-inline-item">⋅</li> <li class="list-inline-item"> <a href="#">Terms of Use</a> </li> <li class="list-inline-item">⋅</li> <li class="list-inline-item"> <a href="#">Privacy Policy</a> </li> </ul> <p class="text-muted small mb-4 mb-lg-0">Copyright © 2011 - <?php print date('Y', time());?> <a href="https://techarise.com/">TECHARISE.COM</a> All rights reserved.</p> </div> <div class="col-lg-6 h-100 text-center text-lg-right my-auto"> <ul class="list-inline mb-0"> <li class="list-inline-item mr-3"> <a href="#"> <i class="fab fa-facebook fa-2x fa-fw"></i> </a> </li> <li class="list-inline-item mr-3"> <a href="#"> <i class="fab fa-twitter-square fa-2x fa-fw"></i> </a> </li> <li class="list-inline-item"> <a href="#"> <i class="fab fa-instagram fa-2x fa-fw"></i> </a> </li> </ul> </div> </div> </div> </footer> <script> var baseurl = "<?php print site_url();?>"; </script> <!-- Bootstrap core JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script> <script type="text/javascript" src="https://js.stripe.com/v2/"></script> <script type="text/javascript"> //set your publishable key Stripe.setPublishableKey('<?php print STRIPE_PUBLISHABLE_KEY; ?>'); //callback to handle the response from stripe function stripeResponseHandler(status, response) { if (response.error) { //enable the submit button $('#payBtn').removeAttr("disabled"); //display the errors on the form $(".payment-errors").html('<div class="alert alert-danger">'+response.error.message+'</div>'); } else { var form$ = $("#paymentFrm"); //get token id var token = response['id']; //insert the token into the form form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />"); //submit form to the server form$.get(0).submit(); } } $(document).ready(function() { //on form submit $("#paymentFrm").submit(function(event) { //disable the submit button to prevent repeated clicks $('#payBtn').attr("disabled", "disabled"); //create single-use token to charge the user Stripe.createToken({ number: $('#stripe-card-number').val(), cvc: $('#stripe-card-cvc').val(), exp_month: $('#stripe-card-expiry-month').val(), exp_year: $('#stripe-card-expiry-year').val() }, stripeResponseHandler); //submit from callback return false; }); }); </script> <script src="<?php print HTTP_JS_PATH; ?>custom.js"></script> </body> </html> |
Step 8: Create a view(index)
Create a view file named index.php inside “application/views/stripe” folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php $this->load->view('templates/header');?> <!-- container --> <section class="showcase"> <div class="container"> <div class="pb-2 mt-4 mb-2 border-bottom"> <h2>Stripe Payment Gateway Integration in Codeigniter</h2> </div> <span id="success-msg" class="payment-errors"></span> <div class="row"> <?php foreach($productInfo as $key=>$element) { ?> <div class="col-lg-3 col-md-3 mb-3"> <div class="card h-100"> <a href="#"><img src="<?php print $element['image'];?>" alt="product 10" title="product 10" class="card-img-top"></a> <div class="card-body"> <h4 class="card-title"> <a href="#"><?php print $element['name'];?></a> </h4> <h5>₹<?php print $element['price'];?></h5> <p class="card-text"><?php print $element['description'];?></p> </div> <div class="card-footer text-right"> <a href="<?php site_url()?>stripe/checkout/<?php print $element['product_id'];?>" class="add-to-cart btn-success btn btn-sm" data-productid="<?php print $element['product_id'];?>" title="Add to Cart"><i class="fa fa-shopping-cart fa-fw"></i> Buy Now</a> </div> </div> </div> <?php } ?> </div> </div> </section> <?php $this->load->view('templates/footer');?> |
Step 9: Create a view(checkout)
Create a view file named checkout.php inside “application/views/stripe” folder.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php $this->load->view('templates/header');?> <!-- container --> <section class="showcase"> <div class="container"> <div class="pb-2 mt-4 mb-2 border-bottom"> <h2>Stripe Payment Gateway Integration in Codeigniter</h2> </div> <span id="success-msg" class="payment-errors"></span> <!-- stripe payment form --> <form action="<?php print site_url(); ?>stripe/callback" method="POST" id="paymentFrm"> <input type="hidden" name="amount" value="<?php print number_format($itemInfo['price']);?>"> <input type="hidden" name="product_name" value="<?php print $itemInfo['name'];?>"> <input type="hidden" name="product_id" value="<?php print $itemInfo['product_id'];?>"> <div class="row justify-content-center"> <div class="col-12 col-md-8 col-lg-6 pb-5"> <div class="row"></div> <!--Form with header--> <div class="card border-gray rounded-0"> <div class="card-header p-0"> <div class="bg-gray text-left py-2"> <h5 class="pl-2"><strong>Item Name: </strong><?php print $itemInfo['name'];?></h5> <h6 class="pl-2"><strong>Price: </strong> $<?php print number_format($itemInfo['price']);?> USD</h6> </div> </div> <div class="card-body p-3"> <!--Body--> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text">Full Name</div> </div> <input type="text" class="form-control" id="stripe-name" name="stripe_name" placeholder="Full Name *" value=""> </div> </div> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text">Email</div> </div> <input type="email" class="form-control" id="stripe-email" name="stripe_email" placeholder="Email *" value=""> </div> </div> <div class="form-group"> <div class="input-group mb-2"> <div class="input-group-prepend"> <div class="input-group-text">Card Number</div> </div> <input type="text" class="form-control" id="stripe-card-number" name="stripe_cart_no" placeholder="1234 5678 9012 3456" maxlength="20" autocomplete="off"> </div> </div> <div class="form-row"> <div class="form-group col-md-5"> <input type="text" class="form-control" id="stripe-card-expiry-month" name="stripe_month" placeholder="MM" maxlength="2" autocomplete="off"> </div> <div class="form-group col-md-5"> <input type="text" class="form-control" id="stripe-card-expiry-year" name="stripe_year" placeholder="YYYY" maxlength="4" autocomplete="off"> </div> <div class="form-group col-md-2"> <input type="text" class="form-control" id="stripe-card-cvc" name="cvc" placeholder="CVC" maxlength="3" autocomplete="off"> </div> </div> <div class="text-right"> <a href="<?php print site_url();?>" id="payBtn" class="btn btn-primary py-2">Back</a> <button type="buttom" id="payBtn" class="btn btn-info py-2">Pay</button> </div> </div> </div> </div> </div> </form> </div> </section> <?php $this->load->view('templates/footer');?> |
Step 9: Create a view(success)
Create a view file named success.php inside “application/views/stripe” folder
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $this->load->view('templates/header');?> <!-- container --> <section class="showcase"> <div class="container"> <div class="pb-2 mt-4 mb-2 border-bottom"> <h2>Strip Payment Gateway Integration in Codeigniter</h2> </div> <div class="text-xs-center"> <?php if(!empty($msg)) { echo $msg;}?> </div> </div> </section> <?php $this->load->view('templates/footer');?> |