2

安装从这个 github 下载的包后。

https://github.com/2checkout/2checkout-php

require_once("lib/Twocheckout.php");

Twocheckout::privateKey('privatekey'); //Private Key

Twocheckout::sellerId('sellerid'); // 2Checkout Account Number

// If you want to turn off SSL verification (Please don't do this in your production environment)

Twocheckout::verifySSL(false);  // this is set to true by default
// To use your sandbox account set sandbox to true
Twocheckout::sandbox(true);
// All methods return an Array by default or you can set the format to 'json' to get a JSON response.

Twocheckout::format('json');

try {
$charge = Twocheckout_Charge::auth(array(
    "merchantOrderId" => "123",
    "token"      => $_POST['token'],
    "currency"   => 'USD',
    "total"      => '10.00',
    "billingAddr" => array(
        "name" => 'Joe Flagster',
        "addrLine1" => '123 Main Street',
        "city" => 'Townsville',
        "state" => 'OH',
        "zipCode" => '43206',
        "country" => 'USA',
        "email" => 'testingemail@gmail.com',
        "phoneNumber" => '555-555-5555'
    )
));

if ($charge['response']['responseCode'] == 'APPROVED') {
    echo "Thanks for your Order!";
    echo "<h3>Return Parameters:</h3>";
    echo "<pre>";
    print_r($charge);
    echo "</pre>";

}
} catch (Twocheckout_Error $e) {
print_r($e->getMessage());
}

使用沙盒模式提交表单后,它会显示类似“cUrl call failed”之类的错误。如何解决这个问题

4

4 回答 4

4

添加以下行

Twocheckout::verifySSL(false);
于 2015-08-25T08:14:40.830 回答
1

如果我们为 twocheckout 设置用户名和密码,它将正常工作。

在此行下方添加此行:

require_once("lib/Twocheckout.php");

// Your username and password are required to make any Admin API call.
Twocheckout::username('username');
Twocheckout::password('password');
于 2015-05-22T10:30:25.023 回答
0

2Checkout 沙盒仅支持 TLS 1.1 和 1.2 协议。这个库应该没有支持这些协议的问题。你能检查一下你正在运行 PHP的版本吗?和OpenSSLphp -vopenssl version

OpenSSL 在 v1.0.1 中添加了对 TLS v1.1 和 TLS v1.2 的支持。OpenSSL 1.0.0h 和 OpenSSL 1.0.1 之间的主要变化

谢谢:克雷格克里斯滕森

于 2016-02-18T10:20:18.160 回答
0

我正在使用 Wamp64。当我添加 apache->modules->ssl 时,我的这个错误得到了解决。尽管我做了

Twocheckout::verifySSL(false);

但如果不启用 ssl 就无法解决。

于 2017-11-18T15:58:03.087 回答