OneShopNotificationListener.cfm
From Developer's API
(Difference between revisions)
Chrisn (Talk | contribs)
(New page: <pre> <cftry> <cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> <cfset #oneShopApiWrapper.MerchantID("80086")# > <cfset #oneShopApiWrapper.MerchantKey("dfd9e...)
Newer edit →
(New page: <pre> <cftry> <cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> <cfset #oneShopApiWrapper.MerchantID("80086")# > <cfset #oneShopApiWrapper.MerchantKey("dfd9e...)
Newer edit →
Revision as of 19:46, 26 May 2008
<cftry> <cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> <cfset #oneShopApiWrapper.MerchantID("80086")# > <cfset #oneShopApiWrapper.MerchantKey("dfd9e90384e842d18c4ef74ed08a4673")# > <cfset #oneShopApiWrapper.ApiUri("http://localhost")#> <cfset requestBody = GetHttpRequestData()> <cfset requestData = ToString(requestBody.content)> <!--- Use REReplace to remove Byte-Order-Mark from XML the xmlParse method does not like this mark ---> <cfset requestBodyXML = xmlParse(REReplace(requestData,"^[^<]*", "", "all"))> <!--- cfset requestBodyXML = xmlParse("<NewOrder><Token>ea7fa6fa0156473281018d81edf5723e</Token></NewOrder>")---> <cfset notificationType = requestBodyXML.XMLRoot.XMLName> <cfset tokenNode = xmlSearch(requestBodyXML, "/" & notificationType & "/Token")> <cfset token = tokenNode[1].xmlText> <cfswitch expression="#notificationType#"> <cfcase value="NewOrder"> <cfset result = #OneShopApiWrapper.GetOrderById(token)# /> </cfcase> <cfdefaultcase> <!--- May have other types of notifications in the future ---> </cfdefaultcase> </cfswitch> <!--- Load the result into XML ---> <cfset apiResultXML = xmlParse(#result#) /> <cfset apiSuccess = apiResultXML.Response.XmlAttributes["success"] > <!--- Check if the API returned an error ---> <cfif apiSuccess IS "true"> <!---TODO: Do something with the apiResultXML---> <cfelse> <!---TODO: Do something with the error returned by the API ---> </cfif> <cfcatch> <!---TODO: Do something with the exception ---> </cfcatch> </cftry>