与Stripe通信时出现意外错误

Ahm*_*Ali 8 cakephp-2.0 stripe-payments

用条纹计费我有一个表格,我提交信息并下订单后发生错误....

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 )
Run Code Online (Sandbox Code Playgroud)

我的控制器动作代码

    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)));
Run Code Online (Sandbox Code Playgroud)

和我的看法

<?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'));
?>
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

yka*_*ica 12

如果您没有ssl支持,您将在localhost上收到此错误.

您可以在拨打电话之前使用以下内容来解决此问题.

\Stripe\Stripe::setVerifySslCerts(false);
Run Code Online (Sandbox Code Playgroud)


CPH*_*hon 5

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

因此,我联系了Stripe支持人员,他们向我建议了一些步骤(如下所述),最终使我遇到了真正的问题,即文件结构:

  • data / ca-certificates.crtStripe.phpgetDefaultCABundlePath()by 引用dirname(__FILE__) . '/../data/ca-certificates.crt',如果找不到此文件,则可能会出现ApiConnection错误,将空属性作为输出,就像在另一个问题中发布的那样。

因此,解决方案就是将文件确切地放置在该路径上,或者将其移动到特定目录并在Stripe.php中更新其引用(例如,相同的文件夹=> dirname(__FILE__) . '/ca-certificates.crt')。

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

  1. 在服务器中测试TLS:在通过Stripe支持推荐的脚本确保TLSv1.2在服务器中可运行之后,产生以下输出:

    • TLS测试(预设):TLS 1.2
    • TLS测试(TLS_v1):TLS 1.2
    • TLS测试(TLS_v1_2):TLS 1.2
  2. 然后他们建议我检查兼容性问题

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

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

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

    产生了以下内容:

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

  4. 由于服务器正在运行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
    
    Run Code Online (Sandbox Code Playgroud)

    由于这些软件包是服务器中的最新版本,因此我决定再次查看Stripe的zip文件结构,并发现当我解压缩文件时,ca-certificates.crt的路径与其中的路径不同。Stripe.php(引起问题的原因)。

  • ** @ CPHPython **感谢您的回答!它会帮助别人。 (2认同)
  • 这是正确的答案。其他答案是不安全的,即使用于测试也是如此。我很好奇为什么 php.ini 中的 cURL 设置中的默认值没有被使用。 (2认同)

小智 4

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

  • @shturm,我想首先在本地主机上实现 Stripe 以使其正常工作。但我遇到了同样的错误。您能告诉我如何解决此证书问题吗?因为我想在测试模式下充电。如果没有 https,Stripe 就无法工作。另外请分享 php 中的任何工作代码。谢谢。 (2认同)