Today, We want to share with you stripe payment gateway integration in codeigniter.In this post we will show you add credit card payment gateway in your php codeigniter 3 app, hear for use stripe payment gateway in your codeigniter website we will give you demo and example for implement.In this post, we will learn about CodeIgniter Stripe Payment Gateway Api Integration with an example.
Codeigniter Stripe Payment Gateway Integration Example
Option 1 : Download stripe-php Library
we need to download the stripe card payment gateway library https://github.com/stripe/stripe-php..
“application/libraries” folder
make sure the rename folder name “stripe-php”.
Option 2 : Install stripe package Via Composer
composer require stripe/stripe-php
To use the bindings, use the Composer’s autoload
require_once('vendor/autoload.php');
Step 2: Create Controller
step 2: application/controller/Stripe.php
load->library("session"); $this->load->helper('url'); } /** * Get All Data from this method. * * @return Response */ public function index() { $this->load->view('stripePayment/index'); } /** * 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" => "This is from www.pakainfo.com" ]); $response = array('success' => true, 'response'=> $stripe); echo json_encode($response); } }
Step 3: Create View File
application/views/stripePayment/index.php
Codeigniter Stripe Payment Gateway Integration - www.pakainfo.com
function pay(amount) { var handler = StripeCheckout.configure({ key: 'YOUR STRIPE KEY', locale: 'auto', token: function (token) { console.log('Token Created!!'); console.log(token) $('#token_response').html(JSON.stringify(token));
$.ajax({ url:"stripe/payment", method: 'post', data: { tokenId: token.id, amount: amount }, dataType: "json", success: function( response ) { console.log(response.data); $('#token_response').append( '
' + JSON.stringify(response.data)); } }) } });handler.open({ 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: 2024I hope you get an idea about how to integrate stripe payment gateway in codeigniter 3..
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.