1

我正在发送以下数据。

array (size=7)
  'sellerId' => string '901252608' (length=9)
  'privateKey' => string '4A8093AA-6DC9-449B-BA7E-C9819ABB79D7' (length=36)
  'merchantOrderId' => string '12312' (length=5)
  'token' => string 'NTE0NTc5OTMtNWJmOC00YmE0LTkwN2YtNzg4MTNiN2QzNzI4' (length=48)
  'currency' => string 'USD' (length=3)
  'total' => string '10.00' (length=5)
  'billingAddr' => 
    array (size=6)
      'name' => string 'Joe Flagster' (length=12)
      'addrLine1' => string '123 Main Street' (length=15)
      'city' => string 'Townsville' (length=10)
      'state' => string 'Ohio' (length=4)
      'zipCode' => string '43206' (length=5)
      'country' => string 'USA' (length=3)

我收到响应错误的请求 - 参数错误

为什么我收到错误响应

4

3 回答 3

2

回答这个问题,也是成功执行第一次 2checkout 的完整指南。从 github下载2checkout lib 文件

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example Form</title>
    <script type="text/javascript" src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
    <form id="myCCForm" action="" method="post">
        <input name="token" type="hidden" value="" />
        <input id="ccNo" type="text" value="4000000000000002" autocomplete="off" required />
        <input id="expMonth" type="text" size="2" required value="12"/>
        <input id="expYear" type="text" size="4" required value="2016"/>
        <input id="cvv" type="text" value="123" autocomplete="off" required />
        <input type="submit" value="Submit Payment" />
    </form>
<script>
var successCallback = function(data) {
    var myForm = document.getElementById('myCCForm');
    myForm.token.value = data.response.token.token;
    myForm.submit();
};

var errorCallback = function(data) {
    if (data.errorCode === 200);
    else alert(data.errorMsg);
};

var tokenRequest = function() {
    var args = {
        sellerId: "901294338",
        publishableKey: "D0E54E96-FBB9-4A9C-98F0-81359D3FE574",
        ccNo: $("#ccNo").val(),
        cvv: $("#cvv").val(),
        expMonth: $("#expMonth").val(),
        expYear: $("#expYear").val()
    };
    TCO.requestToken(successCallback, errorCallback, args);
};

$(function() {
    TCO.loadPubKey('sandbox');
    $("#myCCForm").submit(function(e) {
        tokenRequest();
        return false;
    });
});

</script>
</body>
</html>
<?php
if(isset($_POST['token'])){
    require_once("lib/Twocheckout.php");
    Twocheckout::privateKey('7EF672B0-9F5E-499E-B4AE-6CBEC67277E1');
    Twocheckout::sellerId('901294338');
    Twocheckout::verifySSL(false);  // this is set to true by default
    Twocheckout::sandbox(true);
    Twocheckout::format('json');
    try {
        $charge = Twocheckout_Charge::auth(array(
            "sellerId" => "901294338",
            "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" => 'testingtester@2co.com',
                "phoneNumber" => '555-555-5555'
            ),
            "shippingAddr" => array(
                "name" => 'Testing Tester',
                "addrLine1" => '123 Test St',
                "city" => 'Columbus',
                "state" => 'OH',
                "zipCode" => '43123',
                "country" => 'USA',
                "email" => 'testingtester@2co.com',
                "phoneNumber" => '555-555-5555'
            )
        ));
        echo '<pre>';print_r(json_decode($charge));echo'</pre>';
    } catch (Twocheckout_Error $e) {echo $e->getMessage();}
}
?>

你需要改变YOUR_SELLER_IDYOUR_PUBLIC_KEYYOUR_PRIVATE_KEY用你自己的。也替换sandboxproduction如果它的生产,else keep sandbox

于 2015-10-19T12:29:16.370 回答
1

您是否在页面加载后设置公钥?因为我有同样的问题,但这是因为我忘记在 TCO 变量中设置公钥。

你必须设置公钥,试试这个代码:

TCO.loadPubKey('sandbox', function() {  // for sandbox environment
  publishableKey = //your public key
});

请记住将此函数放在 jQuery(function($) 中,因为当您尝试访问 TCO 变量时必须加载 twocheckout.js。

于 2015-10-08T15:36:00.697 回答
-1

Bad request - parameter error当 2checkout 阻止您的帐户时会发生错误。请检查并确保您有 2Checout 销售许可和批准的帐户

于 2016-05-04T18:30:02.817 回答