'; return $code; } function paymenttech_capture($params) { // if( $params['currency'] === 'USD' ) // $my_merchantid = $params['merchantidUSD']; // else $my_merchantid = $params['merchantid']; $my_invoice_description = $params['invoiceid']; $my_invoice_link = "" . $params['invoiceid'] . ""; $passed_amount = number_format($params['amount'],2,'.',''); $my_totalamount = str_replace(".","",$passed_amount); // no decimal in passed amount $my_card_number = $params['cardnum']; $my_card_exp_month = $params['cardexp']; $my_cc_verify = $params['cccvv']; $my_card_name = $params['clientdetails']['firstname'].' '.$params['clientdetails']['lastname']; $my_address = $params['clientdetails']['address1']; $my_city = $params['clientdetails']['city']; $my_state = $params['clientdetails']['state']; $my_postcode = $params['clientdetails']['postcode']; require_once (ROOTDIR.'/minixml.inc.php'); $my_date=date('HismdY'); if ($params['testmode']) { $gateway_url = 'https://epayhipvar.paymentech.net/authorize'; } else { $gateway_url = 'https://epayhip.paymentech.net/authorize'; } define("GATEWAY_URL",$gateway_url); $xmlDoc=new MiniXMLDoc(); $xmlRoot=&$xmlDoc->getRoot(); $Request=&$xmlRoot->createChild('Request'); $AC=&$Request->createChild('AC'); $CommonData=&$AC->createChild('CommonData'); $CommonMandatory=&$CommonData->createChild('CommonMandatory'); $CommonMandatory->attribute('HcsTcsInd','T'); $CommonMandatory->attribute('MessageType','AC'); $CommonMandatory->attribute('LangInd','00'); $CommonMandatory->attribute('TzCode','706'); $CommonMandatory->attribute('AuthOverrideInd','N'); $CommonMandatory->attribute('Version','2'); $CommonMandatory->attribute('TxCatg','7'); $CommonMandatory->attribute('CardHolderAttendanceInd','01'); $AccountNum=&$CommonMandatory->createChild('AccountNum'); $AccountNum->attribute('AccountTypeInd','91'); $AccountNum->text($my_card_number); // $my_card_number $POSDetails=&$CommonMandatory->createChild('POSDetails'); $POSDetails->attribute('POSEntryMode','01'); $MerchantID=&$CommonMandatory->createChild('MerchantID'); $MerchantID->text($my_merchantid); $TerminalID=&$CommonMandatory->createChild('TerminalID'); $TerminalID->attribute('POSConditionCode','59'); $TerminalID->attribute('CardPresentInd','N'); $TerminalID->attribute('AttendedTermDataInd','01'); $TerminalID->attribute('TermLocInd','01'); $TerminalID->attribute('CATInfoInd','06'); $TerminalID->attribute('TermEntCapInd','05'); $TerminalID->text('001'); $BIN=&$CommonMandatory->createChild('BIN'); $BIN->text('000002'); $OrderID=&$CommonMandatory->createChild('OrderID'); $OrderID->text($my_invoice_description); // $my_invoice_description $AmountDetails=&$CommonMandatory->createChild('AmountDetails'); $Amount=&$AmountDetails->createChild('Amount'); $Amount->text($my_totalamount); // $my_totalamount $TxTypeCommon=&$CommonMandatory->createChild('TxTypeCommon'); $TxTypeCommon->attribute('TxTypeID','G'); $Currency=&$CommonMandatory->createChild('Currency'); // if( $params['currency'] === 'USD' ) // { // 840 = USD; 124 = CAD // $Currency->attribute('CurrencyCode','840'); // } // else // { // Default is: 124 = CAD $Currency->attribute('CurrencyCode','124'); // } $Currency->attribute('CurrencyExponent','2'); $CardPresence=&$CommonMandatory->createChild('CardPresence'); $CardNP=&$CardPresence->createChild('CardNP'); $Exp=&$CardNP->createChild('Exp'); $Exp->text($my_card_exp_month.$my_card_exp_year); $TxDateTime=&$CommonMandatory->createChild('TxDateTime'); $TxDateTime->text($my_date); $CommonOptional=&$CommonData->createChild('CommonOptional'); $CardSecVal=&$CommonOptional->createChild('CardSecVal'); $CardSecVal->text($my_cc_verify); // $my_cc_verify $ECommerceData=&$CommonOptional->createChild('ECommerceData'); $ECommerceData->attribute('ECSecurityInd','07'); $ECOrderNum=&$ECommerceData->createChild('ECOrderNum'); $ECOrderNum->text($my_invoice_description); // $my_invoice_description $Auth=&$AC->createChild('Auth'); $AuthMandatory=&$Auth->createChild('AuthMandatory'); $AuthMandatory->attribute('FormatInd','H'); $AuthOptional=&$Auth->createChild('AuthOptional'); $AVSextended=&$AuthOptional->createChild('AVSextended'); $AVSname=&$AVSextended->createChild('AVSname'); $AVSname->text(strip_specialchars($my_card_name)); $AVSaddress1=&$AVSextended->createChild('AVSaddress1'); $AVSaddress1->text(strip_specialchars($my_address)); $AVScity=&$AVSextended->createChild('AVScity'); $AVScity->text(strip_specialchars($my_city)); $AVSstate=&$AVSextended->createChild('AVSstate'); $AVSstate->text(strip_specialchars($my_state)); $AVSzip=&$AVSextended->createChild('AVSzip'); $AVSzip->text(strip_specialchars($my_postcode)); // $my_postcode $Cap=&$AC->createChild('Cap'); $CapMandatory=&$Cap->createChild('CapMandatory'); $EntryDataSrc=&$CapMandatory->createChild('EntryDataSrc'); $EntryDataSrc->text('02'); $CapOptional=&$Cap->createChild('CapOptional'); $needle=''; $haystack=$xmlDoc->toString(); $pos=strpos($haystack,$needle); $ReqLen=strlen($haystack)-$pos; $xmlRequest=substr($haystack,$pos,$ReqLen); // strips off version element // echo $xmlRequest.'

'; // 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; } ?>