OneShopNotificationListener.asp

From Developer's API

<!-- #INCLUDE file="../Library/OneShopAPI.asp" -->
<%
	set requestBodyXML = createObject("MSXML2.DOMDocument.4.0")
	set apiResultXML = createObject("MSXML2.DOMDocument.4.0")
	
	dim result
	dim notificationType
	dim token 		
	
	' Create instance of OneShopAPI which acts as a wrapper to the API		
	Set oneShopApiWrapper = new OneShopApi									
	
	' TODO: Add your merchant id	
	oneShopApiWrapper.MerchantID = ""
	' TODO: Add to your merchant api key								
	oneShopApiWrapper.MerchantKey = "" 								
	oneShopApiWrapper.ApiUrl = "https://www.mcssl.com"					

	' Load the request body into XML
	requestBodyXML.load(request.binaryread(request.TotalBytes))			
	
	' Check that the xml was loaded correctly
	if (requestBodyXML.parseError.errorCode = 0) then
		
		' Extract the type of notification is being sent				
		notificationType = requestBodyXML.documentElement.nodeName	
											
		' Extract the token from the request 
		token = requestBodyXML.SelectSingleNode(notificationType & "/Token").text
			
		' Get data from the API depending on what notification type was sent
		select case notificationType
			case "NewOrder"	
					
				result = oneShopApiWrapper.GetOrderById(token)
			case else
				' May have other types of notifications in the future
		end select
		
		' Load the result from the API into XML
		apiResultXML.Load(result)
		
		' Check that the result has been parsed into XML
		if (apiResultXML.parseError.errorCode = 0) then
			
			' Get the success attribute of the result
			apiSuccess = apiResultXML.selectSingleNode("/Response").getAttribute("success")
						
			' Check if the API returned an error
			if apiSuccess = "true" then
				' TODO: Do something with the apiResultXML			
			else
				' TODO: Do something with the error returned by the API
			end if
		else							
			' TODO: Do something with the xmlErr to either notify or log that the XML could not be parsed		
		end if						
	else	 			
		' TODO: Do something with the xml Error to either notify or log that the XML could not be parsed				
	end if	
%>