Пример #1
0
 /**
   Prepare an XML request body for an PDCX
   or EMVX transaction
   @param $type [string] card type
   @param $amount [number] authorization amount
   @return [string] XML request body
 */
 public function prepareDataCapAuth($type, $amount, $prompt = false)
 {
     $request = new PaycardRequest($this->refnum(CoreLocal::get('paycard_id')));
     $request->setProcessor('MercuryE2E');
     $operatorID = $request->cashierNo;
     $termID = $this->getTermID();
     $mcTerminalID = CoreLocal::get('PaycardsTerminalID');
     if ($mcTerminalID === '') {
         $mcTerminalID = CoreLocal::get('laneno');
     }
     $tran_code = $amount > 0 ? 'Sale' : 'Return';
     if ($type == 'EMV') {
         $tran_code = 'EMV' . $tran_code;
     } elseif ($type == 'GIFT') {
         $tran_code = $amount > 0 ? 'NoNSFSale' : 'Return';
     } else {
         if (CoreLocal::get("ebt_authcode") != "" && CoreLocal::get("ebt_vnum") != "") {
             $tran_code = 'Voucher';
         }
     }
     $host = "x1.mercurypay.com";
     if (CoreLocal::get("training") == 1) {
         $host = "x1.mercurydev.net";
         $operatorID = 'test';
     }
     $tran_type = 'Credit';
     $card_type = false;
     if ($type == 'DEBIT') {
         $tran_type = 'Debit';
     } elseif ($type == 'EBTFOOD') {
         $tran_type = 'EBT';
         $card_type = 'Foodstamp';
     } elseif ($type == 'EBTCASH') {
         $tran_type = 'EBT';
         $card_type = 'Cash';
     } elseif ($type == 'GIFT') {
         $tran_type = 'PrePaid';
     }
     $request->setManual($prompt ? 1 : 0);
     try {
         $request->saveRequest();
     } catch (Exception $ex) {
         // TODO: cancel request on JS side
         $this->setErrorMsg(PaycardLib::PAYCARD_ERR_NOSEND);
         return 'Error';
     }
     CoreLocal::set('LastEmvPcId', array($request->last_paycard_transaction_id, $request->last_req_id));
     CoreLocal::set('LastEmvReqType', 'normal');
     // start with fields common to PDCX and EMVX
     $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>' . $request->refNum . '</RefNo>
         <Amount>
             <Purchase>' . $request->formattedAmount() . '</Purchase>';
     if ($request->cashback) {
         $msgXml .= '<CashBack>' . $request->formattedCashBack() . '</CashBack>';
     }
     $msgXml .= '</Amount>
         <RecordNo>RecordNumberRequested</RecordNo>
         <Frequency>OneTime</Frequency>';
     if ($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 ($prompt) {
             $msgXml .= '
                 <Account>
                     <AcctNo>Prompt</AcctNo>
                 </Account>';
         }
         if (CoreLocal::get('PaycardsDatacapMode') == 2) {
             $msgXml .= '<MerchantLanguage>English</MerchantLanguage>';
         } elseif (CoreLocal::get('PaycardsDatacapMode') == 3) {
             $msgXml .= '<MerchantLanguage>French</MerchantLanguage>';
         }
     } else {
         $msgXml .= '
         <Memo>CORE POS 1.0.0 PDCX</Memo>
         <Account>
             <AcctNo>' . ($prompt ? 'Prompt' : 'SecureDevice') . '</AcctNo>
         </Account>
         <TranType>' . $tran_type . '</TranType>';
         if ($card_type) {
             $msgXml .= '<CardType>' . $card_type . '</CardType>';
         }
         if ($type == 'CREDIT') {
             $msgXml .= '<PartialAuth>Allow</PartialAuth>';
         }
         if ($type == 'GIFT') {
             $msgXml .= '<IpPort>9100</IpPort>';
             $msgXml .= '<IpAddress>' . $this->giftServerIP() . '</IpAddress>';
         }
         if (CoreLocal::get("ebt_authcode") != "" && CoreLocal::get("ebt_vnum") != "") {
             $msgXml .= $this->ebtVoucherXml();
         }
     }
     $msgXml .= '
         </Transaction>
         </TStream>';
     $this->last_request = $request;
     return $msgXml;
 }