Example #1
0
 /**
   Prepare an XML request body to void an PDCX
   or EMVX transaction
   @param $pcID [int] PaycardTransactions record ID
   @return [string] XML request
 */
 public function prepareDataCapVoid($pcID)
 {
     $request = new PaycardRequest($this->refnum(CoreLocal::get('paycard_id')));
     $request->setProcessor('MercuryE2E');
     $termID = $this->getTermID();
     $operatorID = $request->cashierNo;
     $mcTerminalID = CoreLocal::get('PaycardsTerminalID');
     if ($mcTerminalID === '') {
         $mcTerminalID = CoreLocal::get('laneno');
     }
     $host = "x1.mercurypay.com";
     if (CoreLocal::get("training") == 1) {
         $host = "x1.mercurydev.net";
         $operatorID = 'test';
     }
     $request->last_paycard_transaction_id = $pcID;
     try {
         $prev = $request->findOriginal();
     } catch (Exception $ex) {
         CoreLocal::set('boxMsg', 'Transaction not found');
         return 'Error';
     }
     try {
         $request->saveRequest();
         CoreLocal::set('LastEmvPcId', array($request->last_paycard_transaction_id, $request->last_req_id));
         CoreLocal::set('LastEmvReqType', 'void');
     } catch (Exception $ex) {
         $this->setErrorMsg(PaycardLib::PAYCARD_ERR_NOSEND);
         return 'Error';
     }
     /* Determine reversal method based on
           original transaction.
           EMV and Credit are voided
           PIN Debit and EBT run an opposite transaction
           (e.g., Return after a Sale)
        */
     $tran_code = '';
     $tran_type = '';
     $card_type = false;
     if ($prev['transType'] == 'EMVSale') {
         $tran_code = 'EMVVoidSale';
         $tran_type = 'EMV';
     } elseif ($prev['transType'] == 'EMVReturn') {
         $tran_code = 'EMVVoidReturn';
         $tran_type = 'EMV';
     } elseif ($prev['transType'] == 'NoNSFSale') {
         $tran_type = 'PrePaid';
         $tran_code = 'VoidSale';
     } else {
         switch ($prev['cardType']) {
             case 'Credit':
                 $tran_code = $prev['transType'] == 'Sale' ? 'VoidSaleByRecordNo' : 'VoidReturnByRecordNo';
                 $tran_type = 'Credit';
                 break;
             case 'Debit':
                 $tran_code = $prev['transType'] == 'Sale' ? 'ReturnByRecordNo' : 'SaleByRecordNo';
                 $tran_type = 'Debit';
                 break;
             case 'EBT':
                 $tran_code = $prev['transType'] == 'Sale' ? 'ReturnByRecordNo' : 'SaleByRecordNo';
                 $tran_type = 'EBT';
                 $card_type = $prev['issuer'];
                 break;
         }
     }
     // common fields
     $msgXml = '<?xml version="1.0"?' . '>
         <TStream>
         <Transaction>
         <MerchantID>' . $termID . '</MerchantID>
         <OperatorID>' . $operatorID . '</OperatorID>
         <LaneID>' . $mcTerminalID . '</LaneID>
         <TranCode>' . $tran_code . '</TranCode>
         <SecureDevice>{{SecureDevice}}</SecureDevice>
         <ComPort>{{ComPort}}</ComPort>
         <InvoiceNo>' . $request->refNum . '</InvoiceNo>
         <RefNo>' . $prev['xTransactionID'] . '</RefNo>
         <Amount>
             <Purchase>' . sprintf('%.2f', abs($prev['amount'])) . '</Purchase>
         </Amount>
         <RecordNo>RecordNumberRequested</RecordNo>
         <Frequency>OneTime</Frequency>';
     if ($tran_type == 'EMV') {
         // add EMV specific fields
         $dc_host = CoreLocal::get('PaycardsDatacapLanHost');
         if (empty($dc_host)) {
             $dc_host = '127.0.0.1';
         }
         $msgXml .= '
         <HostOrIP>' . $dc_host . '</HostOrIP>
         <SequenceNo>{{SequenceNo}}</SequenceNo>
         <CollectData>CardholderName</CollectData>
         <Memo>CORE POS 1.0.0 EMVX</Memo>
         <PartialAuth>Allow</PartialAuth>';
         if (CoreLocal::get('PaycardsDatacapMode') == 2) {
             $msgXml .= '<MerchantLanguage>English</MerchantLanguage>';
         } elseif (CoreLocal::get('PaycardsDatacapMode') == 3) {
             $msgXml .= '<MerchantLanguage>French</MerchantLanguage>';
         }
     } else {
         // add non-EMV fields
         $msgXml .= '
         <Memo>CORE POS 1.0.0 PDCX</Memo>
         <Account>
             <AcctNo>SecureDevice</AcctNo>
         </Account>
         <TranType>' . $tran_type . '</TranType>';
         if ($card_type) {
             $msgXml .= '<CardType>' . $card_type . '</CardType>';
         }
         if ($tran_type == 'Credit') {
             $msgXml .= '<PartialAuth>Allow</PartialAuth>';
         }
         if ($tran_type == 'PrePaid') {
             $msgXml .= '<IpPort>9100</IpPort>';
             $msgXml .= '<IpAddress>' . $this->giftServerIP() . '</IpAddress>';
         }
     }
     /**
       Add token and reversal data fields if available
     */
     if ($prev['xToken']) {
         $msgXml .= '<RecordNo>' . $prev['xToken'] . '</RecordNo>';
     }
     if ($prev['xProcessorRef']) {
         $msgXml .= '<ProcessData>' . $prev['xProcessorRef'] . '</ProcessData>';
     }
     if ($prev['xAcquirerRef']) {
         $msgXml .= '<AcqRefData>' . $prev['xAcquirerRef'] . '</AcqRefData>';
     }
     $msgXml .= '
         <AuthCode>' . $prev['xApprovalNumber'] . '</AuthCode>
         </Transaction>
         </TStream>';
     $this->last_request = $request;
     return $msgXml;
 }