I would like to integerate stripe payment gateway in codeigniter. I previously uses core php library of stripe and it works fine but in codeigniter how i integerate it in codeigniter.
my files are like below : view:
<?php //echo form_open('vendor/stripe_charge'); ?>
<input type="text" name="data-key" value="<?php echo "pk_test_lWC3x0aqak9UBnQy6JnRTGOL";//echo $config['publishable_key']; ?>"/>
<input type="text" name="data-amount" value="5000"/>
<input type="text" name="data-description" value="Paying your bill"/>
<input type="text" name="data-name" value="Yummylicious"/>
<input type="text" name="data-image" value="http://interiorlounge.com.pk/wp-content/uploads/2013/04/logo_huawei_128x128.jpg"/>
<input type="text" name="data-label" value="Pay Your Bill"/>
<input type="submit" value="Pay Your Bill"/>
<!--
// optional parameters in javascript
data-shipping-address="true"
data-billing-address="true" -->
<?php echo form_close(); ?>
"/>controller :
public function stripe_charge(){
echo "stripe function working"."<br>";
echo $this->input->post('amount');
Stripe::setApiKey("sk_test_yDE2WSUQ3wexrlhqO01PeANe");
}
and error occurs : stripe function working Fatal error: Class 'Stripe' not found in D:\xamp\htdocs\halal_lte\application\controllers\vendor.php on line 578
Place stripe library into system/libaries then
$stripe = array(
"secret_key" => STRIPE_SECRET_KEY,
"publishable_key" => STRIPE_PUBLISHABLE_KEY
);
try {
\Stripe\Stripe::setApiKey($stripe['secret_key']);
---and do what you want to do---
} catch (\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();`enter code here`
$err = $body['error'];
return $err['message'];
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
$body = $e->getJsonBody();
$err = $body['error'];
return $err['message'];
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
$body = $e->getJsonBody();
$err = $body['error'];
return $err['message'];
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
$body = $e->getJsonBody();
$err = $body['error'];
return $err['message'];
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
$body = $e->getJsonBody();
$err = $body['error'];
return $err['message'];
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
$body = $e->getJsonBody();
$err = $body['error'];
return $err['message'];
}</pre>
download stripe.php if you don't have and place this into app/protected/components
. components should be autoloaded from main.php
'import'=>array(
..
'application.components.*',
..
),
now you can use
Stripe::setApiKey("sk_test_yDE2WSUQ3wexrlhqO01PeANe");
If u have already prepared Library than u need to put it in application/library folder.
I suggest that u unzip all files on your computer maybe u will have config files which u need to put in config folder and u need to go over readme.md file to get all needed information.
and u need to check maybe u need Dependency Management for PHP(Composer)
to run that libary.