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 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计