OneShopNotificationListener.cs
From Developer's API
(Difference between revisions)
Line 19: | Line 19: | ||
try | try | ||
{ | { | ||
− | //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(" | + | OneShopApi oneShopApiWrapper = new OneShopApi("", "", "https://www.mcssl.com"); |
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
Line 28: | Line 28: | ||
XmlDocument requestBodyXML = new XmlDocument(); | XmlDocument requestBodyXML = new XmlDocument(); | ||
− | //This Line remove the Byte-Order-Mark from the request as the LoadXML does not like data before the XML | + | // 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 *)", "")); | requestBodyXML.LoadXml(Regex.Replace(requestData, "^[^<]|(\\r\\n *)", "")); | ||
Line 48: | Line 48: | ||
} | } | ||
− | //Check that the API returned success | + | // Check that the API returned success |
string apiSuccess = apiResultXML.SelectSingleNode("/Response").Attributes["success"].Value; | string apiSuccess = apiResultXML.SelectSingleNode("/Response").Attributes["success"].Value; | ||
if (apiSuccess == "true") | if (apiSuccess == "true") | ||
{ | { | ||
− | //TODO: Do something useful with the XML | + | // TODO: Do something useful with the XML |
− | + | ||
− | + | ||
} | } | ||
else | else | ||
{ | { | ||
− | //TODO: Do something with the error returned by the API | + | // TODO: Do something with the error returned by the API |
} | } | ||
} | } | ||
catch (Exception ex) | catch (Exception ex) | ||
{ | { | ||
− | //TODO: Log or alert that an exception has occured | + | // TODO: Log or alert that an exception has occured |
} | } | ||
} | } | ||
} | } | ||
</pre> | </pre> |
Revision as of 15:24, 27 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("", "", "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 } else { // TODO: Do something with the error returned by the API } } catch (Exception ex) { // TODO: Log or alert that an exception has occured } } }