Moneris Checkout - Preload request empty return

I'm trying to get the MOC preload request working in the development site, however the request returns no data. Below is a code snippet. Any help would be appreciated.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<!DOCTYPE html>
<html lang="en" xmlns="www.w3.org/.../xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

    <script src="gatewayt.moneris.com/.../script>  

    <script type="text/javascript">
         var myCheckout = new monerisCheckout();
         myCheckout.setMode("qa");
         myCheckout.setCheckoutDiv("monerisCheckout");

         myCheckout.setCallback("page_loaded", myPageLoad);
         myCheckout.setCallback("cancel_transaction", myCancelTransaction);
         myCheckout.setCallback("error_event", myErrorEvent);
         myCheckout.setCallback("payment_receipt", myPaymentReceipt);
         myCheckout.setCallback("payment_complete", myPaymentComplete);

 

         

         function PreLoad() {
             var xhr = new XMLHttpRequest();
             var url = "gatewayt.moneris.com/.../request.php";
             xhr.open("POST", url, true);
             xhr.setRequestHeader("Content-Type", "application/json");
             xhr.onreadystatechange = function () {
             if (xhr.readyState === 4 && xhr.status === 200) {
                  var json = JSON.parse(xhr.responseText);
                  monerisCheckout.startCheckout(json.response.ticket);
                  }

             };
             var data = JSON.stringify({ "store_id": "store1", "api_token": "yesguy1", "checkout_id": "chktF8FY7tore1", "txn_total": "123.00", "environment": "qa",                      "action": "preload", "order_no": "TestNum" });
             xhr.send(data);

           }

 

         function myPageLoad() {}

         function myCancelTransaction() {}

         function myErrorEvent() {}

         function myPaymentReceipt() {}

         function myPaymentComplete() {}

     </script> 

</head>

<body onload="PreLoad()">
       <form id="form1" runat="server">
          <div id="monerisCheckout"></div>
       </form>
</body>
</html>

  • Hi Jason did you figure out ? on my side it seem a cors policy ???
  • In reply to MultipleMedia:

    Hey,

    I've pretty much given up and have told my client it's probably best to switch credit card service providers.

    I just looked into cors and added what I think are the correct request headers for cors and I still get nothing.

    xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
    xhr.setRequestHeader("Access-Control-Allow-Origin", "http://mydomainname.ca");
    xhr.setRequestHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
    xhr.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
    xhr.setRequestHeader("Access-Control-Request-Headers", "X-Requested-With, accept, content-type");
  • In reply to JasonW:

    i just figure out yesterday :)

    First the documentation for the integration is not very clear and have plenty error:
    you call monerisCheckout.startCheckout(json.response.ticket); but its suppose to be:
    myCheckout.startCheckout(json.response.ticket);

    If you have a CORS problem, what you did is not correct cause its Moneris how block your request:(
    So to fix that problem you need to do a "curl", call your post in your back end. I program in net mvc so this is what i did:

    // Json object
    var data = {
    "store_id": "monca05309",
    "api_token": "VrzdiRbTAmK4gB5KrqAl",
    "checkout_id": "chktZLHAL05309",
    "txn_total": "452.00",
    "environment": "qa",
    "action": "preload",
    "order_no": "",
    "cust_id": "chkt - cust - 0303",
    "dynamic_descriptor": "dyndesc",
    "language": "en",
    "cart": {
    "items": [
    {
    "url": "https:\/\/example.com\/examples\/item1.jpg",
    "description": "One item",
    "product_code": "one_item",
    "unit_cost": "100.00",
    "quantity": "1"
    },
    {
    "url": "https:\/\/example.com\/examples\/item2.jpg",
    "description": "Two item",
    "product_code": "two_item",
    "unit_cost": "200.00",
    "quantity": "1"
    },
    {
    "url": "https:\/\/example.com\/examples\/item3.jpg",
    "description": "Three item",
    "product_code": "three_item",
    "unit_cost": "100.00",
    "quantity": "1"
    }
    ],
    "subtotal": "400.00",
    "tax": {
    "amount": "52.00",
    "description": "Taxes",
    "rate": "13.00"
    }
    },
    "contact_details": {
    "first_name": "bill",
    "last_name": "smith",
    "email": "test@moneris.com",
    "phone": "4165551234"
    },
    "billing_details": {
    "address_1": "1 main st",
    "address_2": "Unit 2000",
    "city": "Toronto",
    "province": "ON",
    "country": "CA",
    "postal_code": "M1M1M1"
    }
    }

    var jsonData = {
    jsonData: JSON.stringify(data),
    };

    // my example, i have a button who trigger the post
    // my url is my route to call my fonction in my controller
    $("#monerisBtn").click(function () {
    $.ajax({
    type: "POST",
    url: "/moneris/preload",
    dataType: 'json',
    data: jsonData,
    success: function (result) {
    var json = JSON.parse(result);
    console.log(json.response);
    console.log(json.response.ticket);
    myCheckout.startCheckout(json.response.ticket);
    },
    error: function (status) {
    console.log(status);
    }
    });
    })


    //MVC controller
    [HttpPost]
    public JsonResult Preload(string jsonData)
    {
    var httpWebRequest = (HttpWebRequest)WebRequest.Create("gatewayt.moneris.com/.../request.php");
    httpWebRequest.ContentType = "application/json";
    httpWebRequest.Method = "POST";

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
    streamWriter.Write(jsonData);
    }

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
    var result = streamReader.ReadToEnd();
    return Json(result, JsonRequestBehavior.AllowGet);
    }
    }
  • In reply to MultipleMedia:

    Thanks for that code snippet!

    I'm working in vb.net so I'll see if I can translate it over.
  • In reply to JasonW:

    If you need help for something else like maybe the callback, let me know, im almost finish with the testing integration.