Site Admin
Site Admin Founder of MeaningArticles

Codeigniter Stripe Payment Gateway integration example

Hello Dev.

In case you need to add credit card payment gateway to your php codeigniter 3 application, then i'm able to advise you to apply stripe payment gateway on your codeigniter website. in this article i'm able to give an explanation for the way to integrate stripe payment gateway in codeigniter 3.
Stripe is a fastest online payment processing for internet businesses. stripe offer credit card payment, subscription payment. the most benefit is a they prevent fraud payment.

we are able to use php code library for stripe payment gateway. earlier than you integrate stripe payment gateway you have got stripe account or stripe developer account so, you can without difficulty get stripe api key and secret. then you can use it with this instance.

So, let's follow bellow few steps and you can make payment with codeigniter project.

Step 1: Create Codeigniter Project

CodeIgniter comes in three versions: CodeIgniter 3, 4 and CodeIgniter 2 (legacy), for this tutorial you can visit the official codeigniter site and Download the CodeIgniter 3 app.

Step 2: Download stripe-php Library

In this step we need to download stripe-php library from here: Download.

After download, you have to extract that folder into "application/libraries" folder and make sure rename folder name "stripe-php".

Step 3: Set Stripe API Key and SECRET

Now, we need to set stripe key and secret. so first you can go on Stripe website and create or login stripe account key and secret and add in config.php file:

If you don’t have secret publisher key. So, first of all, you need to REGISTER and get secret publisher key and secret key.

If you have already registered with stripe, so click this link and login on stripe and get the secret publisher key and the secret key LOGIN.

Get secret publisher and key on stripe dashboard looks like:


$config['stripe_key'] = 'your stripe key';

$config['stripe_secret'] = 'your stripe secret';

Step 4: Create Routes

In this step, we will create two routes for get request and another for post request. So, let's add new route on that file.


$route['my-stripe'] = "StripeController";
$route['stripePost']['post'] = "StripeController/stripePost";

Step 5: Create Controller

in next step, now we have create new controller as StripeController and write both method on it like as bellow, So let's create both controller:

defined('BASEPATH') OR exit('No direct script access allowed');
class StripeController extends CI_Controller {
     * Get All Data from this method.
     * @return Response
    public function __construct() {
     * Get All Data from this method.
     * @return Response
    public function index()
     * Get All Data from this method.
     * @return Response
    public function stripePost()
        \Stripe\Charge::create ([
                "amount" => 100 * 100,
                "currency" => "usd",
                "source" => $this->input->post('stripeToken'),
                "description" => "Test payment from" 
        $this->session->set_flashdata('success', 'Payment made successfully.');
        redirect('/my-stripe', 'refresh');

Step 6: Create View File

In Last step, let's create my_stripe.php(application/views/my_stripe.blade.php) for layout and write code of jquery to get token from stripe here and put following code:

<!DOCTYPE html>
    <title>Codeigniter Stripe Payment Integration Example -</title>
    <link rel="stylesheet" href="" />
    <script src=""></script>
    <style type="text/css">
        .panel-title {
        display: inline;
        font-weight: bold;
        .display-table {
            display: table;
        .display-tr {
            display: table-row;
        .display-td {
            display: table-cell;
            vertical-align: middle;
            width: 61%;
<div class="container">
    <h1>Codeigniter Stripe Payment Integration Example <br/></h1>
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <div class="panel panel-default credit-card-box">
                <div class="panel-heading display-table" >
                    <div class="row display-tr" >
                        <h3 class="panel-title display-td" >Payment Details</h3>
                        <div class="display-td" >                            
                            <img class="img-responsive pull-right" src="">
                <div class="panel-body">
                    <?php if($this->session->flashdata('success')){ ?>
                    <div class="alert alert-success text-center">
                            <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                            <p><?php echo $this->session->flashdata('success'); ?></p>
                    <?php } ?>
                    <form role="form" action="/stripePost" method="post" class="require-validation"
                                                    data-stripe-publishable-key="<?php echo $this->config->item('stripe_key') ?>"
                        <div class='form-row row'>
                            <div class='col-xs-12 form-group required'>
                                <label class='control-label'>Name on Card</label> <input
                                    class='form-control' size='4' type='text'>
                        <div class='form-row row'>
                            <div class='col-xs-12 form-group card required'>
                                <label class='control-label'>Card Number</label> <input
                                    autocomplete='off' class='form-control card-number' size='20'
                        <div class='form-row row'>
                            <div class='col-xs-12 col-md-4 form-group cvc required'>
                                <label class='control-label'>CVC</label> <input autocomplete='off'
                                    class='form-control card-cvc' placeholder='ex. 311' size='4'
                            <div class='col-xs-12 col-md-4 form-group expiration required'>
                                <label class='control-label'>Expiration Month</label> <input
                                    class='form-control card-expiry-month' placeholder='MM' size='2'
                            <div class='col-xs-12 col-md-4 form-group expiration required'>
                                <label class='control-label'>Expiration Year</label> <input
                                    class='form-control card-expiry-year' placeholder='YYYY' size='4'
                        <div class='form-row row'>
                            <div class='col-md-12 error form-group hide'>
                                <div class='alert-danger alert'>Please correct the errors and try
                        <div class="row">
                            <div class="col-xs-12">
                                <button class="btn btn-primary btn-lg btn-block" type="submit">Pay Now ($100)</button>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function() {
    var $form         = $(".require-validation");
  $('form.require-validation').bind('submit', function(e) {
    var $form         = $(".require-validation"),
        inputSelector = ['input[type=email]', 'input[type=password]',
                         'input[type=text]', 'input[type=file]',
                         'textarea'].join(', '),
        $inputs       = $form.find('.required').find(inputSelector),
        $errorMessage = $form.find('div.error'),
        valid         = true;
    $inputs.each(function(i, el) {
      var $input = $(el);
      if ($input.val() === '') {
    if (!$'cc-on-file')) {
        number: $('.card-number').val(),
        cvc: $('.card-cvc').val(),
        exp_month: $('.card-expiry-month').val(),
        exp_year: $('.card-expiry-year').val()
      }, stripeResponseHandler);
  function stripeResponseHandler(status, response) {
        if (response.error) {
        } else {
            var token = response['id'];
            $form.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");

Now you can check with following card details:

Name: Test

Number: 4242 4242 4242 4242

CSV: 123     Expiration Month: 12     Expiration Year: 2024

i'm hoping it assist you to, thanks for visit my article if you like my article then proportion together with your friend and social platform.