📄 authorizenet_echeck.php
字号:
/**
* Evaluates the collected data for acceptance and the validity of the type of data supplied
*
*/
function pre_confirmation_check() {
return true;
}
/**
* Display Account Information on the Checkout Confirmation Page
*
* @return array
*/
function confirmation() {
global $order;
$confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_BANK_NAME,
'field' => $_POST['authorizenet_echeck_bank_name']),
array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_BANK_ROUTING_CODE,
'field' => $_POST['authorizenet_echeck_bank_aba_code']),
array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_BANK_ACCOUNT_TYPE,
'field' => $_POST['authorizenet_echeck_bank_acct_type']),
array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_BANK_ACCOUNT_NUM,
'field' => $_POST['authorizenet_echeck_bank_acct_num']),
array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_AUTHORIZATION_TITLE,
'field' => sprintf(MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_AUTHORIZATION_NOTICE, strtolower(zen_db_prepare_input($_POST['authorizenet_echeck_bank_acct_type'])), zen_date_short(date("Y-m-d")), $order->info['total']))
));
return $confirmation;
}
/**
* Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.
* This sends the data to the payment gateway for processing.
* (These are hidden fields on the checkout confirmation page)
*
* @return string
*/
function process_button() {
$process_button_string = zen_draw_hidden_field('bank_aba_code', substr(zen_db_prepare_input($_POST['authorizenet_echeck_bank_aba_code']), 0, 9) ) .
zen_draw_hidden_field('bank_acct_num', substr(zen_db_prepare_input($_POST['authorizenet_echeck_bank_acct_num']), 0, 20) ) .
zen_draw_hidden_field('bank_acct_type', zen_db_prepare_input($_POST['authorizenet_echeck_bank_acct_type']) ) .
zen_draw_hidden_field('bank_name', substr(zen_db_prepare_input($_POST['authorizenet_echeck_bank_name']), 0, 50) ) .
zen_draw_hidden_field('bank_acct_name', substr(zen_db_prepare_input($_POST['authorizenet_echeck_bank_accountholder']), 0, 100) );
if (MODULE_PAYMENT_AUTHORIZENET_ECHECK_WFSS_ENABLED == 'True') {
$process_button_string .= zen_draw_hidden_field('echeck_customer_type', substr(zen_db_prepare_input($_POST['echeck_customer_type']), 0, 10) );
$process_button_string .= zen_draw_hidden_field('echeck_customer_tax_id', substr(zen_db_prepare_input($_POST['echeck_customer_tax_id']), 0, 9) );
$process_button_string .= zen_draw_hidden_field('echeck_dl_num', substr(zen_db_prepare_input($_POST['echeck_dl_num']), 0, 50) );
$process_button_string .= zen_draw_hidden_field('echeck_dl_state', substr(zen_db_prepare_input($_POST['echeck_dl_state']), 0, 2) );
$process_button_string .= zen_draw_hidden_field('echeck_dl_dob', substr(zen_db_prepare_input($_POST['echeck_dl_dob']), 0, 16) );
}
$process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
return $process_button_string;
}
/**
* Store the CC info to the order and process any results that come back from the payment gateway
*
*/
function before_process() {
global $response, $db, $order, $messageStack;
$order->info['cc_owner'] = zen_db_prepare_input($_POST['bank_acct_name']);
$order->info['cc_type'] = 'eCheck';
$order->info['cc_number'] = zen_db_prepare_input($_POST['bank_aba_code'] . '-' . str_pad(substr($_POST['bank_acct_num'], -4), strlen($_POST['bank_acct_num']), "X", STR_PAD_LEFT));
$sessID = zen_session_id();
// DATA PREPARATION SECTION
unset($submit_data); // Cleans out any previous data stored in the variable
// Create a string that contains a listing of products ordered for the description field
$description = '';
for ($i=0; $i<sizeof($order->products); $i++) {
$description .= $order->products[$i]['name'] . ' (qty: ' . $order->products[$i]['qty'] . ') + ';
}
// Remove the last "\n" from the string
$description = substr($description, 0, -2);
// Create a variable that holds the order time
$order_time = date("F j, Y, g:i a");
// Calculate the next expected order id
$last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
$new_order_id = $last_order_id->fields['orders_id'];
$new_order_id = ($new_order_id + 1);
$new_order_id = (string)$new_order_id . '-' . zen_create_random_value(6);
// Populate an array that contains all of the data to be sent to Authorize.net
$submit_data = array(
'x_login' => trim(MODULE_PAYMENT_AUTHORIZENET_ECHECK_LOGIN),
'x_tran_key' => trim(MODULE_PAYMENT_AUTHORIZENET_ECHECK_TXNKEY),
'x_relay_response' => 'FALSE', // AIM uses direct response, not relay response
'x_delim_data' => 'TRUE',
'x_delim_char' => $this->delimiter, // The default delimiter is a comma
'x_encap_char' => $this->encapChar, // The divider to encapsulate response fields
'x_version' => '3.1', // 3.1 is required to use CVV codes
'x_type' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_AUTHORIZATION_TYPE == 'Authorize' ? 'AUTH_ONLY': 'AUTH_CAPTURE',
'x_amount' => number_format($order->info['total'], 2),
'x_currency_code' => $order->info['currency'],
'x_method' => 'ECHECK',
'x_bank_aba_code' => $_POST['bank_aba_code'],
'x_bank_acct_num' => $_POST['bank_acct_num'],
'x_bank_acct_type' => $_POST['bank_acct_type'],
'x_bank_name' => $_POST['bank_name'],
'x_bank_acct_name' => $_POST['bank_acct_name'],
'x_echeck_type' => 'WEB',
'x_recurring_billing' => 'NO',
'x_email_customer' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_EMAIL_CUSTOMER == 'True' ? 'TRUE': 'FALSE',
'x_email_merchant' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_EMAIL_MERCHANT == 'True' ? 'TRUE': 'FALSE',
'x_cust_id' => $_SESSION['customer_id'],
'x_invoice_num' => (MODULE_PAYMENT_AUTHORIZENET_ECHECK_TESTMODE == 'Test' ? 'TEST-' : '') . $new_order_id,
'x_first_name' => $order->billing['firstname'],
'x_last_name' => $order->billing['lastname'],
'x_company' => $order->billing['company'],
'x_address' => $order->billing['street_address'],
'x_city' => $order->billing['city'],
'x_state' => $order->billing['state'],
'x_zip' => $order->billing['postcode'],
'x_country' => $order->billing['country']['title'],
'x_phone' => $order->customer['telephone'],
'x_email' => $order->customer['email_address'],
'x_ship_to_first_name' => $order->delivery['firstname'],
'x_ship_to_last_name' => $order->delivery['lastname'],
'x_ship_to_address' => $order->delivery['street_address'],
'x_ship_to_city' => $order->delivery['city'],
'x_ship_to_state' => $order->delivery['state'],
'x_ship_to_zip' => $order->delivery['postcode'],
'x_ship_to_country' => $order->delivery['country']['title'],
'x_description' => $description,
'x_customer_ip' => zen_get_ip_address(),
'x_po_num' => date('M-d-Y h:i:s'), //$order->info['po_number'],
'x_freight' => number_format((float)$order->info['shipping_cost'],2),
'x_tax_exempt' => 'FALSE', /* 'TRUE' or 'FALSE' */
'x_tax' => number_format((float)$order->info['tax'],2),
'x_duty' => '0',
// Additional Merchant-defined variables go here
'Date' => $order_time,
'IP' => zen_get_ip_address(),
'Session' => $sessID );
// process Wells-Fargo-SecureSource-specific parameters
if (MODULE_PAYMENT_AUTHORIZENET_ECHECK_WFSS_ENABLED == 'True') {
$submit_data['x_customer_organization_type'] = zen_db_prepare_input($_POST['echeck_customer_type']);
if (zen_db_prepare_input($_POST['echeck_customer_tax_id']) != '') {
$submit_data['x_customer_tax_id'] = zen_db_prepare_input($_POST['echeck_customer_tax_id']);
} else {
$submit_data = array_merge($submit_data,
array('x_drivers_license_num' => zen_db_prepare_input($_POST['echeck_dl_num']),
'x_drivers_license_state' => zen_db_prepare_input($_POST['echeck_dl_state']),
'x_drivers_license_dob' => zen_db_prepare_input($_POST['echeck_dl_dob']) ));
}
}
unset($response);
$response = $this->_sendRequest($submit_data);
$response_code = $response[0];
$response_text = $response[3];
$this->auth_code = $response[4];
$this->transaction_id = $response[6];
$response_msg_to_customer = $response_text . ($this->commError == '' ? '' : ' Communications Error - Please notify webmaster.');
$response['Expected-MD5-Hash'] = $this->calc_md5_response($response[6], $response[9]);
$response['HashMatchStatus'] = ($response[37] == $response['Expected-MD5-Hash']) ? 'PASS' : 'FAIL';
$this->_debugActions($response, $order_time, $sessID);
// If the MD5 hash doesn't match, then this transaction's authenticity cannot be verified.
// Thus, order will be placed in Pending status
if ($response['HashMatchStatus'] != 'PASS') {
$this->order_status = 1;
$messageStack->add_session('header', MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_AUTHENTICITY_WARNING, 'caution');
}
// If the response code is not 1 (approved) then redirect back to the payment page with the appropriate error message
if ($response_code != '1') {
$messageStack->add_session('checkout_payment', $response_msg_to_customer . ' - ' . MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_DECLINED_MESSAGE, 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
}
/**
* Post-process activities. Updates the order-status history data with the auth code from the transaction.
*
* @return boolean
*/
function after_process() {
global $insert_id, $db;
$sql = "insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_id, orders_status_id, date_added) values (:orderComments, :orderID, :orderStatus, now() )";
$sql = $db->bindVars($sql, ':orderComments', 'eCheck payment. AUTH: ' . $this->auth_code . '. TransID: ' . $this->transaction_id . '.', 'string');
$sql = $db->bindVars($sql, ':orderID', $insert_id, 'integer');
$sql = $db->bindVars($sql, ':orderStatus', $this->order_status, 'integer');
$db->Execute($sql);
return false;
}
/**
* Build admin-page components
*
* @param int $zf_order_id
* @return string
*/
function RENAME_admin_notification($zf_order_id) {
global $db;
$output = '';
$echeckdata->fields = array();
require(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/authorizenet/authorizenet_admin_notification.php');
return $output;
}
/**
* Used to display error message details
*
* @return array
*/
function get_error() {
$error = array('title' => MODULE_PAYMENT_AUTHORIZENET_ECHECK_TEXT_ERROR,
'error' => stripslashes(urldecode($_GET['error'])));
return $error;
}
/**
* Check to see whether module is installed
*
* @return boolean
*/
function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_AUTHORIZENET_ECHECK_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}
/**
* Install the payment module and its configuration settings
*
*/
function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('鎵撳紑Authorize.net (eCheck)鏀
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -