public function testMercuryE2E() { if (!class_exists('lttLib')) { include dirname(__FILE__) . '/lttLib.php'; } lttLib::clear(); $plugins = CoreLocal::get('PluginList'); if (!in_array('Paycards', $plugins)) { $plugins[] = 'Paycards'; CoreLocal::set('PluginList', $plugins); } /** Initialize session stuff to run a test transaction */ CoreLocal::set('CCintegrate', 1); CoreLocal::set('RegisteredPaycardClasses', array('MercuryE2E')); CoreLocal::set('PaycardsTerminalID', '99'); CoreLocal::set('PaycardsTenderCodeCredit', 'CC'); CoreLocal::set('PaycardsTenderCodeVisa', ''); CoreLocal::set('CacheCardType', 'CREDIT'); CoreLocal::set('ttlflag', 1); CoreLocal::set('amtdue', 0.01); CoreLocal::set('CashierNo', 9999); CoreLocal::set('laneno', 99); CoreLocal::set('transno', 1); CoreLocal::set('training', 1); /** Run parser on test PAN. Verify result and appropriate session vars initialized */ $parser = new paycardEntered(); // source: Visa Test Card using Sign&Pay w/ test keys $pan = '02E600801F2E2700039B25423430303330302A2A2A2A2A2A363738315E544553542F4D50535E313531322A2A2A2A2A2A2A2A2A2A2A2A2A3F3B3430303330302A2A2A2A2A2A363738313D313531322A2A2A2A2A2A2A2A2A2A2A2A2A2A2A2A3FA7284186B3E8E1A3E2AD8548E732DBB5B33285117FB1B0CDBA6D732E5DF031DE3CB590DE2E02BDEF6182373B7401A3E3D304013C85D3BEFDEBF552A3C30914246B0145538F2E5856885CAA06FF64E201CB974CD506ADDCB22C9F3BF500C62310C9C88B56FD2BDF6E59481BC4B6C4F034264B2C38F8FF6F4405D563AA7D49B82221111010000000E001BFXXXX03'; $this->assertEquals(true, $parser->check($pan), 'Parser does not handle input'); $json = $parser->parse($pan); $url = 'plugins/Paycards/gui/paycardboxMsgAuth.php'; $this->assertEmpty($json['output'], 'Parser error message: ' . $json['output']); $this->assertEquals($url, substr($json['main_frame'], -1 * strlen($url)), 'No redirect to auth page'); $this->assertEquals(0.01, CoreLocal::get('paycard_amount')); $this->assertEquals(PaycardLib::PAYCARD_MODE_AUTH, CoreLocal::get('paycard_mode')); $this->assertEquals(PaycardLib::PAYCARD_TYPE_ENCRYPTED, CoreLocal::get('paycard_type')); // mercury's gateway is returning weird errors; // don't feel like addressing it right now return; /** Submit transaction to processor. Verify return value and check database for an appropriate auth record */ $this->emptyPaycardTables(); $processor = new MercuryE2E(); $auth_result = $processor->doSend(PaycardLib::PAYCARD_MODE_AUTH); $this->assertEquals(PaycardLib::PAYCARD_ERR_OK, $auth_result, 'Authorization attempt produced error: ' . $auth_result . ' : ' . CoreLocal::get('boxMsg')); $db = Database::tDataConnect(); $ptrans = $db->query('SELECT * FROM PaycardTransactions'); $row = $db->fetch_row($ptrans); $this->assertEquals(date('Ymd'), $row['dateID']); $this->assertEquals(9999, $row['empNo']); $this->assertEquals(99, $row['registerNo']); $this->assertEquals(1, $row['transNo']); $this->assertEquals(1, $row['transID']); $this->assertEquals('MercuryE2E', $row['processor']); $this->assertEquals('Credit', $row['cardType']); $this->assertEquals('Sale', $row['transType']); $this->assertEquals(0.01, $row['amount']); $this->assertEquals('Visa', $row['issuer']); $this->assertEquals(0, $row['commErr']); $this->assertEquals(200, $row['httpCode']); $this->assertEquals(1, $row['validResponse']); $this->assertEquals(1, $row['xResultCode']); $this->assertEquals(0, $row['xResponseCode']); $this->assertNotEmpty($row['xApprovalNumber']); $this->assertNotEmpty($row['xResultMessage']); $this->assertNotEmpty($row['xTransactionID']); $this->assertNotEmpty($row['xToken']); $this->assertNotEmpty($row['xProcessorRef']); $this->assertNotEmpty($row['xAcquirerRef']); $this->assertEquals('************', substr($row['PAN'], 0, 12)); /** cleanup test transaction record(s) */ $this->emptyPaycardTables(); }
function preprocess() { $this->display = ""; $sd = MiscLib::scaleObject(); $entered = ""; if (isset($_REQUEST["reginput"])) { $entered = strtoupper(trim($_REQUEST["reginput"])); } if (substr($entered, -2) == "CL") { $entered = "CL"; } if ($entered == "RI") { $entered = CoreLocal::get("strEntered"); } if (CoreLocal::get("msgrepeat") == 1 && $entered != "CL") { $entered = CoreLocal::get("strRemembered"); CoreLocal::set('strRemembered', ''); } CoreLocal::set("strEntered", $entered); $json = array(); if ($entered != "") { if (in_array("Paycards", CoreLocal::get("PluginList"))) { /* this breaks the model a bit, but I'm putting * putting the CC parser first manually to minimize * code that potentially handles the PAN */ if (CoreLocal::get("PaycardsCashierFacing") == "1" && substr($entered, 0, 9) == "PANCACHE:") { /* cashier-facing device behavior; run card immediately */ $entered = substr($entered, 9); CoreLocal::set("CachePanEncBlock", $entered); } $pe = new paycardEntered(); if ($pe->check($entered)) { $valid = $pe->parse($entered); $entered = "PAYCARD"; CoreLocal::set("strEntered", ""); $json = $valid; } CoreLocal::set("quantity", 0); CoreLocal::set("multiple", 0); } /* FIRST PARSE CHAIN: * Objects belong in the first parse chain if they * modify the entered string, but do not process it * This chain should be used for checking prefixes/suffixes * to set up appropriate session variables. */ $parser_lib_path = $this->page_url . "parser-class-lib/"; if (!is_array(CoreLocal::get("preparse_chain"))) { CoreLocal::set("preparse_chain", PreParser::get_preparse_chain()); } foreach (CoreLocal::get("preparse_chain") as $cn) { if (!class_exists($cn)) { continue; } $p = new $cn(); if ($p->check($entered)) { $entered = $p->parse($entered); } if (!$entered || $entered == "") { break; } } if ($entered != "" && $entered != "PAYCARD") { /* * SECOND PARSE CHAIN * these parser objects should process any input * completely. The return value of parse() determines * whether to call lastpage() [list the items on screen] */ if (!is_array(CoreLocal::get("parse_chain"))) { CoreLocal::set("parse_chain", Parser::get_parse_chain()); } $result = False; foreach (CoreLocal::get("parse_chain") as $cn) { if (!class_exists($cn)) { continue; } $p = new $cn(); if ($p->check($entered)) { $result = $p->parse($entered); break; } } if ($result && is_array($result)) { // postparse chain: modify result if (!is_array(CoreLocal::get("postparse_chain"))) { CoreLocal::set("postparse_chain", PostParser::getPostParseChain()); } foreach (CoreLocal::get('postparse_chain') as $class) { if (!class_exists($class)) { continue; } $obj = new $class(); $result = $obj->parse($result); } $json = $result; if (isset($result['udpmsg']) && $result['udpmsg'] !== False) { if (is_object($sd)) { $sd->WriteToScale($result['udpmsg']); } } } else { $arr = array('main_frame' => false, 'target' => '.baseHeight', 'output' => DisplayLib::inputUnknown()); $json = $arr; if (is_object($sd)) { $sd->WriteToScale('errorBeep'); } } } } CoreLocal::set("msgrepeat", 0); if (isset($json['main_frame']) && $json['main_frame'] != False) { $this->change_page($json['main_frame']); return False; } if (isset($json['output']) && !empty($json['output'])) { $this->display = $json['output']; } if (isset($json['retry']) && $json['retry'] != False) { $this->add_onload_command("setTimeout(\"inputRetry('" . $json['retry'] . "');\", 150);\n"); } if (isset($json['receipt']) && $json['receipt'] != False) { $ref = isset($json['trans_num']) ? $json['trans_num'] : ReceiptLib::mostRecentReceipt(); $this->add_onload_command("receiptFetch('" . $json['receipt'] . "', '" . $ref . "');\n"); } if (CoreLocal::get('CustomerDisplay') === true) { $child_url = MiscLib::baseURL() . 'gui-modules/posCustDisplay.php'; $this->add_onload_command("setCustomerURL('{$child_url}');\n"); $this->add_onload_command("reloadCustomerDisplay();\n"); } return true; }
if ($entered != "") { /* this breaks the model a bit, but I'm putting * putting the CC parser first manually to minimize * code that potentially handles the PAN */ if (in_array("Paycards", CoreLocal::get("PluginList"))) { /* this breaks the model a bit, but I'm putting * putting the CC parser first manually to minimize * code that potentially handles the PAN */ if (CoreLocal::get("PaycardsCashierFacing") == "1" && substr($entered, 0, 9) == "PANCACHE:") { /* cashier-facing device behavior; run card immediately */ $entered = substr($entered, 9); CoreLocal::set("CachePanEncBlock", $entered); } $pe = new paycardEntered(); if ($pe->check($entered)) { $valid = $pe->parse($entered); $entered = "PAYCARD"; CoreLocal::set("strEntered", ""); $json = $valid; } } CoreLocal::set("quantity", 0); CoreLocal::set("multiple", 0); /* FIRST PARSE CHAIN: * Objects belong in the first parse chain if they * modify the entered string, but do not process it * This chain should be used for checking prefixes/suffixes * to set up appropriate session variables. */ $parser_lib_path = MiscLib::base_url() . "parser-class-lib/"; if (!is_array(CoreLocal::get("preparse_chain"))) {