2019-07-12

Stripe is the polular payment Gateway. Stripe Payment Gateway clean, fast, secure payments services and 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.

Also Read : Razorpay Payment Gateway Integration in Codeigniter using cURL

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

system

index.php

vendor

assets

css

style.css

js

custom.css

Step-2: Create MySQL Database and Table

1- product table

2- orders table

Open application/config/autoload.php file and add/update code like as bellow:

Step-3: Define constants

Update file named constants.php inside “application/config/” folder

Open application/config/database.php file and add constants like as bellow:

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 details

callback() – charges process.

get_curl_handle() – handle curl process

success() – success information .

Step 2: Create a model file

Create a model file named Payment_model.php” inside “application/models” folder.

Open application/config/routes.php file and add code like as bellow:

Step-5: Stripe Token and Validate Card with Stripe.js:

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.

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.

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.

Step 8: Create a view(index)

Create a view file named index.php inside “application/views/stripe” folder

Step 9: Create a view(checkout)

Create a view file named checkout.php inside “application/views/stripe” folder

Step 9: Create a view(success)

Create a view file named success.php inside “application/views/stripe” folder

Also Read : Razorpay Payment Gateway Integration in Codeigniter using cURL

Demo

Download

Show more