Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
How To Integration Stripe Payment Gateway In Codeigniter

how to integration stripe payment gateway in codeigniter

Posted on September 16, 2019May 14, 2020 By XpertPhp No Comments on how to integration stripe payment gateway in codeigniter

In this tutorial, we will tell you how to integrate Stripe payment gateway in Codeigniter Framework(Codeigniter stripe payment gateway integrate example).

The Stripe payment gateway is a popular payment gateway method and it is easily used for the project. so many developers prefer that payment gateway method.

Stripe is a secure payment method and it’s work-based using API. it provides two environments for the user like a sandbox(Test) and live.

Overview

Step 1: Install or Download stripe-PHP Library
Step 2: Get and Set Stripe API Key and SECRET
Step 3: Create Controller
Step 4: Create View File

Step 1: Install or Download stripe-PHP Library
Now, we are going to install the stripe package using the below command and if you want to download the stripe-PHP library then you can download it on https://github.com/stripe/stripe-php. git repository.

1
composer require stripe/stripe-php

Step 2: Get and Set Stripe API Key and SECRET
In this step, we have to need the API Key and SECRET Key. so we will go to the official Stripe site and after then login gets API Key and SECRET Key after then we will set in a config file.
application/config/config.php

1
2
$config['stripe_key'] = 'pk_test_xxxxxxxxxxxxxxxxxxx';
$config['stripe_secret'] = 'sk_test_xxxxxxxxxxxxxx';

Step 3: Create Controller

In this step, we will create a Stripe.php file in the “application/controller” directory and paste the below code in this controller.
application/controller/Stripe.php

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
<?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() {
       parent::__construct();
       $this->load->library("session");
       $this->load->helper('url');
    }
    
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function index()
    {
        $this->load->view('stripe_form');
    }
        
    /**
     * Get All Data from this method.
     *
     * @return Response
    */
    public function payment()
    {
      require_once('application/libraries/stripe-php/init.php');
    
      $stripeSecret = 'YOUR STRIPE SECRETE KEY';
      \Stripe\Stripe::setApiKey($stripeSecret);
      
        $stripe = \Stripe\Charge::create ([
                "amount" => $this->input->post('amount'),
                "currency" => "usd",
                "source" => $this->input->post('tokenId'),
                "description" => "product 1"
        ]);
                  
        $data = array('success' => true, 'data'=> $stripe);
        echo json_encode($data);
    }
}
?>

Step 4: Create View File

So finally, we will create the stripe_form.php file in the “application/views/” directory.
application/views/stripe_form.php

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
<!DOCTYPE html>
<html>
<head>
  <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>How To Integration Stripe Payment Gateway In Codeigniter - XpertPhp</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <style>
   .container{
    padding: 0.5%;
   }
</style>
</head>
<body>
  <div class="container">
  
   <div class="row">
      <div class="col-md-12"><pre id="token_response"></pre></div>
    </div>
    <div class="row">
      <div class="col-md-4">
        <button class="btn btn-primary btn-block" onclick="pay(100)">Pay $100</button>
      </div>
      <div class="col-md-4">
        <button class="btn btn-success btn-block" onclick="pay(500)">Pay $500</button>
      </div>
      <div class="col-md-4">
        <button class="btn btn-info btn-block" onclick="pay(1000)">Pay $10000</button>
      </div>
    </div>
</div>
  
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>
  
<script type="text/javascript">
  
  function pay(amount) {
    var handler = StripeCheckout.configure({
      key: 'YOUR STRIPE KEY',
      locale: 'auto',
      token: function (token) {
        // You can access the token ID with `token.id`.
        // Get the token ID to your server-side code for use.
        console.log('Token Created!!');
        console.log(token)
        $('#token_response').html(JSON.stringify(token));
  
        $.ajax({
          url:"<?php echo base_url(); ?>stripe/payment",
          method: 'post',
          data: { tokenId: token.id, amount: amount },
          dataType: "json",
          success: function( response ) {
            console.log(response.data);
            $('#token_response').append( '<br />' + JSON.stringify(response.data));
          }
        })
      }
    });
  
    handler.open({
      name: 'Demo Site',
      description: '2 widgets',
      amount: amount * 100
    });
  }
</script>
</body>
</html>

Now you can see the following card details:

Number: 4242 4242 4242 4242
CSV: 123
Expiration Month: Use the future month
Expiration Year: Use the future month

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • Codeigniter 4 Ajax Image Upload with Preview Example
  • How To Create Line & Area Chart In Codeigniter With AmChart
  • CodeIgniter 4 Rest Api Example Tutorial
  • Codeigniter 4 Morris Area & Line Charts Example
  • CodeIgniter 4 Ajax Form Submit Validation Example
Codeigniter Tags:codeigniter stripe integration example, how to add stripe payment gateway in codeigniter, stripe payment gateway in codeigniter, stripe payment gateway integration in codeigniter

Post navigation

Previous Post: Laravel 6 CRUD Operation With Ajax Example
Next Post: How to add multiple markers in google maps using Codeigniter

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com