【问题标题】:Unexpected error communicating with Stripe与 Stripe 通信时出现意外错误
【发布时间】:2013-12-11 07:32:45
【问题描述】:

使用 Stripe 计费我有一个表格,我提交信息并下订单,出现以下错误....

Unexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com. (Network error [errno 77]: error setting certificate verify locations: CAfile: C:\xampp\htdocs\PhpProject2\app\Lib\Stripe/../data/ca-certificates.crt CApath: none )

我的控制器操作代码

    if(!empty($this->request->data)){            
        $email = $this->request->data['email'];
        $credit_card = $this->request->data['card_number'];
        $expire_month = $this->request->data['expiration_month'];
        $expire_year = $this->request->data['expiration_year'];
        $cvc = $this->request->data['cvc'];  
        //require_once('./lib/Stripe.php');
        require_once "./../lib/Stripe.php";
        Stripe::setApiKey("sk_test_KEY"); 
        $token = Stripe_Token::create(array(
            "card" => array(
            "number" => $credit_card, 
            "exp_month" => $expire_month, 
            "exp_year" => $expire_year, 
            "cvc" => $cvc)));

我的看法

<?php

echo $this->Form->create(false, array('action' => 'index'));
echo $this->Form->input('email', array('id' => 'email'));
echo $this->Form->input('card_number');
$options = array('1' => 'January', '2' => 'February', '3' => 'March', '4' => 'April',
 '5' =>'May', '6' => 'June', '7' => 'July', '8' => 'August', '9' => 'September',
'10' =>  'October', 
'11' => 'November', '12' => 'December');

 $start_year =array('1'=>2013,'2'=>2014,'3'=>2015,'4'=>2016,
'5'=>2017,'6'=>2018,'7'=>2019,'8'=>2020,'9'=>2021);

echo $this->Form->input('expiration_month', array('type' => 'select', 'options' => $options));
echo $this->Form->input('cvc');
echo $this->Form->end('place order', array('controller' => 'stripes', 'action' => 'index'));
?>

任何帮助将不胜感激

【问题讨论】:

    标签: cakephp-2.0 stripe-payments


    【解决方案1】:

    如果您的 CA 包配置不正确,您将收到此错误。

    您可以在拨打收费电话之前使用以下方法来解决此问题。

    \Stripe\Stripe::setVerifySslCerts(false);
    

    这将使您的流量(包括客户端 PII)容易受到拦截和/或篡改。

    【讨论】:

    • 或:\Stripe\Stripe::setVerifySslCerts(false);
    • 这是个糟糕的建议,尤其是在处理信用卡付款时。这种方法是在他们的代码库中定义的事实是非常糟糕的安全性。
    【解决方案2】:

    禁用 SSL 证书验证 (\Stripe\Stripe::setVerifySslCerts(false); suggested by ykay) 在测试/本地环境中对我很有用,但在生产中仍需要进行此验证。

    所以我联系了 Stripe 支持,他们向我建议了几个步骤(如下所述),最终导致我遇到了真正的问题,我的文件结构:

    • data/ca-certificates.crt 被 Stripe.php 的 getDefaultCABundlePath() 引用。如果未找到此文件,您可能会收到 ApiConnection 错误,输出为空属性,就像在 this other question 中发布的一样。

    所以解决方案要么简单地将这个文件放在那个路径上,要么将它移动到另一个目录并使用Stripe::setCABundlePath()更新它的位置。

    如果正确引用了所有 Stripe 文件:验证 TLSv1.2 支持的步骤

    1. 在服务器中测试 TLS:在通过 Stripe 支持推荐的 this script 确保 TLSv1.2 在服务器中运行之后,产生以下输出:
    • TLS 测试(默认):TLS 1.2
    • TLS 测试 (TLS_v1):TLS 1.2
    • TLS 测试 (TLS_v1_2):TLS 1.2
    1. 然后他们建议我检查兼容性问题:

    https://github.com/stripe/stripe-php#ssl--tls-compatibility-issues

    1. 这导致我在升级 cURL 和 OpenSSL 包中运行脚本,该脚本测试并使用 Stripe 的 PHP 集成(需要 Stripe 的 init.php 代码):

    https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php

    产生了以下内容:

    不支持 TLS 1.2。您将需要升级您的集成。

    1. 由于服务器运行的是 Ubuntu (cat /etc/*-release),因此我升级了 OpenSSL 版本:

    https://support.stripe.com/questions/how-do-i-upgrade-my-openssl-to-support-tls-1-2

    使用以下命令:

        sudo apt-get update && sudo apt-get install --only-upgrade openssl
        sudo apt-get update && sudo apt-get install --only-upgrade libssl-dev
    

    由于这些包在服务器中是最新版本,我决定再看一下 Stripe 的 zip 文件结构,发现当我解压缩文件时,ca-certificates.crt 的路径 与 Stripe.php 中的不一样(这是导致问题的原因)。

    【讨论】:

    • @CPHPython 感谢您的回答!它会帮助别人。
    • 这是正确的答案。其他答案是不安全的,即使对于测试也是如此。我很好奇为什么没有使用 php.ini 中 cURL 设置中的默认设置。
    【解决方案3】:

    不确定,但您的代码可能正在运行。问题是它们需要通过您在使用库时未设置的证书文件(在库本身中,SDK 通常像这样工作)或路径不可解析(混合正/反斜杠)来完成加密通信。

    【讨论】:

    • @shturm,我想先在 localhost 上实现 Stripe 以使其工作。但是我遇到了同样的错误。您能否让我知道如何解决此证书问题。因为我想在测试模式下充电。没有 https,Stripe 就无法工作。也请在 php.ini 中分享任何工作代码。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    相关资源
    最近更新 更多