[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/modules/payment/ -> authorizenet_aim.php (source)

   1  <?php
   2  /**

   3   * authorize.net AIM payment method class

   4   *

   5   * @package paymentMethod

   6   * @copyright Copyright 2003-2006 Zen Cart Development Team

   7   * @copyright Portions Copyright 2003 osCommerce

   8   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   9   * @version $Id: authorizenet_aim.php 5435 2006-12-28 19:09:50Z drbyte $

  10   */
  11  /**

  12   * Authorize.net Payment Module (AIM version)

  13   * You must have SSL active on your server to be compliant with merchant TOS

  14   *

  15   */
  16  class authorizenet_aim extends base {
  17    /**

  18     * $code determines the internal 'code' name used to designate "this" payment module

  19     *

  20     * @var string

  21     */
  22    var $code;
  23    /**

  24     * $title is the displayed name for this payment method

  25     *

  26     * @var string

  27     */
  28    var $title;
  29    /**

  30     * $description is a soft name for this payment method

  31     *

  32     * @var string

  33     */
  34    var $description;
  35    /**

  36     * $enabled determines whether this module shows or not... in catalog.

  37     *

  38     * @var boolean

  39     */
  40    var $enabled;
  41    /**

  42     * $response tracks response information returned from the AIM gateway

  43     *

  44     * @var string/array

  45     */
  46    var $response;
  47    /**

  48     * log file folder

  49     */
  50    var $_logDir = DIR_FS_SQL_CACHE;
  51    /**

  52       * Constructor

  53       *

  54       * @return authorizenet_aim

  55       */
  56    function authorizenet_aim() {
  57      global $order;
  58      $this->code = 'authorizenet_aim';
  59      if (IS_ADMIN_FLAG === true) {
  60        // Payment module title in Admin

  61        $this->title = MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_ADMIN_TITLE;
  62        if (MODULE_PAYMENT_AUTHORIZENET_AIM_STATUS == 'True' && (MODULE_PAYMENT_AUTHORIZENET_AIM_LOGIN == 'testing' || MODULE_PAYMENT_AUTHORIZENET_AIM_TXNKEY == 'Test')) {
  63          $this->title .=  '<span class="alert"> (Not Configured)</span>'; 
  64        } elseif (MODULE_PAYMENT_AUTHORIZENET_AIM_TESTMODE == 'Test') {
  65          $this->title .= '<span class="alert"> (in Testing mode)</span>';
  66        }
  67      } else {
  68        $this->title = MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CATALOG_TITLE; // Payment module title in Catalog

  69      }
  70      $this->description = MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_DESCRIPTION; // Descriptive Info about module in Admin

  71      $this->enabled = ((MODULE_PAYMENT_AUTHORIZENET_AIM_STATUS == 'True') ? true : false); // Whether the module is installed or not

  72      $this->sort_order = MODULE_PAYMENT_AUTHORIZENET_AIM_SORT_ORDER; // Sort Order of this payment option on the customer payment page

  73      $this->form_action_url = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', false); // Page to go to upon submitting page info

  74  
  75      if ((int)MODULE_PAYMENT_AUTHORIZENET_AIM_ORDER_STATUS_ID > 0) {
  76        $this->order_status = MODULE_PAYMENT_AUTHORIZENET_AIM_ORDER_STATUS_ID;
  77      }
  78  
  79      if (is_object($order)) $this->update_status();
  80    }
  81    /**

  82     * calculate zone matches and flag settings to determine whether this module should display to customers or not

  83     *

  84     */
  85    function update_status() {
  86      global $order, $db;
  87  
  88      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_AUTHORIZENET_AIM_ZONE > 0) ) {
  89        $check_flag = false;
  90        $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_AUTHORIZENET_AIM_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  91        while (!$check->EOF) {
  92          if ($check->fields['zone_id'] < 1) {
  93            $check_flag = true;
  94            break;
  95          } elseif ($check->fields['zone_id'] == $order->billing['zone_id']) {
  96            $check_flag = true;
  97            break;
  98          }
  99          $check->MoveNext();
 100        }
 101  
 102        if ($check_flag == false) {
 103          $this->enabled = false;
 104        }
 105      }
 106    }
 107    /**

 108     * JS validation which does error-checking of data-entry if this module is selected for use

 109     * (Number, Owner, and CVV Lengths)

 110     *

 111     * @return string

 112     */
 113    function javascript_validation() {
 114      $js = '  if (payment_value == "' . $this->code . '") {' . "\n" .
 115      '    var cc_owner = document.checkout_payment.authorizenet_aim_cc_owner.value;' . "\n" .
 116      '    var cc_number = document.checkout_payment.authorizenet_aim_cc_number.value;' . "\n";
 117      if (MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV == 'True')  {
 118        $js .= '    var cc_cvv = document.checkout_payment.authorizenet_aim_cc_cvv.value;' . "\n";
 119      }
 120      $js .= '    if (cc_owner == "" || cc_owner.length < ' . CC_OWNER_MIN_LENGTH . ') {' . "\n" .
 121      '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_JS_CC_OWNER . '";' . "\n" .
 122      '      error = 1;' . "\n" .
 123      '    }' . "\n" .
 124      '    if (cc_number == "" || cc_number.length < ' . CC_NUMBER_MIN_LENGTH . ') {' . "\n" .
 125      '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_JS_CC_NUMBER . '";' . "\n" .
 126      '      error = 1;' . "\n" .
 127      '    }' . "\n";
 128      if (MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV == 'True')  {
 129        $js .= '    if (cc_cvv == "" || cc_cvv.length < "3" || cc_cvv.length > "4") {' . "\n".
 130        '      error_message = error_message + "' . MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_JS_CC_CVV . '";' . "\n" .
 131        '      error = 1;' . "\n" .
 132        '    }' . "\n" ;
 133      }
 134      $js .= '  }' . "\n";
 135  
 136      return $js;
 137    }
 138    /**

 139     * Display Credit Card Information Submission Fields on the Checkout Payment Page

 140     *

 141     * @return array

 142     */
 143    function selection() {
 144      global $order;
 145  
 146      for ($i=1; $i<13; $i++) {
 147        $expires_month[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
 148      }
 149  
 150      $today = getdate();
 151      for ($i=$today['year']; $i < $today['year']+10; $i++) {
 152        $expires_year[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
 153      }
 154      $onFocus = ' onfocus="methodSelect(\'pmt-' . $this->code . '\')"';
 155  
 156      if (MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV == 'True') {
 157        $selection = array('id' => $this->code,
 158                           'module' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CATALOG_TITLE,
 159                           'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_OWNER,
 160                                                   'field' => zen_draw_input_field('authorizenet_aim_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'id="'.$this->code.'-cc-owner"'. $onFocus),
 161                                                   'tag' => $this->code.'-cc-owner'),
 162                                             array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_NUMBER,
 163                                                   'field' => zen_draw_input_field('authorizenet_aim_cc_number', '', 'id="'.$this->code.'-cc-number"' . $onFocus),
 164                                                   'tag' => $this->code.'-cc-number'),
 165                                             array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_EXPIRES,
 166                                                   'field' => zen_draw_pull_down_menu('authorizenet_aim_cc_expires_month', $expires_month, '', 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . '&nbsp;' . zen_draw_pull_down_menu('authorizenet_aim_cc_expires_year', $expires_year, '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
 167                                                   'tag' => $this->code.'-cc-expires-month'),
 168                                             array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CVV,
 169                                                   'field' => zen_draw_input_field('authorizenet_aim_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_AIM_TEXT_POPUP_CVV_LINK . '</a>',
 170                                                   'tag' => $this->code.'-cc-cvv')
 171               ));
 172      } else {
 173        $selection = array('id' => $this->code,
 174                           'module' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CATALOG_TITLE,
 175                           'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_OWNER,
 176                                                   'field' => zen_draw_input_field('authorizenet_aim_cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'], 'id="'.$this->code.'-cc-owner"'. $onFocus),
 177                                                   'tag' => $this->code.'-cc-owner'),
 178                                             array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_NUMBER,
 179                                                   'field' => zen_draw_input_field('authorizenet_aim_cc_number', '', 'id="'.$this->code.'-cc-number"' . $onFocus),
 180                                                   'tag' => $this->code.'-cc-number'),
 181                                             array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_EXPIRES,
 182                                                   'field' => zen_draw_pull_down_menu('authorizenet_aim_cc_expires_month', $expires_month, '', 'id="'.$this->code.'-cc-expires-month"' . $onFocus) . '&nbsp;' . zen_draw_pull_down_menu('authorizenet_aim_cc_expires_year', $expires_year, '', 'id="'.$this->code.'-cc-expires-year"' . $onFocus),
 183                                                   'tag' => $this->code.'-cc-expires-month')));
 184      }
 185      return $selection;
 186    }
 187    /**

 188     * Evaluates the Credit Card Type for acceptance and the validity of the Credit Card Number & Expiration Date

 189     *

 190     */
 191    function pre_confirmation_check() {
 192      global $_POST, $messageStack;
 193  
 194      include(DIR_WS_CLASSES . 'cc_validation.php');
 195  
 196      $cc_validation = new cc_validation();
 197      $result = $cc_validation->validate($_POST['authorizenet_aim_cc_number'], $_POST['authorizenet_aim_cc_expires_month'], $_POST['authorizenet_aim_cc_expires_year'], $_POST['authorizenet_aim_cc_cvv']);
 198      $error = '';
 199      switch ($result) {
 200        case -1:
 201        $error = sprintf(TEXT_CCVAL_ERROR_UNKNOWN_CARD, substr($cc_validation->cc_number, 0, 4));
 202        break;
 203        case -2:
 204        case -3:
 205        case -4:
 206        $error = TEXT_CCVAL_ERROR_INVALID_DATE;
 207        break;
 208        case false:
 209        $error = TEXT_CCVAL_ERROR_INVALID_NUMBER;
 210        break;
 211      }
 212  
 213      if ( ($result == false) || ($result < 1) ) {
 214        $payment_error_return = 'payment_error=' . $this->code . '&authorizenet_aim_cc_owner=' . urlencode($_POST['authorizenet_aim_cc_owner']) . '&authorizenet_aim_cc_expires_month=' . $_POST['authorizenet_aim_cc_expires_month'] . '&authorizenet_aim_cc_expires_year=' . $_POST['authorizenet_aim_cc_expires_year'];
 215        $messageStack->add_session('checkout_payment', $error . '<!-- ['.$this->code.'] -->', 'error');
 216        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
 217      }
 218  
 219      $this->cc_card_type = $cc_validation->cc_type;
 220      $this->cc_card_number = $cc_validation->cc_number;
 221      $this->cc_expiry_month = $cc_validation->cc_expiry_month;
 222      $this->cc_expiry_year = $cc_validation->cc_expiry_year;
 223    }
 224    /**

 225     * Display Credit Card Information on the Checkout Confirmation Page

 226     *

 227     * @return array

 228     */
 229    function confirmation() {
 230      global $_POST;
 231  
 232      if (MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV == 'True') {
 233        $confirmation = array(//'title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CATALOG_TITLE, // Redundant
 234                              'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_TYPE,
 235                                                      'field' => $this->cc_card_type),
 236                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_OWNER,
 237                                                      'field' => $_POST['authorizenet_aim_cc_owner']),
 238                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_NUMBER,
 239                                                      'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
 240                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_EXPIRES,
 241                                                      'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['authorizenet_aim_cc_expires_month'], 1, '20' . $_POST['authorizenet_aim_cc_expires_year']))),
 242                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CVV,
 243                                                      'field' => $_POST['authorizenet_aim_cc_cvv'])));
 244      } else {
 245        $confirmation = array(//'title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CATALOG_TITLE, // Redundant
 246                              'fields' => array(array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_TYPE,
 247                                                      'field' => $this->cc_card_type),
 248                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_OWNER,
 249                                                      'field' => $_POST['authorizenet_aim_cc_owner']),
 250                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_NUMBER,
 251                                                      'field' => substr($this->cc_card_number, 0, 4) . str_repeat('X', (strlen($this->cc_card_number) - 8)) . substr($this->cc_card_number, -4)),
 252                                                array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_CREDIT_CARD_EXPIRES,
 253                                                      'field' => strftime('%B, %Y', mktime(0,0,0,$_POST['authorizenet_aim_cc_expires_month'], 1, '20' . $_POST['authorizenet_aim_cc_expires_year'])))));
 254      }
 255      return $confirmation;
 256    }
 257    /**

 258     * Build the data and actions to process when the "Submit" button is pressed on the order-confirmation screen.

 259     * This sends the data to the payment gateway for processing.

 260     * (These are hidden fields on the checkout confirmation page)

 261     *

 262     * @return string

 263     */
 264    function process_button() {
 265      $process_button_string = zen_draw_hidden_field('cc_owner', $_POST['authorizenet_aim_cc_owner']) .
 266                               zen_draw_hidden_field('cc_expires', $this->cc_expiry_month . substr($this->cc_expiry_year, -2)) .
 267                               zen_draw_hidden_field('cc_type', $this->cc_card_type) .
 268                               zen_draw_hidden_field('cc_number', $this->cc_card_number);
 269      if (MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV == 'True') {
 270        $process_button_string .= zen_draw_hidden_field('cc_cvv', $_POST['authorizenet_aim_cc_cvv']);
 271      }
 272  
 273      $process_button_string .= zen_draw_hidden_field(zen_session_name(), zen_session_id());
 274  
 275      return $process_button_string;
 276      return false;
 277    }
 278    /**

 279     * Store the CC info to the order and process any results that come back from the payment gateway

 280     *

 281     */
 282    function before_process() {
 283      global $_POST, $response, $db, $order, $messageStack;
 284  
 285      // how many CC digits do we remember?

 286      if (MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_NUMBER == 'True') {
 287        $order->info['cc_number'] = $_POST['cc_number'];
 288      } else {
 289        $order->info['cc_number'] = str_pad(substr($_POST['cc_number'], -4), strlen($_POST['cc_number']), "X", STR_PAD_LEFT);
 290      }
 291      $order->info['cc_expires'] = $_POST['cc_expires'];
 292      $order->info['cc_type'] = $_POST['cc_type'];
 293      $order->info['cc_owner'] = $_POST['cc_owner'];
 294      $order->info['cc_cvv'] = $_POST['cc_cvv'];
 295  
 296      // DATA PREPARATION SECTION

 297      unset($submit_data);  // Cleans out any previous data stored in the variable

 298  
 299      // Create a string that contains a listing of products ordered for the description field

 300      $description = '';
 301      for ($i=0; $i<sizeof($order->products); $i++) {
 302        $description .= $order->products[$i]['name'] . '(qty: ' . $order->products[$i]['qty'] . ') + ';
 303      }
 304      // Remove the last "\n" from the string

 305      $description = substr($description, 0, -2);
 306  
 307      // Create a variable that holds the order time

 308      $order_time = date("F j, Y, g:i a");
 309  
 310      // Calculate the next expected order id

 311      $last_order_id = $db->Execute("select * from " . TABLE_ORDERS . " order by orders_id desc limit 1");
 312      $new_order_id = $last_order_id->fields['orders_id'];
 313      $new_order_id = ($new_order_id + 1);
 314  
 315      // Populate an array that contains all of the data to be sent to Authorize.net

 316      $submit_data = array(
 317                           'x_login' => MODULE_PAYMENT_AUTHORIZENET_AIM_LOGIN, // The login name is assigned by authorize.net
 318                           'x_tran_key' => MODULE_PAYMENT_AUTHORIZENET_AIM_TXNKEY,  // The Transaction Key is generated through the merchant interface
 319                           'x_relay_response' => 'FALSE', // AIM uses direct response, not relay response
 320                           'x_delim_data' => 'TRUE', // The default delimiter is a comma
 321                           'x_version' => '3.1',  // 3.1 is required to use CVV codes
 322                           'x_type' => MODULE_PAYMENT_AUTHORIZENET_AIM_AUTHORIZATION_TYPE == 'Authorize' ? 'AUTH_ONLY': 'AUTH_CAPTURE',
 323                           'x_method' => 'CC', //MODULE_PAYMENT_AUTHORIZENET_AIM_METHOD == 'Credit Card' ? 'CC' : 'ECHECK',
 324                           'x_amount' => number_format($order->info['total'], 2),
 325                           'x_card_num' => $_POST['cc_number'],
 326                           'x_exp_date' => $_POST['cc_expires'],
 327                           'x_card_code' => $_POST['cc_cvv'],
 328                           'x_email_customer' => MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_CUSTOMER == 'True' ? 'TRUE': 'FALSE',
 329                           'x_email_merchant' => MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_MERCHANT == 'True' ? 'TRUE': 'FALSE',
 330                           'x_cust_id' => $_SESSION['customer_id'],
 331                           'x_invoice_num' => (MODULE_PAYMENT_AUTHORIZENET_AIM_TESTMODE == 'Test' ? 'TEST-' : '') . $new_order_id,
 332                           'x_first_name' => $order->billing['firstname'],
 333                           'x_last_name' => $order->billing['lastname'],
 334                           'x_company' => $order->billing['company'],
 335                           'x_address' => $order->billing['street_address'],
 336                           'x_city' => $order->billing['city'],
 337                           'x_state' => $order->billing['state'],
 338                           'x_zip' => $order->billing['postcode'],
 339                           'x_country' => $order->billing['country']['title'],
 340                           'x_phone' => $order->customer['telephone'],
 341                           'x_email' => $order->customer['email_address'],
 342                           'x_ship_to_first_name' => $order->delivery['firstname'],
 343                           'x_ship_to_last_name' => $order->delivery['lastname'],
 344                           'x_ship_to_address' => $order->delivery['street_address'],
 345                           'x_ship_to_city' => $order->delivery['city'],
 346                           'x_ship_to_state' => $order->delivery['state'],
 347                           'x_ship_to_zip' => $order->delivery['postcode'],
 348                           'x_ship_to_country' => $order->delivery['country']['title'],
 349                           'x_description' => $description,
 350                           // Merchant defined variables go here

 351                           'Date' => $order_time,
 352                           'IP' => $_SERVER['REMOTE_ADDR'],
 353                           'Session' => zen_session_id());
 354  
 355      if(MODULE_PAYMENT_AUTHORIZENET_AIM_TESTMODE == 'Test') {
 356        $submit_data['x_test_request'] = 'TRUE';
 357      }
 358  
 359      // concatenate the submission data and put into $data variable

 360      while(list($key, $value) = each($submit_data)) {
 361        $data .= $key . '=' . urlencode(ereg_replace(',', '', $value)) . '&';
 362      }
 363      // Remove the last "&" from the string

 364      $data = substr($data, 0, -1);
 365  
 366  
 367      // prepare a copy of submitted data for error-reporting purposes

 368      $reportable_submit_data = $submit_data;
 369      $reportable_submit_data['x_login'] = '*******';
 370      $reportable_submit_data['x_tran_key'] = '*******';
 371      $reportable_submit_data['x_card_num'] = '*******' . substr($reportable_submit_data['x_card_num'], -4);
 372      $reportable_submit_data['x_card_code'] = '*******';
 373  
 374  
 375      // SEND DATA BY CURL SECTION

 376      // Post order info data to Authorize.net, make sure you have cURL support installed

 377  
 378      unset($response);
 379  
 380      $url = 'https://secure.authorize.net/gateway/transact.dll';
 381      if (AUTHORIZENET_DEVELOPER_MODE == 'on') $url = 'https://test.authorize.net/gateway/transact.dll';
 382      if (AUTHORIZENET_DEVELOPER_MODE == 'certify') $url = 'https://certification.authorize.net/gateway/transact.dll';
 383      $reportable_submit_data['url'] = $url;
 384  
 385  
 386      // The commented line below is an alternate connection method

 387      //exec("/usr/bin/curl -d \"$data\" $url", $response);

 388  
 389  
 390      $ch = curl_init();
 391      curl_setopt($ch, CURLOPT_URL,$url);
 392      curl_setopt($ch, CURLOPT_VERBOSE, 0);
 393      curl_setopt($ch, CURLOPT_POST, 1);
 394      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 395      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 396      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); /* compatibility for SSL communications on some Windows servers (IIS 5.0+) */
 397      if (CURL_PROXY_REQUIRED == 'True') {
 398        $proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
 399        curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
 400        curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
 401        curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
 402      }
 403  
 404      $authorize = curl_exec($ch);
 405      $commError = curl_error($ch);
 406      $commInfo = @curl_getinfo($ch);
 407      curl_close ($ch);
 408  
 409      $response = split('\,', $authorize);
 410  
 411      $response_code = explode(',', $response[0]);
 412      $response_text = explode(',', $response[3]);
 413      $transaction_id = explode(',', $response[6]);
 414      $authorization_type = explode(',', $response[11]);
 415      $auth_code = explode(',', $response[4]);
 416      $this->auth_code = $auth_code[0];
 417      $this->transaction_id = $transaction_id[0];
 418      // Parse the response code and text for custom error display

 419      $x_response_code = $response_code[0];
 420      $x_response_text = $response_text[0] . ($commError == '' ? '' : 'Communications Error - Please notify webmaster. ');
 421  
 422  
 423  
 424      // DEBUG LOGGING

 425      if ($x_response_code != '1' || (defined('AUTHORIZENET_DEVELOPER_MODE') && in_array(AUTHORIZENET_DEVELOPER_MODE, array('on', 'certifiy'))) || strstr(MODULE_PAYMENT_AUTHORIZENET_AIM_DEBUGGING, 'All')) {
 426        $errorMessage = date('M-d-Y h:i:s') . "\n=================================\n\n" . ($commError !='' ? 'Comm results: ' . $commError . "\n\n" : '') . 'Response Code: ' . print_r($response_code, true) . ' ' . print_r($response_text, true) . 'Sending to Authorizenet: ' . print_r($reportable_submit_data, true) . "\n\n" . 'Result: ' . print_r($response, true) . "\n\n" . 'CURL info: ' . print_r($commInfo, true) . "\n";
 427        if (CURL_PROXY_REQUIRED == 'True') $errorMessage .= 'Using CURL Proxy: [' . CURL_PROXY_SERVER_DETAILS . ']  with Proxy Tunnel: ' .($proxy_tunnel_flag ? 'On' : 'Off') . "\n";
 428  
 429        if (strstr(MODULE_PAYMENT_AUTHORIZENET_AIM_DEBUGGING, 'Log')) {
 430          $key = time() . '_' . zen_create_random_value(4);
 431          $file = $this->_logDir . '/' . 'AIM_Debug_' . $key . '.log';
 432          $fp = @fopen($file, 'a');
 433          @fwrite($fp, $errorMessage);
 434          @fclose($fp);
 435        }
 436        if (strstr(MODULE_PAYMENT_AUTHORIZENET_AIM_DEBUGGING, 'Email')) {
 437          zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'AuthorizenetAIM Debug Data', $errorMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 438        }
 439      }
 440  
 441      // DATABASE SECTION

 442      // Insert the send and receive response data into the database.

 443      // This can be used for testing or for implementation in other applications

 444      // This can be turned on and off if the Admin Section

 445      if (MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_DATA == 'True'){
 446  
 447        // Create a string from all of the response data for insertion into the database

 448        while(list($key, $value) = each($response)) {
 449          $response_list .= ($key +1) . '=' . urlencode(ereg_replace(',', '', $value)) . '&';
 450        }
 451  
 452        // Remove the last "&" from the string

 453        $response_list = substr($response_list, 0, -1);
 454  
 455        $db_response_code = $response_code[0];
 456        $db_response_text = $response_text[0];
 457        $db_transaction_id = $transaction_id[0];
 458        $db_authorization_type = $authorization_type[0];
 459        $db_session_id = zen_session_id();
 460  
 461  
 462        // Insert the data into the database

 463        $db->Execute("insert into " . TABLE_AUTHORIZENET . "  (id, customer_id,order_id, response_code, response_text, authorization_type, transaction_id, sent, received, time, session_id) values ('', '" . $_SESSION['customer_id'] . "', '" . $new_order_id . "', '" . $db_response_code . "', '" . $db_response_text . "', '" . $db_authorization_type . "', '" . $db_transaction_id . "', '" . print_r($reportable_submit_data, true) . "', '" . $response_list . "', '" . $order_time . "', '" . $db_session_id . "')");
 464      }
 465  
 466      // If the response code is not 1 (approved) then redirect back to the payment page with the appropriate error message

 467      if ($x_response_code != '1') {
 468        $messageStack->add_session('checkout_payment', $x_response_text . ' - ' . MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_DECLINED_MESSAGE, 'error');
 469        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false));
 470      }
 471    }
 472    /**

 473     * Post-process activities.

 474     *

 475     * @return boolean

 476     */
 477    function after_process() {
 478      global $insert_id, $db;
 479      $db->Execute("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (comments, orders_id, orders_status_id, date_added) values ('Credit Card payment.  AUTH: " . $this->auth_code . ". TransID: " . $this->transaction_id . ".' , '". (int)$insert_id . "','" . $this->order_status . "', now() )");
 480      return false;
 481    }
 482    /**

 483     * Used to display error message details

 484     *

 485     * @return array

 486     */
 487    function get_error() {
 488      global $_GET;
 489  
 490      $error = array('title' => MODULE_PAYMENT_AUTHORIZENET_AIM_TEXT_ERROR,
 491                     'error' => stripslashes(urldecode($_GET['error'])));
 492  
 493      return $error;
 494    }
 495    /**

 496     * Check to see whether module is installed

 497     *

 498     * @return boolean

 499     */
 500    function check() {
 501      global $db;
 502      if (!isset($this->_check)) {
 503        $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_AUTHORIZENET_AIM_STATUS'");
 504        $this->_check = $check_query->RecordCount();
 505      }
 506      return $this->_check;
 507    }
 508    /**

 509     * Install the payment module and its configuration settings

 510     *

 511     */
 512    function install() {
 513      global $db;
 514      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Authorize.net (AIM) Module', 'MODULE_PAYMENT_AUTHORIZENET_AIM_STATUS', 'True', 'Do you want to accept Authorize.net payments via the AIM Method?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 515      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Login ID', 'MODULE_PAYMENT_AUTHORIZENET_AIM_LOGIN', 'testing', 'The API Login ID used for the Authorize.net service', '6', '0', now())");
 516      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Transaction Key', 'MODULE_PAYMENT_AUTHORIZENET_AIM_TXNKEY', 'Test', 'Transaction Key used for encrypting TP data<br />(See your Authorizenet Account->Security Settings->API Login ID and Transaction Key for details.)', '6', '0', now())"); 
 517  // Future: set_function, use_function ... 'zen_cfg_password_input(', 'zen_cfg_password_display'

 518      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Transaction Mode', 'MODULE_PAYMENT_AUTHORIZENET_AIM_TESTMODE', 'Test', 'Transaction mode used for processing orders', '6', '0', 'zen_cfg_select_option(array(\'Test\', \'Production\'), ', now())");
 519      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Authorization Type', 'MODULE_PAYMENT_AUTHORIZENET_AIM_AUTHORIZATION_TYPE', 'Authorize', 'Do you want submitted credit card transactions to be authorized only, or authorized and captured?', '6', '0', 'zen_cfg_select_option(array(\'Authorize\', \'Authorize/Capture\'), ', now())");
 520      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Database Storage', 'MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_DATA', 'False', 'Do you want to save the gateway data to the database?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 521      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Customer Notifications', 'MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_CUSTOMER', 'False', 'Should Authorize.Net email a receipt to the customer?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 522      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Merchant Notifications', 'MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_MERCHANT', 'False', 'Should Authorize.Net email a receipt to the merchant?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 523      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Request CVV Number', 'MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV', 'True', 'Do you want to ask the customer for the card\'s CVV number', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 524      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Store the Credit Card Number', 'MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_NUMBER', 'False', 'Do you want to store the Credit Card Number. Security Note: The Credit Card Number will be stored <strong>unenecrypted</strong>.<br /><strong>Recommended: False</strong>', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
 525      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_AUTHORIZENET_AIM_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 526      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_AUTHORIZENET_AIM_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
 527      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Order Status', 'MODULE_PAYMENT_AUTHORIZENET_AIM_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'zen_cfg_pull_down_order_statuses(', 'zen_get_order_status_name', now())");
 528      $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Debug Mode', 'MODULE_PAYMENT_AUTHORIZENET_AIM_DEBUGGING', 'Off', 'Would you like to enable debug mode?  A complete detailed log of failed transactions may be emailed to the store owner.', '6', '0', 'zen_cfg_select_option(array(\'Off\', \'Log File\', \'Log and Email\'), ', now())");
 529    }
 530    /**

 531     * Remove the module and all its settings

 532     *

 533     */
 534    function remove() {
 535      global $db;
 536      $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 537    }
 538    /**

 539     * Internal list of configuration keys used for configuration of the module

 540     *

 541     * @return array

 542     */
 543    function keys() {
 544      return array('MODULE_PAYMENT_AUTHORIZENET_AIM_STATUS', 'MODULE_PAYMENT_AUTHORIZENET_AIM_LOGIN', 'MODULE_PAYMENT_AUTHORIZENET_AIM_TXNKEY', 'MODULE_PAYMENT_AUTHORIZENET_AIM_TESTMODE', 'MODULE_PAYMENT_AUTHORIZENET_AIM_AUTHORIZATION_TYPE', 'MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_DATA', 'MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_CUSTOMER', 'MODULE_PAYMENT_AUTHORIZENET_AIM_EMAIL_MERCHANT', 'MODULE_PAYMENT_AUTHORIZENET_AIM_USE_CVV', 'MODULE_PAYMENT_AUTHORIZENET_AIM_STORE_NUMBER', 'MODULE_PAYMENT_AUTHORIZENET_AIM_SORT_ORDER', 'MODULE_PAYMENT_AUTHORIZENET_AIM_ZONE', 'MODULE_PAYMENT_AUTHORIZENET_AIM_ORDER_STATUS_ID', 'MODULE_PAYMENT_AUTHORIZENET_AIM_DEBUGGING'); //'MODULE_PAYMENT_AUTHORIZENET_AIM_METHOD'

 545    }
 546  }
 547  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics