[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: pm2checkout.php 14 2006-07-28 17:42:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13    class pm2checkout {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor

  17      function pm2checkout() {
  18        global $order;
  19  
  20        $this->signature = '2checkout|pm2checkout|1.1|2.2';
  21  
  22        $this->code = 'pm2checkout';
  23        $this->title = MODULE_PAYMENT_2CHECKOUT_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_2CHECKOUT_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_2CHECKOUT_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_2CHECKOUT_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_2CHECKOUT_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_2CHECKOUT_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_2CHECKOUT_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->form_action_url = 'https://www.2checkout.com/2co/buyer/purchase';
  36      }
  37  
  38  // class methods

  39      function update_status() {
  40        global $order;
  41  
  42        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_2CHECKOUT_ZONE > 0) ) {
  43          $check_flag = false;
  44          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_2CHECKOUT_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  45          while ($check = tep_db_fetch_array($check_query)) {
  46            if ($check['zone_id'] < 1) {
  47              $check_flag = true;
  48              break;
  49            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  50              $check_flag = true;
  51              break;
  52            }
  53          }
  54  
  55          if ($check_flag == false) {
  56            $this->enabled = false;
  57          }
  58        }
  59      }
  60  
  61      function javascript_validation() {
  62        return false;
  63      }
  64  
  65      function selection() {
  66        return array('id' => $this->code,
  67                     'module' => $this->public_title . (strlen(MODULE_PAYMENT_2CHECKOUT_TEXT_PUBLIC_DESCRIPTION) > 0 ? ' (' . MODULE_PAYMENT_2CHECKOUT_TEXT_PUBLIC_DESCRIPTION . ')' : ''));
  68      }
  69  
  70      function pre_confirmation_check() {
  71        return false;
  72      }
  73  
  74      function confirmation() {
  75        return false;
  76      }
  77  
  78      function process_button() {
  79        global $HTTP_POST_VARS, $currencies, $currency, $order, $languages_id;
  80  
  81        $process_button_string = tep_draw_hidden_field('sid', MODULE_PAYMENT_2CHECKOUT_LOGIN) .
  82                                 tep_draw_hidden_field('total', number_format($order->info['total'], 2)) .
  83                                 tep_draw_hidden_field('cart_order_id', date('YmdHis')) .
  84                                 tep_draw_hidden_field('fixed', 'Y') .
  85                                 tep_draw_hidden_field('card_holder_name', $order->billing['firstname'] . ' ' . $order->billing['lastname']) .
  86                                 tep_draw_hidden_field('street_address', $order->billing['street_address']) .
  87                                 tep_draw_hidden_field('city', $order->billing['city']) .
  88                                 tep_draw_hidden_field('state', $order->billing['state']) .
  89                                 tep_draw_hidden_field('zip', $order->billing['postcode']) .
  90                                 tep_draw_hidden_field('country', $order->billing['country']['title']) .
  91                                 tep_draw_hidden_field('email', $order->customer['email_address']) .
  92                                 tep_draw_hidden_field('phone', $order->customer['telephone']) .
  93                                 tep_draw_hidden_field('ship_street_address', $order->delivery['street_address']) .
  94                                 tep_draw_hidden_field('ship_city', $order->delivery['city']) .
  95                                 tep_draw_hidden_field('ship_state', $order->delivery['state']) .
  96                                 tep_draw_hidden_field('ship_zip', $order->delivery['postcode']) .
  97                                 tep_draw_hidden_field('ship_country', $order->delivery['country']['title']);
  98  
  99        for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 100          $process_button_string .= tep_draw_hidden_field('c_prod_' . ($i+1), (int)$order->products[$i]['id'] . ',' . (int)$order->products[$i]['qty']) .
 101                                    tep_draw_hidden_field('c_name_' . ($i+1), $order->products[$i]['name']) .
 102                                    tep_draw_hidden_field('c_description_' . ($i+1), $order->products[$i]['name']) .
 103                                    tep_draw_hidden_field('c_price_' . ($i+1), tep_round(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), $currencies->currencies[$currency]['decimal_places']));
 104        }
 105  
 106        $process_button_string .= tep_draw_hidden_field('id_type', '1');
 107  
 108        if (MODULE_PAYMENT_2CHECKOUT_TESTMODE == 'Test') {
 109          $process_button_string .= tep_draw_hidden_field('demo', 'Y');
 110        }
 111  
 112        $process_button_string .= tep_draw_hidden_field('return_url', tep_href_link(FILENAME_SHOPPING_CART));
 113  
 114        $lang_query = tep_db_query("select code from " . TABLE_LANGUAGES . " where languages_id = '" . (int)$languages_id . "'");
 115        $lang = tep_db_fetch_array($lang_query);
 116  
 117        switch (strtolower($lang['code'])) {
 118          case 'es':
 119            $process_button_string .= tep_draw_hidden_field('lang', 'sp');
 120            break;
 121        }
 122  
 123        $process_button_string .= tep_draw_hidden_field('cart_brand_name', 'oscommerce') .
 124                                  tep_draw_hidden_field('cart_version_name', PROJECT_VERSION);
 125  
 126        return $process_button_string;
 127      }
 128  
 129      function before_process() {
 130        global $HTTP_POST_VARS;
 131  
 132        if ($HTTP_POST_VARS['credit_card_processed'] != 'Y') {
 133          tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_2CHECKOUT_TEXT_ERROR_MESSAGE), 'SSL', true, false));
 134        }
 135      }
 136  
 137      function after_process() {
 138        global $HTTP_POST_VARS, $order, $insert_id;
 139  
 140        if (MODULE_PAYMENT_2CHECKOUT_TESTMODE == 'Test') {
 141          $sql_data_array = array('orders_id' => (int)$insert_id, 
 142                                  'orders_status_id' => (int)$order->info['order_status'], 
 143                                  'date_added' => 'now()', 
 144                                  'customer_notified' => '0',
 145                                  'comments' => MODULE_PAYMENT_2CHECKOUT_TEXT_WARNING_DEMO_MODE);
 146  
 147          tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 148        }
 149  
 150        if (tep_not_null(MODULE_PAYMENT_2CHECKOUT_SECRET_WORD) && (MODULE_PAYMENT_2CHECKOUT_TESTMODE == 'Production')) {
 151          if (md5(MODULE_PAYMENT_2CHECKOUT_SECRET_WORD . MODULE_PAYMENT_2CHECKOUT_LOGIN . $HTTP_POST_VARS['order_number'] . number_format($order->info['total'], 2)) != $HTTP_POST_VARS['key']) {
 152            $sql_data_array = array('orders_id' => (int)$insert_id, 
 153                                    'orders_status_id' => (int)$order->info['order_status'], 
 154                                    'date_added' => 'now()', 
 155                                    'customer_notified' => '0',
 156                                    'comments' => MODULE_PAYMENT_2CHECKOUT_TEXT_WARNING_TRANSACTION_ORDER);
 157  
 158            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 159          }
 160        }
 161      }
 162  
 163      function get_error() {
 164        return false;
 165      }
 166  
 167      function check() {
 168        if (!isset($this->_check)) {
 169          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_2CHECKOUT_STATUS'");
 170          $this->_check = tep_db_num_rows($check_query);
 171        }
 172        return $this->_check;
 173      }
 174  
 175      function install() {
 176        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable 2CheckOut', 'MODULE_PAYMENT_2CHECKOUT_STATUS', 'False', 'Do you want to accept 2CheckOut payments?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 177        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Seller ID', 'MODULE_PAYMENT_2CHECKOUT_LOGIN', '', 'Seller ID used for the 2CheckOut service', '6', '0', now())");
 178        tep_db_query("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_2CHECKOUT_TESTMODE', 'Test', 'Transaction mode used for the 2Checkout service', '6', '0', 'tep_cfg_select_option(array(\'Test\', \'Production\'), ', now())");
 179        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Secret Word', 'MODULE_PAYMENT_2CHECKOUT_SECRET_WORD', '', 'The secret word to confirm transactions with (must be the same as defined on the merchat account configuration page', '6', '0', now())");
 180        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_PAYMENT_2CHECKOUT_SORT_ORDER', '0', 'Sort order of display (lowest is displayed first)', '6', '0', now())");
 181        tep_db_query("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_2CHECKOUT_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
 182        tep_db_query("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_2CHECKOUT_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 183      }
 184  
 185      function remove() {
 186        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 187      }
 188  
 189      function keys() {
 190        return array('MODULE_PAYMENT_2CHECKOUT_STATUS', 'MODULE_PAYMENT_2CHECKOUT_LOGIN', 'MODULE_PAYMENT_2CHECKOUT_TESTMODE', 'MODULE_PAYMENT_2CHECKOUT_SECRET_WORD', 'MODULE_PAYMENT_2CHECKOUT_ZONE', 'MODULE_PAYMENT_2CHECKOUT_ORDER_STATUS_ID', 'MODULE_PAYMENT_2CHECKOUT_SORT_ORDER');
 191      }
 192    }
 193  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7