【问题标题】:2CheckOut - TwoCheckoutException: Bad request - parameter error2CheckOut - TwoCheckoutException:错误请求 - 参数错误
【发布时间】:2020-01-02 20:41:21
【问题描述】:

所以基本上我正在尝试在我的网站中实现 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 = "Ex@a.com";
        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());
    }
}

这是来自我的沙盒的所有信息:

【问题讨论】:

    标签: javascript c# payment 2checkout


    【解决方案1】:

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多