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
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="" xmlns:SOAP-ENC="" xmlns:xsi="" xmlns:xsd="" xmlns:xs="" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="" xmlns:wsse="" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
  <Security xmlns="" 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>
 <SOAP-ENV:Body id="_0">
  <faultstring>Data type '' mismatch in element 'CreditCardType'</faultstring>

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 "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
'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
      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
            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
            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
            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)
            set tfile=nothing
            set fs=nothing
            '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)
            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