2CheckOut-TwoCheckoutException:错误的请求-参数错误

问题描述 投票:0回答:1

所以基本上我试图在我的网站上实现2checkout,并且我已经完成了文档中的所有操作,但出现此错误:TwoCheckoutException: Bad request - parameter error。我尝试检查并使用私钥/公钥和ID,但是当我更改它们时,它显示“身份验证错误”,因此我确定它们还可以。我了解了地址和所有内容,并且更改了它们,但仍无法正常工作。

这是我的完整代码:

@{
    ViewData["Title"] = "Test";
}
    <script type="text/javascript" src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
<h2>Test</h2>
<form id="myCCForm" action="/Home/SubmitCard" method="post">
    <input name="token" type="hidden" value="" />
    <div>
        <label>
            <span>Card Number</span>
            <input id="ccNo" type="text" value="" autocomplete="off" required />
        </label>
    </div>
    <div>
        <label>
            <span>Expiration Date (MM/YYYY)</span>
            <input id="expMonth" type="text" size="2" required />
        </label>
        <span> / </span>
        <input id="expYear" type="text" size="4" required />
    </div>
    <div>
        <label>
            <span>CVC</span>
            <input id="cvv" type="text" value="" autocomplete="off" required />
        </label>
    </div>
    <input type="submit" value="Submit Payment" />
</form>

<script type="text/javascript">

    // 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) {
            alert("Error 200");
            // This error code indicates that the ajax call failed. We recommend that you retry the token request.
        } else {
            alert(data.errorMsg);
        }
    };

    var tokenRequest = function () {
        // Setup token request arguments
        var args = {
            sellerId: "901417674",
            publishableKey: "309FC596-8380-4B6F-B269-3E157A5A5D0B",
            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>

这是服务器端代码:

public IActionResult SubmitCard()
{
    TwoCheckout.TwoCheckoutConfig.SellerID = "901417674";
    TwoCheckout.TwoCheckoutConfig.PrivateKey = "4E704021-B233-435F-A904-47B2620B9E66";
    TwoCheckout.TwoCheckoutConfig.Sandbox = true;

    try
    {
        TwoCheckout.AuthBillingAddress Billing = new TwoCheckout.AuthBillingAddress();
        Billing.addrLine1 = "123 Main Street";
        Billing.city = "Townsville";
        Billing.zipCode = "43206";
        Billing.state = "Ohio ";
        Billing.country = "USA";
        Billing.name = "Joe Flagster";
        Billing.email = "[email protected]";
        Billing.phoneNumber = "065";

        TwoCheckout.ChargeAuthorizeServiceOptions Customer = new TwoCheckout.ChargeAuthorizeServiceOptions();
        Customer.total = 1;
        Customer.currency = "USD";
        Customer.merchantOrderId = "12";
        Customer.billingAddr = Billing;
        Customer.token = Request.Form["token"];

        TwoCheckout.ChargeService Charge = new TwoCheckout.ChargeService();

        var result = Charge.Authorize(Customer);
        return View("Success", result);
    }
    catch(TwoCheckout.TwoCheckoutException ex)
    {
        return View("Error", ex.ToString());
    }
}

这是我的沙盒中的所有信息:

enter image description here

javascript c# payment 2checkout
1个回答
0
投票

您可能需要从站点管理-> 站点设置更新沙箱的站点设置,并转到进行演示设置并再次检查

希望对您有帮助

© www.soinside.com 2019 - 2024. All rights reserved.