troubleshooting Question

Troubles with XML parsing script. Saves like successful but wasn't...???

Avatar of Andrew Angell
Andrew AngellFlag for United States of America asked on
ASP
2 Comments1 Solution432 ViewsLast Modified:
I was getting the following XML response from PayPal's API because I was sending the card type field as Mastercard instead of MasterCard (capital C).  

 <?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
 <SOAP-ENV:Header>
  <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType" />
 <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
 <Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
  <Username xsi:type="xs:string">API_USERNAME</Username>
  <Password xsi:type="xs:string">API_PASSWORD</Password>
  </Credentials>
  </RequesterCredentials>
  </SOAP-ENV:Header>
 <SOAP-ENV:Body id="_0">
 <SOAP-ENV:Fault>
  <faultcode>SOAP-ENV:Client</faultcode>
  <faultstring>Data type '' mismatch in element 'CreditCardType'</faultstring>
  </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>

My script simply looks at the XML response given, parses out the value of <Ack> (which is normally present) and then if Ack = Successful saves it to a successful folder and if not it saves the response to a failed folder.  Here is the part that is suppose to take care of this.  This chunk is the what posts the request and handles the response.

'POST the XML to the PayPal API and store the response
      Set objXMLDOC = Server.CreateObject("Msxml2.ServerXMLHTTP")

      objXMLDOC.setOption 3, "LOCAL_MACHINE\MY\" &PayPalAPIUsername
      objXMLDOC.SetOption 2, 13056
      objXMLDOC.setTimeouts 30 * 300, 30 * 300, 30 * 300, 30 * 300

      objXMLDOC.open "POST", ""&PayPalAPIURL&"", False
      objXMLDOC.setRequestHeader "Content-Type", "text/xml"
      objXMLDOC.send (soapXML)

      xmlResponse = objXMLDOC.responseText

      Set objXMLDOC = Nothing
      
'open the XML document
      Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
      xmlDoc.Async = false
      xmlDoc.Load(xmlResponse)
      
'Check the status of the response
'Forward sucessful transactions to the receipt page
'Display errors if a problem occured.      
      Set Ack = xmlDoc.selectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/DoDirectPaymentResponse")
            For Each node In Ack
                  AckStatus = node.selectSingleNode("Ack").text
            Next
      Set Ack = Nothing
      
      If AckStatus = Success Then
      
            'Store the returned transaction information in session variables
            Set AVSCode = xmlDoc.selectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/DoDirectPaymentResponse")
                  For Each node In AVSCode
                        Session("AVSCode") = node.selectSingleNode("AVSCode").text
                  Next
            Set AVSCode = Nothing
            
            Set CVV2Code = xmlDoc.selectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/DoDirectPaymentResponse")
                  For Each node In CVV2Code
                        Session("CVV2Code") = node.selectSingleNode("CVV2Code").text
                  Next
            Set CVV2Code = Nothing
            
            Set TransactionID = xmlDoc.selectNodes("/SOAP-ENV:Envelope/SOAP-ENV:Body/DoDirectPaymentResponse")
                  For Each node In TransactionID
                        Session("PayPalTransactionID") = node.selectSingleNode("TransactionID").text
                  Next
            Set TransactionID = Nothing
            
            'Save a copy of the successful response XML to disk
          'appending the same time as the request got.
            set fs=Server.CreateObject("Scripting.FileSystemObject")
            filename = (server.MapPath("xml\response\successful\DoDirectPaymentResponse"&sysTime&".xml"))
            set tfile=fs.CreateTextFile(filename)
            tfile.WriteLine(xmlResponse)
            tfile.close
            set tfile=nothing
            set fs=nothing
            
            response.Redirect("directPaymentComplete.asp")
      Else
            'Save a copy of the failed response XML to disk
          'appending the same time as the request got.
            set fs=Server.CreateObject("Scripting.FileSystemObject")
            filename = (server.MapPath("xml\response\failed\DoDirectPaymentResponse"&sysTime&".xml"))
            set tfile=fs.CreateTextFile(filename)
            tfile.WriteLine(xmlResponse)
            tfile.close
            set tfile=nothing
            set fs=nothing
            
            Response.Write("I'm sorry, there was a problem with your transaction.  Your card has NOT been charged.  Please call 866-592-8169 to proceed.")
      End If
      
'Close out the XMLDom object
Set xmlDoc = Nothing

As you can see, the response I actually got because of the problem didn't even contain the normal elements, and Ack does not even exist.  Thing is, when I ran through this I ended up at my directPaymentReceipt.asp page which is only suppose to be redirected to upon Ack = Successful.  Also, the XML was saved into the successful folder.

Why does the If/Then think Ack = Succcessful when Ack doesn't even exist?  What do I need to do to fix this?  Any information would be greatly appreciated.  Thanks!

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros