2Checkout : Bad request - parameter error

微笑、不失礼 提交于 2021-01-28 21:30:00

问题


I am sending below data.

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)

I am getting response Bad request - parameter error

Why I am getting error response


回答1:


Answer to this question and also is complete guide to perform your first 2checkout successfully. Download 2checkout lib files from github

<!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();}
}
?>

You need to change YOUR_SELLER_ID, YOUR_PUBLIC_KEY and YOUR_PRIVATE_KEY with your own. Also replace sandbox with production if its production, else keep sandbox




回答2:


Do you set the public key after the page load? Because I had the same problem, but it was because I forget set the public key in TCO variable.

You must set the public key, try this code:

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

Remember to put this function inside jQuery(function($), because twocheckout.js must be loaded when you try to access to TCO variable.




回答3:


Bad request - parameter error error occurs when 2checkout blocks your account. Please check and make sure you have 2Checout sale permission with approved account



来源:https://stackoverflow.com/questions/25227500/2checkout-bad-request-parameter-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!