1

我正在使用asp.net mvc 42Checkout制作一个在线交易系统。我正在使用 2Checkout 沙盒帐户来测试系统并按照他们的教程进行测试。出于某种原因,我收到了这个错误,

值不能为空。参数名称:s

这是我的代码,

控制器

    public ActionResult CheckOut()
    {
        return View();
    }

    [ValidateAntiForgeryToken]
    [HttpPost]
    public ActionResult Process()
    {
        TwoCheckoutConfig.SellerID = "901299852";
        TwoCheckoutConfig.PrivateKey = "9E1A8B89-2A90-40D7-A7F5-CBF252B3B4A0";
        TwoCheckoutConfig.Sandbox = true;

        try
        {
            var Billing = new AuthBillingAddress();
            Billing.addrLine1 = "123 test st";
            Billing.city = "Columbus";
            Billing.zipCode = "43123";
            Billing.state = "OH";
            Billing.country = "USA";
            Billing.name = "Testing Tester";
            Billing.email = "example@2co.com";
            Billing.phoneNumber = "5555555555";
            Billing.phoneExt = "555";

            var Customer = new ChargeAuthorizeServiceOptions();
            Customer.total = (decimal)1.00;
            Customer.currency = "USD";
            Customer.merchantOrderId = "123";
            Customer.billingAddr = Billing;
            Customer.token = Request["token"];

            var Charge = new ChargeService();

            var result = Charge.Authorize(Customer);  // Error getting in this line
            ViewBag.Message = result.responseMsg;
        }
        catch (TwoCheckoutException e)
        {
            ViewBag.Message = e.Message.ToString();
        }

        return View();
    }

查看(结帐)

<div class="container well">
    @using (Html.BeginForm("Process", "Home", FormMethod.Post, new { id = "myCCForm" }))
    {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "Error! Please provide valid information!")

    <input id="token" name="token" type="hidden" value="">
    <div>
        <label>
            <span>Card Number</span>
        </label>
        <input id="ccNo" type="text" size="20" value="" autocomplete="off" required />
    </div>
    <div>
        <label>
            <span>Expiration Date (MM/YYYY)</span>
        </label>
        <input type="text" size="2" id="expMonth" required />
        <span>/ </span>
        <input type="text" size="2" id="expYear" required />
    </div>
    <div>
        <label>
            <span>CVC</span>
        </label>
        <input id="cvv" size="4" type="text" value="" autocomplete="off" required />
    </div>
    <input type="submit" value="Submit Payment">
}
</div>

<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="https://www.2checkout.com/checkout/api/2co.min.js"></script>

<script>
    // 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) {tokenRequest();} else {alert(data.errorMsg);}
    };

    var tokenRequest = function() {
        // Setup token request arguments
        var args = {
            sellerId: "901299852",
            publishableKey: "F4AA3A98-B605-423E-ACAC-D70BCB50A7F7",
            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>

查看(过程)

<div class="container well">
    <h3 class="text-center">@ViewBag.Message</h3>
</div>

任何人都知道为什么我会收到此错误?我该如何解决?非常需要这个帮助!谢谢。

4

3 回答 3

2

有同样的问题。您只需要删除 Nuget 包并从 2checkout Github下载 dll 。就是这样——一切都会奏效。不知何故,Nuget 包已经过时了。

于 2016-04-24T18:38:25.463 回答
0

我也面临同样的问题。

我刚刚创建了新项目并在新项目中编写了相同的代码。现在一切正常。

于 2018-06-12T12:00:27.087 回答
0

请检查堆栈转储,这通常发生在 System.IO.StringReader..ctor(String s) 期望一个非空字符串但被作为空值传递时。您还应该检查源文件的权限,以确保 .Net 进程可以访问这些文件。读取权限应该足够了。

于 2015-12-18T18:24:57.533 回答