Monday, March 17, 2014

C# - Access Moneris Payment Gateway in Local Environment – Part 1

Testing payment related functionalities are more critical developing systems which enables payment through the payment gateway. In Canada, one of the famous online payment gateway is "Moneris". Following article shows how to configure Moneris payment gateway to test payment functionalities in local development environment.

Following URL navigates the Moneris website which can use to configure store for testing purposes.

https://esqa.moneris.com/mpg/

Following screen shows login screen for their Testing site

Moneris Login Page
Then navigates to Admin -> “hosted config” section (see following screen)

Moneris Hosted Config Page

Then generate new configuration. When entering Approved and Decline URLs Moneris does not allowed you to add localhost or any IP address. Due to that reason we need to put valid address. However to overcome that issue we can add host entry to local development machine (add new host entry in host file located in “C:\Windows\System32\drivers\etc”) and use that host address as an address of web site. For the demonstration use address - http://localdev.payment/.


User can configured three different pages as an approved return page, Cancel return page and decline page. Based on the requirement it can configure response as a POST or GET or POST with XML. If you enable the "Use enhance Cancel" you can filter-out the cancel response and decline response separately without using two different pages for cancel and decline.  There are several key fields we need to extract from the Moneris response. Following list shows some of required fields and values. For more details please visit Moneris (http://www.moneris.com/)


Configuration Fields

Create request for payment gateway


To create payment request need to send set of required fields to the payment gateway. Following code snippet shows how to create payment request for Moneris payment gateway. Following knowledge base provide relevant request fields and response fields

http://docs.abvma.ca/documents/eSELECTplusHPPIG/eSELECTplusHPPIG.pdf

  protected void Page_Load(object sender, EventArgs e)

        {

            ClientScript.RegisterHiddenField("ps_store_id", "MB5YEtore3");

            ClientScript.RegisterHiddenField("hpp_key", "hpL9K5APKH49");

            ClientScript.RegisterHiddenField("order_id", "ord000001");

            ClientScript.RegisterHiddenField("charge_total", "100.00");



            btnSubmitPayment.PostBackUrl = "https://esqa.moneris.com/HPPDP/index.php";

        }


Following code snippet shows how get response from Moneris and extract.

    protected void Page_Load(object sender, EventArgs e)

        {

            lblResponseOrderIdValue.Text = Request.Form["response_order_id"];

            lblReseponseCodeValue.Text = Request.Form["response_code"];

            lblDateStampValue.Text = Request.Form["date_stamp"];

            lblTimeStampValue.Text = Request.Form["time_stamp"];

            lblBankApprovalCodeValue.Text = Request.Form["bank_approval_code"];

            lblResultValue.Text = Request.Form["result"];

            lblTotalAmountValue.Text = Request.Form["charge_total"];

        }



Following screen captures shows payment request and sample payment response


Payment Request

Moneris Payment Gateway - Test Details

Cancel Payment Response

Decline Payment Response