So I’m setting up DPS for someone and I’ve got a little error in my xml_parse. I’m using the sample code from DPS (http://www.paymentexpress.com/Technical_Resources/Sample_code_-_PHP/PX_Post_-_cURL.aspx) and I’ve modified it to work with PxPay. My problem is it’s spitting back an error and I don’t know what the code is doing so not sure what’s going wrong
This is my code
function parse_xml($data){
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}
}
and I’m getting an “Undefined offset: 1” error on this line
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
as far as I know all it’s spitting back to me is something like the following
<Request valid="1">
<URI>https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Samplepxpayuser&request=v5x4Ygc8SJlc3FLYva7pIp6QHqKiSatHN8sNMufz-NNrOGJXn0TJf5TOIVNwQRyNqPo9cPMUfXWJkxjAGGDGDzhkwFD6VxRD2KesUBcmD5ViwVnb4va16zLih9VmKlipvEelGaYsF3fCqudnaWV1abz6f8VNKJOhGeypImjWk9I9xV0-iZh860FPcOam_UVHe81aQ4C2LJKB_znLiWqALSeeOHskI9vxdPOfcsfO7xXOuSMVXsKK6kVX4eZjcODKS1JGKP97fhb4gI2vpR7KUwIGC7U9VkXkPQfAGyYuP1g8x0QR1kC6eNzov3-W48OyvQ1_Fabn8cc1deTrsk6s3bPj3dgrlcXUfnFvmSOemB4rs-ixPDwQcaEsZWQvUcIsaPXAWfQdgtC0dETayY_wVFN8yVmljpCZweiGyNhUHhYGIWLEGuP_Le1HwyHXc_fMaQOeqdZNrFBviCJyWZ2HKferSEwkyQqMmq</URI>
</Request>
Does anyone have any experience with DPS or know what may be going wrong here?
I am getting the result back but it’s still spitting me this error in my error reports
EDIT
This is no longer needed. This code is now obsolete
replace
eval($php_stmt);withif (isset($xml_elem['value'])) { eval($php_stmt); }