Example #1
0
function doquery($dateStr, $refNum)
{
    global $GOEMERCH_ID, $GOEMERCH_GATEWAY_ID;
    echo 'issuing query...' . "\n";
    $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    $xml .= "<TRANSACTION>";
    $xml .= "<FIELDS>";
    $xml .= "<FIELD KEY=\"merchant\">{$GOEMERCH_ID}</FIELD>";
    $xml .= "<FIELD KEY=\"gateway_id\">{$GOEMERCH_GATEWAY_ID}</FIELD>";
    $xml .= "<FIELD KEY=\"operation_type\">query</FIELD>";
    $xml .= "<FIELD KEY=\"trans_type\">SALE</FIELD>";
    $xml .= "<FIELD KEY=\"begin_date\">{$dateStr}</FIELD>";
    $xml .= "<FIELD KEY=\"begin_time\">0001AM</FIELD>";
    $xml .= "<FIELD KEY=\"end_date\">{$dateStr}</FIELD>";
    $xml .= "<FIELD KEY=\"end_time\">1159PM</FIELD>";
    $xml .= "<FIELD KEY=\"order_id\">{$refNum}</FIELD>";
    $xml .= "</FIELDS>";
    $xml .= "</TRANSACTION>";
    $result = docurl($xml);
    fwrite(STDERR, $result['response'] . "\n");
    $p = new xmlData($result['response']);
    if ($p->get_first("RECORDS_FOUND") != 0) {
        return $p->get_first("REFERENCE_NUMBER1");
    } else {
        return False;
    }
}
Example #2
0
 private function handleResponseBalance($balResult)
 {
     $xml = new xmlData($balResult["response"]);
     $program = 'Gift';
     if ($balResult['curlErr'] != CURLE_OK || $balResult['curlHTTP'] != 200) {
         if ($authResult['curlHTTP'] == '0') {
             CoreLocal::set("boxMsg", "No response from processor<br />\n                                          The transaction did not go through");
             return PaycardLib::PAYCARD_ERR_PROC;
         }
         return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_COMM);
         // comm error, try again
     }
     CoreLocal::set("paycard_response", array());
     CoreLocal::set("paycard_response", $xml->array_dump());
     $resp = CoreLocal::get("paycard_response");
     if (isset($resp["BALANCE"])) {
         $resp["Balance"] = $resp["BALANCE"];
         CoreLocal::set("paycard_response", $resp);
     }
     // there's less to verify for balance checks, just make sure all the fields are there
     if ($xml->isValid() && $xml->get('TRANSACTIONTYPE') && $xml->get('TRANSACTIONTYPE') == $program && $xml->get('AUTHORIZED') && $xml->get('AUTHORIZED') == 'true' && (!$xml->get('ERRORMSG') || $xml->get_first('ERRORMSG') == '') && $xml->get('BALANCE')) {
         return PaycardLib::PAYCARD_ERR_OK;
         // balance checked, no error
     }
     // the authorizor gave us some failure code
     CoreLocal::set("boxMsg", "Processor error: " . $xml->get_first("ERRORMSG"));
     return PaycardLib::PAYCARD_ERR_PROC;
 }
Example #3
0
 public function lookupTransaction($ref, $local, $mode)
 {
     $merchantID = GOEMERCH_ID;
     $password = GOEMERCH_PASSWD;
     $gatewayID = GOEMERCH_GATEWAY_ID;
     if (substr($ref, 13, 4) == "9999") {
         $merchantID = "1264";
         $password = "******";
         $gatewayID = "a91c38c3-7d7f-4d29-acc7-927b4dca0dbe";
     }
     $dateStr = date('mdy');
     $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
     $xml .= "<TRANSACTION>";
     $xml .= "<FIELDS>";
     $xml .= "<FIELD KEY=\"merchant\">{$merchantID}</FIELD>";
     if ($password != "") {
         $xml .= "<FIELD KEY=\"password\">{$password}</FIELD>";
     }
     $xml .= "<FIELD KEY=\"gateway_id\">{$gatewayID}</FIELD>";
     $xml .= "<FIELD KEY=\"operation_type\">query</FIELD>";
     $xml .= "<FIELD KEY=\"trans_type\">SALE</FIELD>";
     $xml .= "<FIELD KEY=\"begin_date\">{$dateStr}</FIELD>";
     $xml .= "<FIELD KEY=\"begin_time\">0001AM</FIELD>";
     $xml .= "<FIELD KEY=\"end_date\">{$dateStr}</FIELD>";
     $xml .= "<FIELD KEY=\"end_time\">1159PM</FIELD>";
     $xml .= "<FIELD KEY=\"order_id\">{$ref}</FIELD>";
     $xml .= "</FIELDS>";
     $xml .= "</TRANSACTION>";
     $this->GATEWAY = "https://secure.goemerchant.com/secure/gateway/xmlgateway.aspx";
     $curl_result = $this->curlSend($xml, 'POST', true, array(), false);
     if ($curl_result['curlErr'] != CURLE_OK || $curl_result['curlHTTP'] != 200) {
         return array('output' => DisplayLib::boxMsg('No response from processor', '', true), 'confirm_dest' => MiscLib::base_url() . 'gui-modules/pos2.php', 'cancel_dest' => MiscLib::base_url() . 'gui-modules/pos2.php');
     }
     $directions = 'Press [enter] or [clear] to continue';
     $resp = array('confirm_dest' => MiscLib::base_url() . 'gui-modules/pos2.php', 'cancel_dest' => MiscLib::base_url() . 'gui-modules/pos2.php');
     $info = new Paycards();
     $url_stem = $info->pluginUrl();
     $xml_resp = new xmlData($curl_result['response']);
     $status = 'UNKNOWN';
     if ($xml_resp->get_first('RECORDS_FOUND') == 0) {
         $status = 'NOTFOUND';
         $directions = 'Press [enter] to try again, [clear] to stop';
         $query_string = 'id=' . ($local ? '_l' : '') . $ref . '&mode=' . $mode;
         $resp['confirm_dest'] = $url_stem . '/gui/PaycardTransLookupPage.php?' . $query_string;
     } else {
         $responseCode = $xml_resp->get_first('TRANS_STATUS1');
         $resultCode = $responseCode;
         $normalized = $resultCode;
         $xTransID = $xml_resp->get_first('REFERENCE_NUMBER1');
         $rMsg = '';
         if ($responseCode == 1) {
             $status = 'APPROVED';
             $rMsg = 'APPROVED';
             $normalized = 1;
         } else {
             if ($responseCode == 2) {
                 $status == 'DECLINED';
                 $rMsg = 'DECLINED';
                 $normalized = 2;
             } else {
                 if ($responseCode == 0) {
                     $status == 'ERROR';
                     $eMsg = $xml_resp->get_first('ERROR1');
                     $normalized = 3;
                     if ($eMsg) {
                         $rMsg = substr($eMsg, 0, 100);
                     } else {
                         $rMsg = 'ERROR';
                     }
                 } else {
                     $responseCode = -3;
                     $normalized = 0;
                     $status = 'UNKNOWN';
                 }
             }
         }
         $apprNumber = '';
         // not returned by query op
         if ($local == 1 && $mode == 'verify') {
             // Update efsnetResponse record to contain
             // actual processor result and finish
             // the transaction correctly
             $db = Database::tDataConnect();
             $upP = $db->prepare("\n                    UPDATE PaycardTransactions \n                    SET xResponseCode=?,\n                        xResultCode=?,\n                        xResultMessage=?,\n                        xTransactionID=?,\n                        xApprovalNumber=?,\n                        commErr=0,\n                        httpCode=200,\n                        validResponse=?\n                    WHERE refNum=?\n                        AND transID=?");
             $args = array($responseCode, $resultCode, $rMsg, $xTransID, $apprNumber, $normalized, $ref, CoreLocal::get('paycard_id'));
             $upR = $db->execute($upP, $args);
             $upP = $db->prepare("\n                    UPDATE efsnetResponse SET\n                        xResponseCode=?,\n                        xResultCode=?, \n                        xResultMessage=?,\n                        xTransactionID=?,\n                        xApprovalNumber=?,\n                        commErr=0,\n                        httpCode=200\n                    WHERE refNum=?\n                        AND transID=?");
             $args = array($responseCode, $resultCode, $rMsg, $xTransID, $apprNumber, $ref, CoreLocal::get('paycard_id'));
             if ($db->table_exists('efsnetResponse')) {
                 $upR = $db->execute($upP, $args);
             }
             if ($status == 'APPROVED') {
                 PaycardLib::paycard_wipe_pan();
                 $this->cleanup(array());
                 $resp['confirm_dest'] = $url_stem . '/gui/paycardSuccess.php';
                 $resp['cancel_dest'] = $url_stem . '/gui/paycardSuccess.php';
                 $directions = 'Press [enter] to continue';
             } else {
                 PaycardLib::paycard_reset();
             }
         }
         // end verification record update
     }
     // end found result
     switch (strtoupper($status)) {
         case 'APPROVED':
             $line1 = $status;
             $line2 = 'Amount: ' . sprintf('%.2f', $xml_resp->get_first('AMOUNT1'));
             $line3 = 'Type: CREDIT';
             $voided = $xml_resp->get_first('CREDIT_VOID1');
             $line4 = 'Voided: ' . (strtoupper($voided) == 'VOID' ? 'Yes' : 'No');
             $resp['output'] = DisplayLib::boxMsg($line1 . '<br />' . $line2 . '<br />' . $line3 . '<br />' . $line4 . '<br />' . $directions, '', true);
             break;
         case 'DECLINED':
             $resp['output'] = DisplayLib::boxMsg('The original transaction was declined
                                                   <br />' . $directions, '', true);
             break;
         case 'ERROR':
             $resp['output'] = DisplayLib::boxMsg('The original transaction resulted in an error
                                                   <br />' . $directions, '', true);
             break;
         case 'NOTFOUND':
             $resp['output'] = DisplayLib::boxMsg('Processor has no record of the transaction
                                                   <br />' . $directions, '', true);
             break;
         case 'UNKNOWN':
             $resp['output'] = DisplayLib::boxMsg('Processor responded but made no sense
                                                   <br />' . $directions, '', true);
             break;
     }
     return $resp;
 }
Example #4
0
 private function handleResponseBalance($balResult)
 {
     $resp = $this->desoapify("GiftTransactionResult", $balResult["response"]);
     $xml = new xmlData($resp);
     $program = 'Gift';
     if ($balResult['curlErr'] != CURLE_OK || $balResult['curlHTTP'] != 200) {
         if ($authResult['curlHTTP'] == '0') {
             if (!$this->second_try) {
                 $this->second_try = true;
                 return $this->send_balance("w2.backuppay.com");
             } else {
                 CoreLocal::set("boxMsg", "No response from processor<br />\n                                The transaction did not go through");
                 return PaycardLib::PAYCARD_ERR_PROC;
             }
         }
         return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_COMM);
         // comm error, try again
     }
     CoreLocal::set("paycard_response", array());
     CoreLocal::set("paycard_response", $xml->array_dump());
     $resp = CoreLocal::get("paycard_response");
     if (isset($resp["BALANCE"])) {
         $resp["Balance"] = $resp["BALANCE"];
         CoreLocal::set("paycard_response", $resp);
     }
     // there's less to verify for balance checks, just make sure all the fields are there
     if ($xml->isValid() && $xml->get('TRANTYPE') && $xml->get('TRANTYPE') == 'PrePaid' && $xml->get('CMDSTATUS') && $xml->get('CMDSTATUS') == 'Approved' && $xml->get('BALANCE')) {
         return PaycardLib::PAYCARD_ERR_OK;
         // balance checked, no error
     }
     // the authorizor gave us some failure code
     CoreLocal::set("boxMsg", "Processor error: " . $xml->get_first("TEXTRESPONSE"));
     return PaycardLib::PAYCARD_ERR_PROC;
 }
Example #5
0
 function handleResponseVoid($authResult)
 {
     $xml = new xmlData($authResult['response']);
     $request = $this->last_request;
     $this->last_paycard_transaction_id = $request->last_paycard_transaction_id;
     $response = new PaycardResponse($request, $authResult);
     $validResponse = $xml->isValid() ? 1 : 0;
     $responseCode = $xml->get("RESPONSECODE");
     if ($responseCode === false) {
         $validResponse = -3;
     }
     $response->setResponseCode($responseCode);
     $resultCode = $xml->get_first("CODE");
     $response->setResultCode($resultCode);
     $resultMsg = $xml->get_first("DESCRIPTION");
     $response->setResultMsg($resultMsg);
     $response->setValid($validResponse);
     try {
         $response->saveResponse();
     } catch (Exception $ex) {
     }
     if ($authResult['curlErr'] != CURLE_OK || $authResult['curlHTTP'] != 200) {
         return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_COMM);
     }
     switch ($xml->get("RESPONSECODE")) {
         case 1:
             // APPROVED
             return PaycardLib::PAYCARD_ERR_OK;
         case 2:
             // DECLINED
             CoreLocal::set("boxMsg", "Transaction declined");
             if ($xml->get_first("ERRORCODE") == 4) {
                 CoreLocal::set("boxMsg", CoreLocal::get("boxMsg") . "<br />Pick up card");
             }
             break;
         case 3:
             // ERROR
             CoreLocal::set("boxMsg", "");
             $codes = $xml->get("ERRORCODE");
             $texts = $xml->get("ERRORTEXT");
             if (!is_array($codes)) {
                 CoreLocal::set("boxMsg", "EC{$codes}: {$texts}");
             } else {
                 for ($i = 0; $i < count($codes); $i++) {
                     CoreLocal::set("boxMsg", CoreLocal::get("boxMsg") . "EC" . $codes[$i] . ": " . $texts[$i]);
                     if ($i != count($codes) - 1) {
                         CoreLocal::set("boxMsg", CoreLocal::get("boxMsg") . "<br />");
                     }
                 }
             }
             break;
         default:
             CoreLocal::set("boxMsg", "An unknown error occurred<br />at the gateway");
     }
     return PaycardLib::PAYCARD_ERROR_PROC;
 }
Example #6
0
 function handleResponseAuth($authResult)
 {
     $inner_xml = $this->desoapify("SOAP-ENV:Body", $authResult['response']);
     $xml = new xmlData($inner_xml);
     $request = $this->last_request;
     $this->last_paycard_transaction_id = $request->last_paycard_transaction_id;
     $response = new PaycardResponse($request, $authResult);
     $dbTrans = PaycardLib::paycard_db();
     $cvv2 = CoreLocal::get("paycard_cvv2");
     $validResponse = $xml->isValid() ? 1 : 0;
     $statusMsg = $xml->get("fdggwsapi:TransactionResult");
     $responseCode = 4;
     switch (strtoupper($statusMsg)) {
         case 'APPROVED':
             $responseCode = 1;
             break;
         case 'DECLINED':
         case 'FRAUD':
             $responseCode = 2;
             break;
         case 'FAILED':
         case 'DUPLICATE':
             $responseCode = 0;
             break;
     }
     $response->setResponseCode($responseCode);
     // aren't two separate codes from goemerchant
     $resultCode = $responseCode;
     $response->setResultCode($resultCode);
     $resultMsg = $statusMsg;
     // already gathered above
     $response->setResultMsg($resultMsg);
     $xTransID = $xml->get("fdggwsapi:ProcessorReferenceNumber");
     $response->setTransactionID($xTransID);
     $apprNumber = $xml->get("fdggwsapi:ApprovalCode");
     $response->setApprovalNum($apprNumber);
     // valid credit transactions don't have an approval number
     $response->setValid(0);
     try {
         $response->saveResponse();
     } catch (Exception $ex) {
     }
     if ($authResult['curlErr'] != CURLE_OK || $authResult['curlHTTP'] != 200) {
         TransRecord::addcomment("");
         if ($authResult['curlHTTP'] == '0') {
             CoreLocal::set("boxMsg", "No response from processor<br />\n                            The transaction did not go through");
             return PaycardLib::PAYCARD_ERR_PROC;
         }
         return $this->setErrorMsg(PaycardLib::PAYCARD_ERR_COMM);
     }
     switch ($responseCode) {
         case 1:
             // APPROVED
             return PaycardLib::PAYCARD_ERR_OK;
         case 2:
             // DECLINED
             CoreLocal::set("boxMsg", 'Card Declined');
             break;
         case 0:
             // ERROR
             $texts = $xml->get_first("fdggwsapi:ProcessorResponseMessage");
             CoreLocal::set("boxMsg", "Error: {$texts}");
             break;
         default:
             CoreLocal::set("boxMsg", "An unknown error occurred<br />at the gateway");
     }
     return PaycardLib::PAYCARD_ERR_PROC;
 }
Example #7
0
 public function lookupTransaction($ref, $local, $mode)
 {
     $ws_params = array('merchant' => CoreLocal::get('MercuryE2ETerminalID'), 'pw' => CoreLocal::get('MercuryE2EPassword'), 'invoice' => $ref);
     // emp_no 9999 => test transaction
     if (substr($ref, 4, 4) == "9999") {
         $ws_params['merchant'] = '395347308=E2ETKN';
         $ws_params['pw'] = '123E2ETKN';
     }
     $this->SOAPACTION = 'http://www.mercurypay.com/CTranDetail';
     $soaptext = $this->soapify('CTranDetail', $ws_params, 'http://www.mercurypay.com');
     $this->GATEWAY = 'https://' . self::PRIMARY_URL . '/ws/ws.asmx';
     $curl_result = $this->curlSend($soaptext, 'SOAP', false, array(), false);
     if ($curl_result['curlErr'] != CURLE_OK || $curl_result['curlHTTP'] != 200) {
         $this->GATEWAY = 'https://' . self::BACKUP_URL . '/ws/ws.asmx';
         $curl_result = $this->curlSend($soaptext, 'SOAP', false, array(), false);
         if ($curl_result['curlErr'] != CURLE_OK || $curl_result['curlHTTP'] != 200) {
             return array('output' => DisplayLib::boxMsg('No response from processor', '', true), 'confirm_dest' => MiscLib::base_url() . 'gui-modules/pos2.php', 'cancel_dest' => MiscLib::base_url() . 'gui-modules/pos2.php');
         }
     }
     $directions = 'Press [enter] or [clear] to continue';
     $resp = array('confirm_dest' => MiscLib::base_url() . 'gui-modules/pos2.php', 'cancel_dest' => MiscLib::base_url() . 'gui-modules/pos2.php');
     $info = new Paycards();
     $url_stem = $info->pluginUrl();
     $xml_resp = $this->desoapify('CTranDetailResponse', $curl_result['response']);
     $xml = new xmlData($xml_resp);
     $status = trim($xml->get_first('STATUS'));
     if ($status === '') {
         $status = 'NOTFOUND';
         $directions = 'Press [enter] to try again, [clear] to stop';
         $query_string = 'id=' . ($local ? '_l' : '') . $ref . '&mode=' . $mode;
         $resp['confirm_dest'] = $url_stem . '/gui/PaycardTransLookupPage.php?' . $query_string;
     } else {
         if ($local == 1 && $mode == 'verify') {
             // Update efsnetResponse record to contain
             // actual processor result and finish
             // the transaction correctly
             $responseCode = -3;
             $resultCode = 0;
             $normalized = 0;
             if ($status == 'Approved') {
                 $responseCode = 1;
                 $normalized = 1;
                 PaycardLib::paycard_wipe_pan();
                 $this->cleanup(array());
                 $resp['confirm_dest'] = $url_stem . '/gui/paycardSuccess.php';
                 $resp['cancel_dest'] = $url_stem . '/gui/paycardSuccess.php';
                 $directions = 'Press [enter] to continue';
             } else {
                 if ($status == 'Declined') {
                     PaycardLib::paycard_reset();
                     $responseCode = 2;
                     $normalized = 2;
                 } else {
                     if ($status == 'Error') {
                         PaycardLib::paycard_reset();
                         $responseCode = 0;
                         $resultCode = -1;
                         // CTranDetail does not provide this value
                         $normalized = 3;
                     } else {
                         // Unknown status; clear any data
                         PaycardLib::paycard_reset();
                     }
                 }
             }
             $apprNumber = $xml->get_first('authcode');
             $xTransID = $xml->get_first('reference');
             $rMsg = $status;
             if ($apprNumber) {
                 $rMsg .= ' ' . $apprNumber;
             }
             if (strlen($rMsg) > 100) {
                 $rMsg = substr($rMsg, 0, 100);
             }
             $db = Database::tDataConnect();
             $upP = $db->prepare("\n                UPDATE PaycardTransactions \n                SET xResponseCode=?,\n                    xResultCode=?,\n                    xResultMessage=?,\n                    xTransactionID=?,\n                    xApprovalNumber=?,\n                    commErr=0,\n                    httpCode=200,\n                    validResponse=?\n                WHERE refNum=?\n                    AND transID=?");
             $args = array($responseCode, $resultCode, $rMsg, $xTransID, $apprNumber, $normalized, $ref, CoreLocal::get('paycard_id'));
             $upR = $db->execute($upP, $args);
             $upP = $db->prepare("\n                UPDATE efsnetResponse SET\n                    xResponseCode=?,\n                    xResultCode=?, \n                    xResultMessage=?,\n                    xTransactionID=?,\n                    xApprovalNumber=?,\n                    commErr=0,\n                    httpCode=200\n                WHERE refNum=?\n                    AND transID=?");
             $args = array($responseCode, $resultCode, $rMsg, $xTransID, $apprNumber, $ref, CoreLocal::get('paycard_id'));
             if ($db->table_exists('efsnetResponse')) {
                 $upR = $db->execute($upP, $args);
             }
         }
     }
     switch (strtoupper($status)) {
         case 'APPROVED':
             $line1 = $status . ' ' . $xml->get_first('authcode');
             $line2 = 'Amount: ' . sprintf('%.2f', $xml->get_first('total'));
             $trans_type = $xml->get_first('trantype');
             $line3 = 'Type: ' . $trans_type;
             $voided = $xml->get_first('voided');
             $line4 = 'Voided: ' . ($voided == 'true' ? 'Yes' : 'No');
             $resp['output'] = DisplayLib::boxMsg($line1 . '<br />' . $line2 . '<br />' . $line3 . '<br />' . $line4 . '<br />' . $directions, '', true);
             break;
         case 'DECLINED':
             $resp['output'] = DisplayLib::boxMsg('The original transaction was declined
                                                   <br />' . $directions, '', true);
             break;
         case 'ERROR':
             $resp['output'] = DisplayLib::boxMsg('The original transaction resulted in an error
                                                   <br />' . $directions, '', true);
             break;
         case 'NOTFOUND':
             $resp['output'] = DisplayLib::boxMsg('Processor has no record of the transaction
                                                   <br />' . $directions, '', true);
             break;
     }
     return $resp;
 }