📄 authorizenet.php
字号:
array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_NUMBER,
'field' => zen_draw_input_field('authorizenet_cc_number', '', 'id="'.$this->code.'-cc-number"' . $onFocus),
'tag' => $this->code.'-cc-number'),
array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_EXPIRES,
'field' => zen_draw_pull_down_menu('authorizenet_cc_expires_month', $expires_month, '', 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . ' ' . zen_draw_pull_down_menu('authorizenet_cc_expires_year', $expires_year, '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
'tag' => $this->code.'-cc-expires-month')));
if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True') {
$selection['fields'][] = array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CVV,
'field' => zen_draw_input_field('authorizenet_cc_cvv', '', 'size="4", maxlength="4"' . ' id="'.$this->code.'-cc-cvv"' . $onFocus) . ' ' . '<a href="javascript:popupWindow(\'' . zen_href_link(FILENAME_POPUP_CVV_HELP) . '\')">' . MODULE_PAYMENT_AUTHORIZENET_TEXT_POPUP_CVV_LINK . '</a>',
'tag' => $this->code.'-cc-cvv');
}
}
return $selection;
}
/**
* Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date
*
*/
function pre_confirmation_check() {
global $messageStack;
if (isset($_POST['authorizenet_cc_number'])) {
include(DIR_WS_CLASSES . 'cc_validation.php');
$cc_validation = new cc_validation();
$result = $cc_validation->validate($_POST['authorizenet_cc_number'], $_POST['authorizenet_cc_expires_month'], $_POST['authorizenet_cc_expires_year']);
$error = '';
switch ($result) {
case -1:
$error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
break;
case -2:
case -3:
case -4:
$error = TEXT_CCVAL_ERROR_INVALID_DATE;
break;
case false:
$error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
break;
}
if ( ($result == false) || ($result < 1) ) {
$payment_error_return = 'payment_error=' . $this->code . 'authorizenet_cc_owner=' . urlencode($_POST['authorizenet_cc_owner']) . '&authorizenet_cc_expires_month=' . $_POST['authorizenet_cc_expires_month'] . '&authorizenet_cc_expires_year=' . $_POST['authorizenet_cc_expires_year'];
$messageStack->add_session('checkout_payment', $error . '<!-- ['.$this->code.'] -->', 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
}
$this->cc_card_type = $cc_validation->cc_type;
$this->cc_card_number = $cc_validation->cc_number;
$this->cc_expiry_month = $cc_validation->cc_expiry_month;
$this->cc_expiry_year = $cc_validation->cc_expiry_year;
}
}
/**
* Display Credit Card Information on the Checkout Confirmation Page
*
* @return array
*/
function confirmation() {
if (isset($_POST['authorizenet_cc_number'])) {
$confirmation = array('title' => $this->title . ': ' . $this->cc_card_type,
'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_OWNER,
'field' => $_POST['authorizenet_cc_owner']),
array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_NUMBER,
'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_EXPIRES,
'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['authorizenet_cc_expires_month'], 1, '20' . $_POST['authorizenet_cc_expires_year'])))));
} else {
$confirmation = array(); //array('title' => $this->title);
}
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() {
global $order;
$sequence = rand(1, 1000);
$submit_data_core = array(
'x_login' => MODULE_PAYMENT_AUTHORIZENET_LOGIN,
'x_amount' => number_format($order->info['total'], 2),
//'x_currency_code' => $_SESSION['currency'],
'x_version' => '3.0',
'x_method' => ((MODULE_PAYMENT_AUTHORIZENET_METHOD == 'Credit Card') ? 'CC' : 'ECHECK'),
'x_type' => MODULE_PAYMENT_AUTHORIZENET_AUTHORIZATION_TYPE == 'Authorize' ? 'auth_only': 'auth_capture',
'x_cust_ID' => $_SESSION['customer_id'],
'x_email_customer' => ((MODULE_PAYMENT_AUTHORIZENET_EMAIL_CUSTOMER == 'True') ? 'TRUE': 'FALSE'),
'x_company' => $order->billing['company'],
'x_first_name' => $order->billing['firstname'],
'x_last_name' => $order->billing['lastname'],
'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_fax' => $order->customer['fax'],
'x_email' => $order->customer['email_address'],
'x_ship_to_company' => $order->delivery['company'],
'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_Customer_IP' => zen_get_ip_address(),
'x_relay_form' => 'TRUE',
'x_relay_URL' => zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true, false),
'x_invoice_num' => '',
'x_description' => 'Website Purchase from ' . str_replace('"',"'", STORE_NAME),
'x_duplicate_window' => '120');
$submit_data_security = $this->InsertFP(MODULE_PAYMENT_AUTHORIZENET_LOGIN, MODULE_PAYMENT_AUTHORIZENET_TXNKEY, number_format($order->info['total'], 2), $sequence);
$submit_data_offline = array(
'x_show_form' => 'PAYMENT_FORM',
'x_receipt_link_method' => 'POST',
'x_receipt_link_text' => 'Click here to complete your order.',
'x_receipt_link_url' => zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false)
);
//The following can be set in the authnet account admin area instead of here
$submit_data_extras = array(
// 'x_header_email_receipt' => '',
// 'x_footer_email_receipt' => '',
// 'x_header_html_payment_form' => '',
// 'x_footer_html_payment_form' => '',
// 'x_header_html_receipt' => '',
// 'x_footer_html_receipt' => '',
// 'x_logo_url' => '',
// 'x_background_url' => '',
// 'x_color_link' => '',
// 'x_color_background' => '',
// 'x_color_text' => ''
);
$submit_data_onsite = array(
'x_card_num' => $this->cc_card_number,
'x_exp_date' => $this->cc_expiry_month . substr($this->cc_expiry_year, -2));
if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True') {
$submit_data_core['x_version'] = '3.1';
if ($this->gateway_mode == 'onsite') $submit_data_onsite['x_card_code'] = $_POST['authorizenet_cc_cvv'];
}
if ($this->gateway_mode == 'onsite') {
$submit_data = array_merge($submit_data_core, $submit_data_security, $submit_data_onsite);
} else {
$submit_data = array_merge($submit_data_core, $submit_data_security, $submit_data_offline, $submit_data_extras);
}
if (MODULE_PAYMENT_AUTHORIZENET_TESTMODE == 'Test') $submit_data['x_Test_Request'] = 'TRUE';
$submit_data[zen_session_name()] = zen_session_id();
$process_button_string = "\n";
foreach($submit_data as $key => $value) {
$process_button_string .= zen_draw_hidden_field($key, $value) . "\n";
}
// prepare a copy of submitted data for error-reporting purposes
$this->reportable_submit_data = $submit_data;
$this->reportable_submit_data['x_login'] = '*******';
if (isset($this->reportable_submit_data['x_tran_key'])) $this->reportable_submit_data['x_tran_key'] = '*******';
if (isset($this->reportable_submit_data['x_card_num'])) $this->reportable_submit_data['x_card_num'] = str_repeat('X', strlen($this->reportable_submit_data['x_card_num'] - 4)) . substr($this->reportable_submit_data['x_card_num'], -4);
// if (isset($this->reportable_submit_data['x_card_code'])) $this->reportable_submit_data['x_card_code'] = '*******';
$this->reportable_submit_data['url'] = $url;
$this->_debugActions($this->reportable_submit_data, 'Submit-Data', '', 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 $messageStack;
$this->authorize = $_POST;
unset($this->authorize['btn_submit_x'], $this->authorize['btn_submit_y']);
$this->authorize['HashValidationValue'] = $this->calc_md5_response($this->authorize['x_trans_id'], $this->authorize['x_amount']);
$this->authorize['HashMatchStatus'] = ($this->authorize['x_MD5_Hash'] == $this->authorize['HashValidationValue']) ? 'PASS' : 'FAIL';
$this->_debugActions($this->authorize, 'Response-Data', '', zen_session_id());
// if in 'echo' mode, dump the returned data to the browser and stop execution
if (AUTHORIZENET_DEVELOPER_MODE == 'echo' || MODULE_PAYMENT_AUTHORIZENET_DEBUGGING == 'echo') {
echo 'Returned Response Codes:<br /><pre>' . print_r($_POST, true) . '</pre><br />';
die('Press the BACK button in your browser to return to the previous page.');
}
if ($this->authorize['x_response_code'] == '1'
// && $this->authorize['x_type'] == $this->submit_data['x_type']
// && $this->authorize['x_method'] == $this->submit_data['x_method']
// && $this->authorize['x_amount'] == $this->submit_data['x_amount']
// && $this->authorize['x_invoice_num'] == $this->submit_data['x_invoice_num']
// && $this->authorize['x_description'] == $this->submit_data['x_description']
&& $this->authorize['x_MD5_Hash'] == $this->authorize['HashValidationValue']) {
$this->auth_code = $this->authorize['x_auth_code'];
$this->transaction_id = $this->authorize['x_trans_id'];
return;
}
if ($this->authorize['x_response_code'] == '2') {
$messageStack->add_session('checkout_payment', $this->authorize['x_response_reason_text'] . MODULE_PAYMENT_AUTHORIZENET_TEXT_DECLINED_MESSAGE, 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
// Code 3 or anything else is an error
$messageStack->add_session('checkout_payment', MODULE_PAYMENT_AUTHORIZENET_TEXT_ERROR_MESSAGE, 'error');
zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
}
/**
* Post-processing activities
*
* @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', 'Credit Card 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;
}
/**
* 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_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鏀
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -