1

I'm using asp.net mvc 4 and 2Checkout to make an online transaction system. I'm using 2Checkout sandbox account to test the system and following their tutorial for testing. For some reason, I'm getting this error,

Value cannot be null. Parameter name: s

Here are my codes,

Controller

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

View (CheckOut)

<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>

View (Process)

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

Anyone knows why I'm getting this error? How can I resolve it? Need this help badly! Thanks.

Shihan Khan
  • 2,180
  • 4
  • 34
  • 67
  • is you checked value of Request["token"] ? –  Dec 03 '15 at 06:58
  • Just checked at your advice. I get null for token. – Shihan Khan Dec 03 '15 at 07:05
  • Sorry my bad, I get token value. – Shihan Khan Dec 03 '15 at 07:06
  • can you please post Billing class and Customer Class ? –  Dec 03 '15 at 11:31
  • Please check the link of the tutorial I've provided. I just followed that link. The classes you mentioned comes from the assembly `TwoCheckout`. There's no definition given separately for those functions. – Shihan Khan Dec 03 '15 at 11:46
  • i found that " Customer.billingAddr = Billing;" is incorrect.... you have to pass array or list of Billing not object of Billing. –  Dec 04 '15 at 07:32
  • can you please tell, how to pass array of billing instead of object (format), I am facing same issue but not found any solution – Muhammad Ali Hassan Jan 02 '16 at 15:23
  • I'm using their standard checkout instead of api. I still didn't found a solution. – Shihan Khan Jan 02 '16 at 17:02
  • @PranavPatel Hi Dear, As you say to pass array or list of Billing to customer class, it will be invalid. Customer class will not accept array or list of billing class. I'm facing same issue. If anyone has solution then help me please. – dilipkumar1007 May 02 '16 at 05:55

3 Answers3

2

Had the same problem. All you need is to delete Nuget package and download dll from 2checkout Github. That's all - everything will work. Somehow Nuget package is obsolete.

EugeneK
  • 75
  • 7
0

Please check the stack dump, typically this happens when System.IO.StringReader..ctor(String s) is expecting a non-null string but instead is being passed as null. You should also check the permissions on the source files to ensure the .Net process has access to the files. Read access should be sufficient.

wtrmLn
  • 121
  • 1
  • 2
0

i also faced the same problem.

i just created new project and written the same code in new project. and everything working fine now.

Ramesh
  • 11
  • 2
  • This isn't an answer. Please read [How to answer](https://stackoverflow.com/help/how-to-answer) – Hintham Jun 12 '18 at 12:26