Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 2CheckOut-TwoCheckoutException:错误请求-参数错误_Javascript_C#_Payment_2checkout - Fatal编程技术网

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

Javascript 2CheckOut-TwoCheckoutException:错误请求-参数错误,javascript,c#,payment,2checkout,Javascript,C#,Payment,2checkout,因此,基本上我试图在我的网站中实现2checkout,我已经从文档中完成了所有工作,但我得到了以下错误:TwoCheckoutException:Bad request-parameter error。我试着检查和使用私钥/公钥和id,但当我更改它们时,它会显示“授权错误”,所以我确信它们没有问题。我读到了地址和所有信息,我已经更改了地址,但仍然无法工作 这是我的全部代码: @{ ViewData["Title"] = "Test"; } <script type="tex

因此,基本上我试图在我的网站中实现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());
    }
}