安装从此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());
}
使用沙盒模式提交表单后,它会显示错误,例如&#34; cUrl调用失败&#34;。如何解决这个问题
答案 0 :(得分: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');
答案 1 :(得分:0)
2Checkout沙箱仅支持TLS 1.1和1.2协议。该库应该没有支持这些协议的问题。你能查看你正在运行的PHP
和OpenSSL
的版本吗?
php -v
和openssl version
OpenSSL增加了对TLS v1.1&amp; v1.0.1中的TLS v1.2。 OpenSSL 1.0.0h和OpenSSL 1.0.1之间的主要变化
thx:craigchristenson
答案 2 :(得分:0)
我使用的是Wamp64。当我添加apache-&gt; modules-&gt; ssl时,我的这个错误得到了解决。尽管我做了
Twocheckout::verifySSL(false);
但没有启用ssl就没有用。