doulao7572 2015-07-31 10:33 采纳率: 0%
浏览 55
已采纳

如何在codeigniter中集成Stripe支付网关

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

  • 写回答

3条回答 默认 最新

  • duanfang2708 2015-07-31 10:42
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀