OneShopNotificationListener.cs

From Developer's API

(Difference between revisions)
(New page: <pre> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebContro...)
 
Line 20: Line 20:
 
         {
 
         {
 
             //TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter.
 
             //TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter.
             OneShopApi oneShopApiWrapper = new OneShopApi("", "", "https://www.mcssl.com");
+
             OneShopApi oneShopApiWrapper = new OneShopApi("118303", "0", "https://www.mcssl.com");
  
 
             System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
 
             System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();

Revision as of 19:58, 26 May 2008

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text.RegularExpressions;

public partial class SampleClients_OneShopNotificationListener : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //TODO: Add your Merchant ID as the First Parameter, and your Merchant Key as Second Parameter.
            OneShopApi oneShopApiWrapper = new OneShopApi("118303", "0", "https://www.mcssl.com");

            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
   
            string requestData = enc.GetString(Request.BinaryRead(Request.TotalBytes));
           
            XmlDocument requestBodyXML = new XmlDocument();

            //This Line remove the Byte-Order-Mark from the request as the LoadXML does not like data before the XML
            requestBodyXML.LoadXml(Regex.Replace(requestData, "^[^<]|(\\r\\n *)", ""));

            string notificationType = requestBodyXML.DocumentElement.Name;

            string Token = requestBodyXML.SelectSingleNode("/" + notificationType + "/Token").InnerText;

            XmlDocument apiResultXML= new XmlDocument();

            switch (notificationType)
            {
                case "NewOrder":
                   
                    apiResultXML.Load(oneShopApiWrapper.GetOrderById(Token));

                    break;
                default:
                    break;
            }

            //Check that the API returned success
            string apiSuccess = apiResultXML.SelectSingleNode("/Response").Attributes["success"].Value;

            if (apiSuccess == "true")
            {
                //TODO: Do something useful with the XML

                //TODO: Remove the following code
            }
            else
            {
                //TODO: Do something with the error returned by the API
            }
        }
        catch (Exception ex)
        {
            //TODO: Log or alert that an exception has occured
        }        
    }
}