OneShopNotificationListener.cfm
From Developer's API
(Difference between revisions)
Line 3: | Line 3: | ||
<cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> | <cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> | ||
− | <!--- TODO: Add your merchant Id ---> | + | <!--- TODO: Add your merchant Id ---> |
− | <cfset #oneShopApiWrapper. | + | <cfset #oneShopApiWrapper.MerchantID("")# > |
<!--- TODO: Add your merchant Key ---> | <!--- TODO: Add your merchant Key ---> | ||
<cfset #oneShopApiWrapper.MerchantKey("")# > | <cfset #oneShopApiWrapper.MerchantKey("")# > | ||
− | <cfset #oneShopApiWrapper.ApiUri(" | + | <cfset #oneShopApiWrapper.ApiUri("http://localhost")#> |
<cfset requestBody = GetHttpRequestData()> | <cfset requestBody = GetHttpRequestData()> | ||
Line 14: | Line 14: | ||
<!--- Use REReplace to remove Byte-Order-Mark from XML the xmlParse method does not like this mark ---> | <!--- 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(REReplace(requestData,"^[^<]*", "", "all"))> | ||
− | + | ||
− | + | ||
− | + | ||
<cfset notificationType = requestBodyXML.XMLRoot.XMLName> | <cfset notificationType = requestBodyXML.XMLRoot.XMLName> | ||
Line 40: | Line 38: | ||
<!--- Check if the API returned an error ---> | <!--- Check if the API returned an error ---> | ||
<cfif apiSuccess IS "true"> | <cfif apiSuccess IS "true"> | ||
− | <!---TODO: Do something with the apiResultXML---> | + | <!---TODO: Do something with the apiResultXML---> |
− | + | ||
<cfelse> | <cfelse> | ||
− | <!--- TODO: Do something with the error returned by the API ---> | + | <!---TODO: Do something with the error returned by the API ---> |
</cfif> | </cfif> | ||
<cfcatch> | <cfcatch> | ||
− | <!--- TODO: Do something with the exception ---> | + | <!---TODO: Do something with the exception ---> |
</cfcatch> | </cfcatch> | ||
</cftry> | </cftry> | ||
</pre> | </pre> |
Latest revision as of 14:01, 29 May 2008
<cftry> <cfset oneShopApiWrapper = createObject("component", "OneShopAPI").init() /> <!--- TODO: Add your merchant Id ---> <cfset #oneShopApiWrapper.MerchantID("")# > <!--- TODO: Add your merchant Key ---> <cfset #oneShopApiWrapper.MerchantKey("")# > <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 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>