I'm fairly novice with PHP, but I can usually figure things out. But I'm stuck on working around this legacy code that we use on our sales form.
I have to shoehorn in another Card processing merchant that does things a little differently with their API.
This is processing the response from a cURL API where I receive a SOAP XML response. I'm having some issues with the actual response as well, so I have it sampled in what appears to be a proper xml format, then attempting to parse out the message objects.
The process:
1. I have the response XML converting into a "SimpleXMLElement" with the simplexml_load_string
2. Then the XML is "converted to an array", I think, with the $array = (array)$xml;
3. Then, the code should be able to look into the array values and process a Success or Failed based on the Status Value
4. Then the $data is json encoded and is passed to the JavaScript file for further processing of the notification and filling in the Auth code field of the sales form.
The Problem(s):
1. You'll see in the PHP code that I have 2 testing sections to process the response. The first uses the $array and the second skips the array and just uses the $xml. One is commented out for testing the other, of course.
2. When using the $xml section to get the values, I get real close to what I need until it get json encoded, then the output just says Object Object in the JS Alert. It appears that the code is finding the proper value of the key, but it's not handled the same way for the json encoding in order to get a good alert.
3. When using the array process, I don't get anything but a full failure to extract the values, so it rolls to the end else statement "$data = array( 'message' => $xml->transaction->description, 'html' => 'Failed, Not seeing Success or TransactionID', 'date' => $curdate->format('m/d/Y h:i:s a') );"
What I really need help with is:
What is the proper way to use the array process to grab that Status value? is it $array->status == "Success" or do I need to go deeper?
I'm hoping that then I will get the proper json encoding to pass on.
Thank you for your time!
Here is what the SimpleXMLElement produces:
SimpleXMLElement Object( [transaction] => SimpleXMLElement Object ( [status] => Success [reasoncode] => N/A [transactionid] => J7DXXXX8U0 [description] => The credit card has been accepted. ))
Thank you for the awesome response. I will attempt the changes over the weekend and let you know how it turns out.
Thank you, thank you!
Chris Inman
ASKER
Chris,
Phenomenal response as I actually was able to understand it as you explained and walked through it, even at my novice level.
Getting rid of the array conversion altogether was great and converting the xml data to string worked like a charm for the json.
With some other minor tweaks, I have this bad boy running pretty good now.
I still have a minor issue with the vendors end, but that is on them to fix.
Many Thanks to you Sir!
~Chris
Chris Stanyon
No worries Chris,
Pleased you got it working, but more importantly, I'm pleased you know why you got it working.
Thank you, thank you!