Codeigniter Stripe Payment Gateway Integration Example




Codeigniter Stripe Payment Gateway Integration Example

Hi Guys,

In this tutorial,I will learn you how to use stripe payment gateway integration in can simply and esay to use the Stripe Payment Gateway Integration in Codeigniter.

we will discuss step by step how to integrate stripe card payment gateway in our Codeigniter version 3 based project.

Stripe is a fastest online payment processing for internet businesses. stripe provide credit card payment, subscription payment.

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

Step 1: Download Stripe Payment Gateway Library

There are two option for download or install stripe library for codeigniter.

Option 1 : Download stripe-php Library

we need to download the stripe card payment gateway library here:

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

Option 2 : Install stripe package Via Composer

The second option to install a stripe package via the composer for Codeigniter.

composer require stripe/stripe-php

To use the bindings, use the Composer’s autoload


Step 2: Create Controller

First of all, we need to create a new Stripe controller, So go application/controller and create a new controller name Stripe.php.



defined('BASEPATH') OR exit('No direct script access allowed');

class Stripe 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 payment()



$stripeSecret = 'YOUR STRIPE SECRETE KEY';


$stripe = \Stripe\Charge::create ([

"amount" => $this->input->post('amount'),

"currency" => "usd",

"source" => $this->input->post('tokenId'),

"description" => "This is from"


// after successfull payment, you can store payment related information into your database

$data = array('success' => true, 'data'=> $stripe);

echo json_encode($data);



Step 3: Create View File

last step,you can create to view file in project.


<!DOCTYPE html>



<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<meta name="csrf-token" content="{{ csrf_token() }}">

<title>Codeigniter Stripe Payment Gateway Integration -</title>

<link rel="stylesheet" href="" />

<script src=""></script>



padding: 0.5%;





<div class="container">

<div class="row">

<div class="col-md-12"><pre id="token_response"></pre></div>


<div class="row">

<div class="col-md-4">

<button class="btn btn-primary btn-block" onclick="pay(100)">Pay $100</button>


<div class="col-md-4">

<button class="btn btn-success btn-block" onclick="pay(500)">Pay $500</button>


<div class="col-md-4">

<button class="btn btn-info btn-block" onclick="pay(1000)">Pay $10000</button>




<script src=""></script>

<script src=""></script>

<script src=""></script>

<script type="text/javascript">

function pay(amount) {

var handler = StripeCheckout.configure({


locale: 'auto',

token: function (token) {

// You can access the token ID with ``.

// Get the token ID to your server-side code for use.

console.log('Token Created!!');




url:"<?php echo base_url(); ?>stripe/payment",

method: 'post',

data: { tokenId:, amount: amount },

dataType: "json",

success: function( response ) {


$('#token_response').append( '<br />' + JSON.stringify(;





name: 'Demo Site',

description: '2 widgets',

amount: amount * 100






Now you can check with following card details:


Name: Test

Number: 4242 4242 4242 4242

CSV: 123

Expiration Month: 12

Expiration Year: 2024

It will help you...