How to integrate stripe payment gateway in Codeigniter ?

In last tutorial we have studied  stripe payment gateway in PHP In this tutorial I will explain you how to integrate stripe payment gateway in Codeigniter. There are lots of payment gateway available in the web market like PayPal and many more. Stripe is one of the most powerful payment gateway for Web and Mobile payment.Integration of Stripe payment gateway using Codeigniter is very easy. Just follow few steps and it will be ready.
Stripe take care the processing and keeping client’s card data so no information of essence would be stored on our server and you would not have to comply with all the rules that come with storing credit/debit cards.Stripe is the easiest way to accept credit and debit card payments online. With Stripe, you can create exactly the payment experience you want in your website or mobile app, and we handle everything from security to daily transfers to your bank account.

First create a stripe account on After registration click on my account

stripe payment gateway in php

Once you click on the account setting  click on the app keys to get secret key and publishable key. You will see the screen below

stripe gateway in PHP

Now download the stripe library from GITHUB and place in the your libraries folder in codeigniter location(codeigniter/application/libraries) and rename the folder to Stripe.

Now create a file name stripe.php in the view folder and write down the below code

<!DOCTYPE html>
<html lang="en">
<div class='web'>
<form action="<?php echo site_url('Stripe_payment/checkout');?>" method="POST">
<script src=""
data-image="your site image"
data-description="Demo Transaction ($100.00)"
data-amount="10000" />

Now create a controller name Stripe_payment.php and copy the following code

defined('BASEPATH') OR exit('No direct script access allowed');
class Stripe_payment extends CI_Controller {
	public function __construct() {
          public function index()
	public function checkout()
		try {	
			require_once(APPPATH.'libraries/Stripe/lib/Stripe.php');//or you
			Stripe::setApiKey("YOUR_SECRET_KEY"); //Replace with your Secret Key
			$charge = Stripe_Charge::create(array(
				"amount" => 10000,
				"currency" => "usd",
				"card" => $_POST['stripeToken'],
				"description" => "Demo Transaction"
			echo "<h1>Your payment has been completed.</h1>";	
		catch(Stripe_CardError $e) {
		catch (Stripe_InvalidRequestError $e) {
		} catch (Stripe_AuthenticationError $e) {
		} catch (Stripe_ApiConnectionError $e) {
		} catch (Stripe_Error $e) {
		} catch (Exception $e) {

Run the url Now you can integrate you payment using stripe.

Testing Card Number – 4242424242424242
CVV Number – 1234 
Card Expiry Date – Use any future date

Hope this tutorial how to integrate stripe payment gateway in Codeigniter will help you.

  • Franck


    I’ve an error in my code:

    A PHP Error was encountered
    Severity: Error
    Message: Class ‘Stripe’ not found
    Filename: controllers/Stripe_payment.php
    Line Number: 21

    can you help me ?

    • mk

      I got the same error, did you manage to find the solution?

      • Franck

        no solution for the moment :(

        • mk

          A friend recommended this video. It helped me. Maybe it will help you too.

          • Shany Mathew

            can you help me? i cant watch this.please help

  • Ricky Negi

    This Error indicate that your libraries are missing. Make sure you have downloaded the Stripe library from Github and place in the folder library inside application below:


    If you have already done then go to libraries->Stripe->lib and rename the file stripe.php to Stripe.php. There might be First capital in the file name in small letter (s) that need to replace with Capital (S). Hope this will help you.

    • mk

      I did what you recommended, does this need to be done on a live server or localhost. Can you explain weebhooks…does this affect this setup?

  • mk

    Thanks @rickynegi:disqus I used this video to fix my errors.