OneShopNotificationListener.asp

From Developer's API

Revision as of 19:33, 26 May 2008 by Chrisn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
<!-- #INCLUDE file="../Library/OneShopAPI.asp" -->
<%
set requestBodyXML = createObject("MSXML2.DOMDocument.4.0")
set apiResultXML = createObject("MSXML2.DOMDocument.4.0")

dim xmlErr
dim result
dim notificationType
dim token 		
		
Set oneShopApiWrapper = new OneShopApi								'Create instance of OneShopAPI which acts as a wrapper to the API	
	
oneShopApiWrapper.MerchantID = "80086"								'TODO: Add your merchant id
oneShopApiWrapper.MerchantKey = "dfd9e90384e842d18c4ef74ed08a4673" 								'TODO: Add to your merchant api key
oneShopApiWrapper.ApiUrl = "http://localhost"					

'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 xmlErr to either notify or log that the XML could not be parsed				
end if

%>