WAIT WINDOW 'PROCESANDO'NOWAIT
loConexionCobroPre = CREATEOBJECT( "Microsoft.XMLHTTP" )

cobroPre = 'http://52.24.48.246:7575/emswitch/services/cobro/pre'
cobroConfirm = 'http://52.24.48.246:7575/emswitch/services/cobro/confirm'
loTransactionId = '60002'

datosCobroPre = '<cobroPreParams>'+;
				'<amount>0.01</amount>'+;
				'<dateTime>2015-08-25T10:00:00</dateTime>'+;
				'<document>110420956</document>'+;
				'<host>localhost</host>'+;
				'<language>ES</language>'+;
				'<source>0999523429</source>'+;
				'<transactionId>' + loTransactionId + '</transactionId>'+;
				'<zoneId>America/Guayaquil</zoneId>'+;
				'</cobroPreParams>'
				
&& configuraci[on
username = 'olesys'
lpassword = 'olesys'
auth = Strconv(username + ":" + lpassword, 13)

&& MSXML2.XMLHTTP.3.0 : https://msdn.microsoft.com/en-us/library/ms535874%28v=vs.85%29.aspx

&& Cobro pre (solicitud)

loConexionCobroPre.open("POST", cobroPre, .F.)
loConexionCobroPre.setRequestHeader("Content-Type", "application/xml")
loConexionCobroPre.setRequestHeader("Accept", "application/xml")
loConexionCobroPre.setRequestHeader("Authorization", "Basic " + auth)

&& Envío:
loConexionCobroPre.send(datosCobroPre)

&& Respuesta:

&& Status 200: OK, 401: Problemas de autenticación
loStatus = loConexionCobroPre.status
&& XML de respuesta:
loResponse = loConexionCobroPre.responseText
?STR(loStatus) + loResponse

&& Va a cambiar a 201
IF loStatus = 200
	
	oXML = CREATEOBJECT('MSXML2.DomDocument')
	oXML.ASYNC = .F.
	oXml.loadXML(loResponse)		
	oRootNode 	= oXML.documentElement
	
	oNodeList = oRootNode.getElementsByTagName("result")
	oNode = oNodeList.ITEM(0)
	loResult	= oNode.firstChild.nodeValue
	
	oNodeList = oRootNode.getElementsByTagName("errorCodeId")
	oNode = oNodeList.ITEM(0)
	loErrorCodeId	= oNode.firstChild.nodeValue
	
	&& 1: ok, 2: error
	
	IF loResult = '1'
		oNodeList	= oRootNode.getElementsByTagName("sessionId")
		oNode 		= oNodeList.ITEM(0)
		loSessionId	= oNode.firstChild.nodeValue
		
		loCobroConfirm = '<cobroConfirmParams>'+;
					 '<dateTime>2015-08-25T10:00:00</dateTime>'+;
					 '<host>localhost</host>'+;
					 '<sessionId>' + loSessionId + '</sessionId>'+;
				     '<zoneId>America/Guayaquil</zoneId>'+;
	                 '</cobroConfirmParams>'	                 

		&& Cobro confirm (consultar si ya confirmó el cliente)

		loConexionCobroConfirm = CREATEOBJECT( "Microsoft.XMLHTTP" )

		loConexionCobroConfirm.open("POST", cobroConfirm, .F.)
		loConexionCobroConfirm.setRequestHeader("Content-Type", "application/xml")
		loConexionCobroConfirm.setRequestHeader("Accept", "application/xml")
		loConexionCobroConfirm.setRequestHeader("Authorization", "Basic " + auth)
		
		loConexionCobroConfirm.send(loCobroConfirm)
		loStatus = loConexionCobroConfirm.status
		loResponse = loConexionCobroConfirm.responseText
		
		? 'Status ' + STR(loStatus)
		? 'Resultado cobroConfirm: ' + loResponse		
		
	ELSE 
		MESSAGEBOX("Resultado " + loResult + "; errorCodeId " + loErrorCodeId)
	ENDIF	

ELSE 
	
	MESSAGEBOX('Error ' + STR(loStatus))

endif



