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

时间:2015-07-31 10:33:54

标签: php codeigniter

我想在codeigniter中整合条带支付网关。我以前使用条带的核心php库,它工作正常,但在codeigniter我如何在codeigniter中集成它。

我的文件如下: 视图:

<?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(); ?>
                            “/&GT;                                                                                                                                                                                                        

控制器:

public function stripe_charge(){
        echo "stripe function working"."<br>";
        echo $this->input->post('amount');
        Stripe::setApiKey("sk_test_yDE2WSUQ3wexrlhqO01PeANe");
}

并发生错误: 条纹功能工作 致命错误:第578行的D:\ xamp \ htdocs \ halal_lte \ application \ controllers \ vendor.php中找不到“Stripe”类

3 个答案:

答案 0 :(得分:0)

将条带库放入系统/库中,然后

 

$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>

答案 1 :(得分:0)

下载stripe.php如果您没有,请将其放入app/protected/components。组件应从main.php

自动加载
'import'=>array(
        ..
        'application.components.*',
        ..
    ),

现在可以使用

Stripe::setApiKey("sk_test_yDE2WSUQ3wexrlhqO01PeANe");

答案 2 :(得分:0)

如果您已经准备好了库,那么您需要将它放在应用程序/库文件夹中。

我建议你解压缩计算机上的所有文件,也许你会有配置文件,你需要把它放在配置文件夹中,你需要通过readme.md文件来获取所有需要的信息。

你需要检查一下你可能需要PHP的(Composer)

依赖管理

运行该库。