📄 authorizenet.php
字号:
<?php
/**
* authorize.net SIM payment method class
*
* @package paymentMethod
* @copyright Copyright 2003-2007 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: authorizenet.php 7620 2007-12-11 19:12:46Z drbyte $
*/
/**
* authorize.net SIM payment method class
*
*/
class authorizenet extends base {
/**
* $code determines the internal 'code' name used to designate "this" payment module
*
* @var string
*/
var $code;
/**
* $title is the displayed name for this payment method
*
* @var string
*/
var $title;
/**
* $description is a soft name for this payment method
*
* @var string
*/
var $description;
/**
* $enabled determines whether this module shows or not... in catalog.
*
* @var boolean
*/
var $enabled;
/**
* log file folder
*
* @var string
*/
var $_logDir = '';
/**
* vars
*/
var $gateway_mode;
var $reportable_submit_data;
var $authorize;
var $auth_code;
var $transaction_id;
var $order_status;
/**
* @return authorizenet
*/
function authorizenet() {
global $order;
$this->code = 'authorizenet';
if (IS_ADMIN_FLAG === true) {
$this->title = MODULE_PAYMENT_AUTHORIZENET_TEXT_ADMIN_TITLE; // Payment module title in Admin
if (MODULE_PAYMENT_AUTHORIZENET_STATUS == 'True' && (MODULE_PAYMENT_AUTHORIZENET_LOGIN == 'testing' || MODULE_PAYMENT_AUTHORIZENET_TXNKEY == 'Test' || MODULE_PAYMENT_AUTHORIZENET_MD5HASH == '*Set A Hash Value at AuthNet Admin*')) {
$this->title .= '<span class="alert"> (Not Configured)</span>';
} elseif (MODULE_PAYMENT_AUTHORIZENET_TESTMODE == 'Test') {
$this->title .= '<span class="alert"> (in Testing mode)</span>';
}
} else {
$this->title = MODULE_PAYMENT_AUTHORIZENET_TEXT_CATALOG_TITLE; // Payment module title in Catalog
}
$this->description = MODULE_PAYMENT_AUTHORIZENET_TEXT_DESCRIPTION;
$this->enabled = ((MODULE_PAYMENT_AUTHORIZENET_STATUS == 'True') ? true : false);
$this->sort_order = MODULE_PAYMENT_AUTHORIZENET_SORT_ORDER;
if ((int)MODULE_PAYMENT_AUTHORIZENET_ORDER_STATUS_ID > 0) {
$this->order_status = MODULE_PAYMENT_AUTHORIZENET_ORDER_STATUS_ID;
}
if (is_object($order)) $this->update_status();
$this->form_action_url = 'https://secure.authorize.net/gateway/transact.dll';
if (AUTHORIZENET_DEVELOPER_MODE == 'on') $this->form_action_url = 'https://test.authorize.net/gateway/transact.dll';
if (AUTHORIZENET_DEVELOPER_MODE == 'echo' || MODULE_PAYMENT_AUTHORIZENET_DEBUGGING == 'echo') $this->form_action_url = 'https://developer.authorize.net/param_dump.asp';
if (AUTHORIZENET_DEVELOPER_MODE == 'certify') $this->form_action_url = 'https://certification.authorize.net/gateway/transact.dll';
$this->gateway_mode = MODULE_PAYMENT_AUTHORIZENET_GATEWAY_MODE;
$this->_logDir = DIR_FS_SQL_CACHE;
}
// Authorize.net utility functions
// DISCLAIMER:
// This code is distributed in the hope that it will be useful, but without any warranty;
// without even the implied warranty of merchantability or fitness for a particular purpose.
// Main Interfaces:
//
// function InsertFP ($loginid, $txnkey, $amount, $sequence) - Insert HTML form elements required for SIM
// function CalculateFP ($loginid, $txnkey, $amount, $sequence, $tstamp) - Returns Fingerprint.
// compute HMAC-MD5
// Uses PHP mhash extension. Be sure to enable the extension
// function hmac ($key, $data) {
// return (bin2hex (mhash(MHASH_MD5, $data, $key)));
//}
// Thanks is lance from http://www.php.net/manual/en/function.mhash.php
//lance_rushing at hot* spamfree *mail dot com
//27-Nov-2002 09:36
//
/**
* compute HMAC-MD5
*
* @param string $key
* @param string $data
* @return string
*/
function hmac ($key, $data)
{
// RFC 2104 HMAC implementation for php.
// Creates an md5 HMAC.
// Eliminates the need to install mhash to compute a HMAC
// Hacked by Lance Rushing
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*",md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad ;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*",md5($k_ipad . $data)));
}
// end code from lance (resume authorize.net code)
/**
* Inserts the hidden variables in the HTML FORM required for SIM
* Invokes hmac function to calculate fingerprint.
*
* @param string $loginid
* @param string $txnkey
* @param float $amount
* @param string $sequence
* @param float $currency
* @return string
*/
function InsertFP ($loginid, $txnkey, $amount, $sequence, $currency = "") {
$tstamp = time ();
$fingerprint = $this->hmac ($txnkey, $loginid . "^" . $sequence . "^" . $tstamp . "^" . $amount . "^" . $currency);
$security_array = array('x_fp_sequence' => $sequence,
'x_fp_timestamp' => $tstamp,
'x_fp_hash' => $fingerprint);
return $security_array;
}
// end authorize.net-provided code
// class methods
/**
* Calculate zone matches and flag settings to determine whether this module should display to customers or not
*/
function update_status() {
global $order, $db;
if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_AUTHORIZENET_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_AUTHORIZENET_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}
if ($check_flag == false) {
$this->enabled = false;
}
}
}
/**
* JS validation which does error-checking of data-entry if this module is selected for use
* (Number, Owner Lengths)
*
* @return string
*/
function javascript_validation() {
if ($this->gateway_mode == 'offsite') return '';
$js = ' if (payment_value == "' . $this->code . '") {' . "\n" .
' var cc_owner = document.checkout_payment.authorizenet_cc_owner.value;' . "\n" .
' var cc_number = document.checkout_payment.authorizenet_cc_number.value;' . "\n";
if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True') {
$js .= ' var cc_cvv = document.checkout_payment.authorizenet_cc_cvv.value;' . "\n";
}
$js .= ' if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_OWNER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" .
' if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
' error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_NUMBER . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n";
if (MODULE_PAYMENT_AUTHORIZENET_USE_CVV == 'True') {
$js .= ' if (cc_cvv == "" || cc_cvv.length < "3" || cc_cvv.length > "4") {' . "\n".
' error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_TEXT_JS_CC_CVV . '";' . "\n" .
' error = 1;' . "\n" .
' }' . "\n" ;
}
$js .= ' }' . "\n";
return $js;
}
/**
* Display Credit Card Information Submission Fields on the Checkout Payment Page
*
* @return array
*/
function selection() {
global $order;
for ($i=1; $i<13; $i++) {
$expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B - (%m)',mktime(0,0,0,$i,1,2000)));
}
$today = getdate();
for ($i=$today['year']; $i < $today['year']+10; $i++) {
$expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
}
$onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
if ($this->gateway_mode == 'offsite') {
$selection = array('id' => $this->code,
'module' => $this->title);
} else {
$selection = array('id' => $this->code,
'module' => $this->title,
'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_TEXT_CREDIT_CARD_OWNER,
'field' => zen_draw_input_field('authorizenet_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'id="'.$this->code.'-cc-owner"' . $onFocus),
'tag' => $this->code.'-cc-owner'),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -