'; // source displays XML tree - comment once in production // logTransaction("PaymentTech",$xmlRequest,"Information"); $ch=curl_init(); // curl_setopt($ch, CURLOPT_VERBOSE, 1); // comment once in production if (!curl_setopt($ch,CURLOPT_URL,GATEWAY_URL)) { echo 'CURLOPT URL Error
'; } if (!curl_setopt($ch,CURLOPT_HEADER,1)) { echo 'CURLOPT Header Error
'; } if (!curl_setopt($ch,CURLOPT_HTTPHEADER,array('POST /AUTHORIZE HTTP/1.0','MIME-Version: 1.0','Content-type: application/PTI21','Content-transfer-encoding: text','Request-number: 1','Document-type: Request'))) { echo 'CURLOPT HTTPHEADER Error
'; } if (!curl_setopt($ch,CURLOPT_POST,1)) { echo 'CURLOPT POST Error
'; } if (!curl_setopt($ch,CURLOPT_POSTFIELDS,$xmlRequest)) { echo 'CURLOPT POSTFIELDS Error
'; } if (!curl_setopt($ch,CURLOPT_TIMEOUT,90)) { echo 'CURLOPT TIMEOUT Error
';
}
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
// gives error, but keeps xml formatting
$result=curl_exec($ch);
if ($result === false) {
$result = "Curl Error: ".curl_errno($ch)." - ".curl_error($ch);
}
curl_close($ch);
// logTransaction("PaymentTech",$result,"Result Info");
$commonMandatoryXML = "Response/ACResponse/CommonDataResponse/CommonMandatoryResponse";
// minixml does not like the DOCTYPE -- simple_xml may be the way to go to retrieve the procStatus and approvalStatus
$result = str_replace('',"",$result);
$xmlDocResp=new MiniXMLDoc();
$xmlDocResp->fromString($result);
$procstatusEl = $xmlDocResp->getElementByPath($commonMandatoryXML.'/ProcStatus');
if( !is_object($procstatusEl) )
$procstatusEl = $xmlDocResp->getElementByPath('Response/QuickResponse/ProcStatus');
$procstatus = trim($procstatusEl->getValue());
if ($procstatus === '0')
{
$approvalstatusEl = $xmlDocResp->getElementByPath($commonMandatoryXML.'/ApprovalStatus');
if( is_object($approvalstatusEl) )
{
$approvalstatus = trim($approvalstatusEl->getValue());
if ($approvalstatus==='1')
{
$authCodeEl = $xmlDocResp->getElementByPath($commonMandatoryXML.'/ResponseCodes/AuthCode');
$authCode = trim($authCodeEl->getValue());
addInvoicePayment($params['invoiceid'],$authCode,"","","paymenttech","on");
logTransaction("PaymentTech",$result,"Successful [".$my_invoice_link."]");
sendMessage("Credit Card Payment Confirmation",$params['invoiceid']);
$result="success";
} elseif ($approvalstatus==='0') {
$declineCodeEl = $xmlDocResp->getElementByPath($commonMandatoryXML.'/StatusMsg');
if( is_object($declineCodeEl) )
$declineMSG = trim($declineCodeEl->getValue());
logTransaction("PaymentTech",$result,"Declined [".$my_invoice_link."]
".$declineMSG."");
sendMessage("Credit Card Payment Failed",$params['invoiceid']);
$result="declined";
} else {
logTransaction("PaymentTech",$result,"Error [".$my_invoice_link."]");
sendMessage("Credit Card Payment Failed",$params['invoiceid']);
$result="error";
}
return $result;
}
}
// ProcStatus == 521 on Prov/State format error
// some sort of failure... general or data format error
$statusEl = $xmlDocResp->getElementByPath('Response/ACResponse/CommonDataResponse/ApprovalStatus');
if( !is_object($statusEl) )
$statusEl = $xmlDocResp->getElementByPath('Response/QuickResponse/StatusMsg');
if( is_object($statusEl) ) {
logTransaction("PaymentTech",trim($statusEl->getValue()),"Failure [".$my_invoice_link."]");
} else {
logTransaction("PaymentTech",$result,"Failure");
}
sendMessage("Credit Card Payment Failed",$params['invoiceid']);
$result="failure";
return $result;
}
function strip_specialchars($val) {
return $val;
}
?>