您正在使用2checkout沙箱来测试付款解决方案。令牌已成功创建并记录在我的API日志控制台中。但最后我看到错误cURL call failed
这是我的代码
的index.html
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
</head>
<body>
<form id="myCCForm" action="payment.php" method="post">
<input id="token" name="token" type="hidden" value="">
<div>
<label>
<span>Card Number</span>
</label>
<input id="ccNo" type="text" size="20" value="" autocomplete="off" required />
</div>
<div>
<label>
<span>Expiration Date (MM/YYYY)</span>
</label>
<input type="text" size="2" id="expMonth" required />
<span> / </span>
<input type="text" size="2" id="expYear" required />
</div>
<div>
<label>
<span>CVC</span>
</label>
<input id="cvv" size="4" type="text" value="" autocomplete="off" required />
</div>
<input type="submit" value="Submit Payment">
</form>
</body>
<script>
// Called when token created successfully.
var successCallback = function(data) {
var myForm = document.getElementById('myCCForm');
// Set the token as the value for the token input
myForm.token.value = data.response.token.token;
// IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
myForm.submit();
};
// Called when token creation fails.
var errorCallback = function(data) {
if (data.errorCode === 200) {tokenRequest();} else {alert(data.errorMsg);}
};
var tokenRequest = function() {
// Setup token request arguments
var args = {
sellerId: "My seller id added here",
publishableKey: "my publishableKey added here",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
$(function() {
// Pull in the public encryption key for our environment
TCO.loadPubKey('sandbox');
$("#myCCForm").submit(function(e) {
// Call our token request function
tokenRequest();
// Prevent form from submitting
return false;
});
});
</script>
</html>
payment.php
require_once("2checkout-php/lib/Twocheckout.php");
Twocheckout::privateKey('my private hey here');
Twocheckout::sellerId('my seller id here');
Twocheckout::sandbox(true);
try {
$charge = Twocheckout_Charge::auth(array(
"merchantOrderId" => "123",
"token" => $_POST['token'],
"currency" => 'USD',
"total" => '10.00',
"billingAddr" => array(
"name" => 'Testing Tester',
"addrLine1" => '123 Test St',
"city" => 'Columbus',
"state" => 'OH',
"zipCode" => '43123',
"country" => 'USA',
"email" => 'example@2co.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());}
这是我的API控制台
我尝试添加
Twocheckout::username('username');
Twocheckout::password('password');
和
Twocheckout::verifySSL(false);
没有任何作用。可以有人请帮我解决这个问题。谢谢。
答案 0 :(得分:0)
请确保您使用的是TLS v1.1或v1.2,因为这些是沙箱环境当前支持的唯一协议。您可以查看哪个版本的PHP&amp;您正在使用的SSL(php -v,openssl版本)以确保您是最新的。 OpenSSL有一些重大变化,可以在这里找到: https://www.openssl.org/news/openssl-1.0.1-notes.html