[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: worldpay_junior.php 1807 2008-01-13 00:50:08Z user $
   4  
   5    osCMax Power E-Commerce
   6    http://oscdox.com
   7  
   8    Copyright 2008 osCMax
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class worldpay_junior {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function worldpay_junior() {
  18        global $order;
  19  
  20        $this->signature = 'worldpay|worldpay_junior|1.0|2.2';
  21  
  22        $this->code = 'worldpay_junior';
  23        $this->title = MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_WORLDPAY_JUNIOR_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_WORLDPAY_JUNIOR_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->form_action_url = 'https://select.worldpay.com/wcc/purchase';
  36      }
  37  
  38  // class methods
  39      function update_status() {
  40        global $order;
  41  
  42        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_WORLDPAY_JUNIOR_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_WORLDPAY_JUNIOR_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        global $cart_Worldpay_Junior_ID;
  67  
  68        if (tep_session_is_registered('cart_Worldpay_Junior_ID')) {
  69          $order_id = substr($cart_Worldpay_Junior_ID, strpos($cart_Worldpay_Junior_ID, '-')+1);
  70  
  71          $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
  72  
  73          if (tep_db_num_rows($check_query) < 1) {
  74            tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
  75            tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
  76            tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
  77            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
  78            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
  79            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
  80  
  81            tep_session_unregister('cart_Worldpay_Junior_ID');
  82          }
  83        }
  84  
  85        return array('id' => $this->code,
  86                     'module' => $this->public_title);
  87      }
  88  
  89      function pre_confirmation_check() {
  90        global $cartID, $cart;
  91  
  92        if (empty($cart->cartID)) {
  93          $cartID = $cart->cartID = $cart->generate_cart_id();
  94        }
  95  
  96        if (!tep_session_is_registered('cartID')) {
  97          tep_session_register('cartID');
  98        }
  99      }
 100  
 101      function confirmation() {
 102        global $cartID, $cart_Worldpay_Junior_ID, $customer_id, $languages_id, $order, $order_total_modules;
 103  
 104        $insert_order = false;
 105  
 106        if (tep_session_is_registered('cart_Worldpay_Junior_ID')) {
 107          $order_id = substr($cart_Worldpay_Junior_ID, strpos($cart_Worldpay_Junior_ID, '-')+1);
 108  
 109          $curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 110          $curr = tep_db_fetch_array($curr_check);
 111  
 112          if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_Worldpay_Junior_ID, 0, strlen($cartID))) ) {
 113            $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
 114  
 115            if (tep_db_num_rows($check_query) < 1) {
 116              tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
 117              tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
 118              tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
 119              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
 120              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
 121              tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
 122            }
 123  
 124            $insert_order = true;
 125          }
 126        } else {
 127          $insert_order = true;
 128        }
 129  
 130        if ($insert_order == true) {
 131          $order_totals = array();
 132          if (is_array($order_total_modules->modules)) {
 133            reset($order_total_modules->modules);
 134            while (list(, $value) = each($order_total_modules->modules)) {
 135              $class = substr($value, 0, strrpos($value, '.'));
 136              if ($GLOBALS[$class]->enabled) {
 137                for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
 138                  if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
 139                    $order_totals[] = array('code' => $GLOBALS[$class]->code,
 140                                            'title' => $GLOBALS[$class]->output[$i]['title'],
 141                                            'text' => $GLOBALS[$class]->output[$i]['text'],
 142                                            'value' => $GLOBALS[$class]->output[$i]['value'],
 143                                            'sort_order' => $GLOBALS[$class]->sort_order);
 144                  }
 145                }
 146              }
 147            }
 148          }
 149  
 150          $sql_data_array = array('customers_id' => $customer_id,
 151                                  'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
 152                                  'customers_company' => $order->customer['company'],
 153                                  'customers_street_address' => $order->customer['street_address'],
 154                                  'customers_suburb' => $order->customer['suburb'],
 155                                  'customers_city' => $order->customer['city'],
 156                                  'customers_postcode' => $order->customer['postcode'],
 157                                  'customers_state' => $order->customer['state'],
 158                                  'customers_country' => $order->customer['country']['title'],
 159                                  'customers_telephone' => $order->customer['telephone'],
 160                                  'customers_email_address' => $order->customer['email_address'],
 161                                  'customers_address_format_id' => $order->customer['format_id'],
 162                                  'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
 163                                  'delivery_company' => $order->delivery['company'],
 164                                  'delivery_street_address' => $order->delivery['street_address'],
 165                                  'delivery_suburb' => $order->delivery['suburb'],
 166                                  'delivery_city' => $order->delivery['city'],
 167                                  'delivery_postcode' => $order->delivery['postcode'],
 168                                  'delivery_state' => $order->delivery['state'],
 169                                  'delivery_country' => $order->delivery['country']['title'],
 170                                  'delivery_address_format_id' => $order->delivery['format_id'],
 171                                  'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],
 172                                  'billing_company' => $order->billing['company'],
 173                                  'billing_street_address' => $order->billing['street_address'],
 174                                  'billing_suburb' => $order->billing['suburb'],
 175                                  'billing_city' => $order->billing['city'],
 176                                  'billing_postcode' => $order->billing['postcode'],
 177                                  'billing_state' => $order->billing['state'],
 178                                  'billing_country' => $order->billing['country']['title'],
 179                                  'billing_address_format_id' => $order->billing['format_id'],
 180                                  'payment_method' => $order->info['payment_method'],
 181                                  'cc_type' => $order->info['cc_type'],
 182                                  'cc_owner' => $order->info['cc_owner'],
 183                                  'cc_number' => $order->info['cc_number'],
 184                                  'cc_expires' => $order->info['cc_expires'],
 185                                  'date_purchased' => 'now()',
 186                                  'orders_status' => $order->info['order_status'],
 187                                  'currency' => $order->info['currency'],
 188                                  'currency_value' => $order->info['currency_value']);
 189  
 190          tep_db_perform(TABLE_ORDERS, $sql_data_array);
 191  
 192          $insert_id = tep_db_insert_id();
 193  
 194          for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 195            $sql_data_array = array('orders_id' => $insert_id,
 196                                    'title' => $order_totals[$i]['title'],
 197                                    'text' => $order_totals[$i]['text'],
 198                                    'value' => $order_totals[$i]['value'],
 199                                    'class' => $order_totals[$i]['code'],
 200                                    'sort_order' => $order_totals[$i]['sort_order']);
 201  
 202            tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
 203          }
 204  
 205          for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 206            $sql_data_array = array('orders_id' => $insert_id,
 207                                    'products_id' => tep_get_prid($order->products[$i]['id']),
 208                                    'products_model' => $order->products[$i]['model'],
 209                                    'products_name' => $order->products[$i]['name'],
 210                                    'products_price' => $order->products[$i]['price'],
 211                                    'final_price' => $order->products[$i]['final_price'],
 212                                    'products_tax' => $order->products[$i]['tax'],
 213                                    'products_quantity' => $order->products[$i]['qty']);
 214  
 215            tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
 216  
 217            $order_products_id = tep_db_insert_id();
 218  
 219            $attributes_exist = '0';
 220            if (isset($order->products[$i]['attributes'])) {
 221              $attributes_exist = '1';
 222              for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 223                if (DOWNLOAD_ENABLED == 'true') {
 224                  $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename
 225                                       from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 226                                       left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 227                                       on pa.products_attributes_id=pad.products_attributes_id
 228                                       where pa.products_id = '" . $order->products[$i]['id'] . "'
 229                                       and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 230                                       and pa.options_id = popt.products_options_id
 231                                       and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 232                                       and pa.options_values_id = poval.products_options_values_id
 233                                       and popt.language_id = '" . $languages_id . "'
 234                                       and poval.language_id = '" . $languages_id . "'";
 235                  $attributes = tep_db_query($attributes_query);
 236                } else {
 237                  $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 238                }
 239                $attributes_values = tep_db_fetch_array($attributes);
 240  
 241                $sql_data_array = array('orders_id' => $insert_id,
 242                                        'orders_products_id' => $order_products_id,
 243                                        'products_options' => $attributes_values['products_options_name'],
 244                                        'products_options_values' => $attributes_values['products_options_values_name'],
 245                                        'options_values_price' => $attributes_values['options_values_price'],
 246                                        'price_prefix' => $attributes_values['price_prefix']);
 247  
 248                tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
 249  
 250                if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
 251                  $sql_data_array = array('orders_id' => $insert_id,
 252                                          'orders_products_id' => $order_products_id,
 253                                          'orders_products_filename' => $attributes_values['products_attributes_filename'],
 254                                          'download_maxdays' => $attributes_values['products_attributes_maxdays'],
 255                                          'download_count' => $attributes_values['products_attributes_maxcount']);
 256  
 257                  tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
 258                }
 259              }
 260            }
 261          }
 262  
 263          $cart_Worldpay_Junior_ID = $cartID . '-' . $insert_id;
 264          tep_session_register('cart_Worldpay_Junior_ID');
 265        }
 266  
 267        return false;
 268      }
 269  
 270      function process_button() {
 271        global $order, $currency, $languages_id, $language, $customer_id, $cart_Worldpay_Junior_ID;
 272  
 273        $order_id = substr($cart_Worldpay_Junior_ID, strpos($cart_Worldpay_Junior_ID, '-')+1);
 274  
 275        $lang_query = tep_db_query("select code from " . TABLE_LANGUAGES . " where languages_id = '" . (int)$languages_id . "'");
 276        $lang = tep_db_fetch_array($lang_query);
 277  
 278        $process_button_string = tep_draw_hidden_field('instId', MODULE_PAYMENT_WORLDPAY_JUNIOR_INSTALLATION_ID) .
 279                                 tep_draw_hidden_field('amount', $this->format_raw($order->info['total'])) .
 280                                 tep_draw_hidden_field('currency', $currency) .
 281                                 tep_draw_hidden_field('hideCurrency', 'true') .
 282                                 tep_draw_hidden_field('cartId', $order_id) .
 283                                 tep_draw_hidden_field('desc', STORE_NAME) .
 284                                 tep_draw_hidden_field('name', $order->billing['firstname'] . ' ' . $order->billing['lastname']) .
 285                                 tep_draw_hidden_field('address', $order->billing['street_address']) .
 286                                 tep_draw_hidden_field('postcode', $order->billing['postcode']) .
 287                                 tep_draw_hidden_field('country', $order->billing['country']['iso_code_2']) .
 288                                 tep_draw_hidden_field('tel', $order->customer['telephone']) .
 289                                 tep_draw_hidden_field('email', $order->customer['email_address']) .
 290                                 tep_draw_hidden_field('fixContact', 'Y') .
 291                                 tep_draw_hidden_field('lang', strtoupper($lang['code'])) .
 292                                 tep_draw_hidden_field('signatureFields', 'amount:currency:cartId') .
 293                                 tep_draw_hidden_field('signature', md5(MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD . ':' . $this->format_raw($order->info['total']) . ':' . $currency . ':' . $order_id)) .
 294                                 tep_draw_hidden_field('MC_callback', substr(tep_href_link('ext/modules/payment/worldpay/junior_callback.php', '', 'NONSSL', false, false), strpos(tep_href_link('ext/modules/payment/worldpay/junior_callback.php', '', 'NONSSL', false, false), '://')+3));
 295  
 296        if (MODULE_PAYMENT_WORLDPAY_JUNIOR_TRANSACTION_METHOD == 'Pre-Authorization') {
 297          $process_button_string .= tep_draw_hidden_field('authMode', 'E');
 298        }
 299  
 300        if (MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE == 'True') {
 301          $process_button_string .= tep_draw_hidden_field('testMode', '100');
 302        }
 303  
 304        $process_button_string .= tep_draw_hidden_field('M_sid', tep_session_id()) .
 305                                  tep_draw_hidden_field('M_cid', $customer_id) .
 306                                  tep_draw_hidden_field('M_lang', $language) .
 307                                  tep_draw_hidden_field('M_hash', md5(tep_session_id() . $customer_id . $order_id . $language . number_format($order->info['total'], 2) . MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD));
 308  
 309        return $process_button_string;
 310      }
 311  
 312      function before_process() {
 313        global $customer_id, $language, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_Worldpay_Junior_ID;
 314        global $$payment;
 315  
 316        $order_id = substr($cart_Worldpay_Junior_ID, strpos($cart_Worldpay_Junior_ID, '-')+1);
 317  
 318        $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 319        if (tep_db_num_rows($check_query)) {
 320          $check = tep_db_fetch_array($check_query);
 321  
 322          if ($check['orders_status'] == MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID) {
 323            $hash_result = false;
 324  
 325            if (isset($HTTP_GET_VARS['hash']) && !empty($HTTP_GET_VARS['hash']) && ($HTTP_GET_VARS['hash'] == md5(tep_session_name() . $customer_id . $order_id . $language . number_format($order->info['total'], 2) . MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD))) {
 326              $hash_result = true;
 327            }
 328  
 329            $sql_data_array = array('orders_id' => $order_id,
 330                                    'orders_status_id' => MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID,
 331                                    'date_added' => 'now()',
 332                                    'customer_notified' => '0',
 333                                    'comments' => (($hash_result == true) ? 'WorldPay: Transaction Verified' : 'WorldPay: Incorrect Transaction Hash'));
 334  
 335            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 336  
 337            if (MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE == 'True') {
 338              $sql_data_array = array('orders_id' => $order_id,
 339                                      'orders_status_id' => MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID,
 340                                      'date_added' => 'now()',
 341                                      'customer_notified' => '0',
 342                                      'comments' => MODULE_PAYMENT_WORLDPAY_JUNIOR_TEXT_WARNING_DEMO_MODE);
 343  
 344              tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 345            }
 346          }
 347        }
 348  
 349        tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int)$order_id . "'");
 350  
 351        $sql_data_array = array('orders_id' => $order_id,
 352                                'orders_status_id' => (MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID),
 353                                'date_added' => 'now()',
 354                                'customer_notified' => (SEND_EMAILS == 'true') ? '1' : '0',
 355                                'comments' => $order->info['comments']);
 356  
 357        tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 358  
 359  // initialized for the email confirmation
 360        $products_ordered = '';
 361        $subtotal = 0;
 362        $total_tax = 0;
 363  
 364        for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 365  // Stock Update - Joao Correia
 366          if (STOCK_LIMITED == 'true') {
 367            if (DOWNLOAD_ENABLED == 'true') {
 368              $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename
 369                                  FROM " . TABLE_PRODUCTS . " p
 370                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 371                                  ON p.products_id=pa.products_id
 372                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 373                                  ON pa.products_attributes_id=pad.products_attributes_id
 374                                  WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
 375  // Will work with only one option for downloadable products
 376  // otherwise, we have to build the query dynamically with a loop
 377              $products_attributes = $order->products[$i]['attributes'];
 378              if (is_array($products_attributes)) {
 379                $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
 380              }
 381              $stock_query = tep_db_query($stock_query_raw);
 382            } else {
 383              $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 384            }
 385            if (tep_db_num_rows($stock_query) > 0) {
 386              $stock_values = tep_db_fetch_array($stock_query);
 387  // do not decrement quantities if products_attributes_filename exists
 388              if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
 389                $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
 390              } else {
 391                $stock_left = $stock_values['products_quantity'];
 392              }
 393              tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 394              if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
 395                tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 396              }
 397            }
 398          }
 399  
 400  // Update products_ordered (for bestsellers list)
 401          tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 402  
 403  //------insert customer choosen option to order--------
 404          $attributes_exist = '0';
 405          $products_ordered_attributes = '';
 406          if (isset($order->products[$i]['attributes'])) {
 407            $attributes_exist = '1';
 408            for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 409              if (DOWNLOAD_ENABLED == 'true') {
 410                $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename
 411                                     from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 412                                     left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 413                                     on pa.products_attributes_id=pad.products_attributes_id
 414                                     where pa.products_id = '" . $order->products[$i]['id'] . "'
 415                                     and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 416                                     and pa.options_id = popt.products_options_id
 417                                     and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 418                                     and pa.options_values_id = poval.products_options_values_id
 419                                     and popt.language_id = '" . $languages_id . "'
 420                                     and poval.language_id = '" . $languages_id . "'";
 421                $attributes = tep_db_query($attributes_query);
 422              } else {
 423                $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 424              }
 425              $attributes_values = tep_db_fetch_array($attributes);
 426  
 427              $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
 428            }
 429          }
 430  //------insert customer choosen option eof ----
 431          $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
 432          $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
 433          $total_cost += $total_products_price;
 434  
 435          $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
 436        }
 437  
 438  // lets start with the email confirmation
 439        $email_order = STORE_NAME . "\n" .
 440                       EMAIL_SEPARATOR . "\n" .
 441                       EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" .
 442                       EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" .
 443                       EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
 444        if ($order->info['comments']) {
 445          $email_order .= tep_db_output($order->info['comments']) . "\n\n";
 446        }
 447        $email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
 448                        EMAIL_SEPARATOR . "\n" .
 449                        $products_ordered .
 450                        EMAIL_SEPARATOR . "\n";
 451  
 452        for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 453          $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
 454        }
 455  
 456        if ($order->content_type != 'virtual') {
 457          $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
 458                          EMAIL_SEPARATOR . "\n" .
 459                          tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
 460        }
 461  
 462        $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
 463                        EMAIL_SEPARATOR . "\n" .
 464                        tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
 465  
 466        if (is_object($$payment)) {
 467          $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
 468                          EMAIL_SEPARATOR . "\n";
 469          $payment_class = $$payment;
 470          $email_order .= $payment_class->title . "\n\n";
 471          if ($payment_class->email_footer) {
 472            $email_order .= $payment_class->email_footer . "\n\n";
 473          }
 474        }
 475  
 476        tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 477  
 478  // send emails to other people
 479        if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
 480          tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 481        }
 482  
 483  // load the after_process function from the payment modules
 484        $this->after_process();
 485  
 486        $cart->reset(true);
 487  
 488  // unregister session variables used during checkout
 489        tep_session_unregister('sendto');
 490        tep_session_unregister('billto');
 491        tep_session_unregister('shipping');
 492        tep_session_unregister('payment');
 493        tep_session_unregister('comments');
 494  
 495        tep_session_unregister('cart_Worldpay_Junior_ID');
 496  
 497        tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 498      }
 499  
 500      function after_process() {
 501        return false;
 502      }
 503  
 504      function get_error() {
 505        return false;
 506      }
 507  
 508      function check() {
 509        if (!isset($this->_check)) {
 510          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_WORLDPAY_JUNIOR_STATUS'");
 511          $this->_check = tep_db_num_rows($check_query);
 512        }
 513        return $this->_check;
 514      }
 515  
 516      function install() {
 517        $check_query = tep_db_query("select orders_status_id from " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Preparing [WorldPay]' limit 1");
 518  
 519        if (tep_db_num_rows($check_query) < 1) {
 520          $status_query = tep_db_query("select max(orders_status_id) as status_id from " . TABLE_ORDERS_STATUS);
 521          $status = tep_db_fetch_array($status_query);
 522  
 523          $status_id = $status['status_id']+1;
 524  
 525          $languages = tep_get_languages();
 526  
 527          for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 528            tep_db_query("insert into " . TABLE_ORDERS_STATUS . " (orders_status_id, language_id, orders_status_name) values ('" . $status_id . "', '" . $languages[$i]['id'] . "', 'Preparing [WorldPay]')");
 529          }
 530  
 531          $flags_query = tep_db_query("describe " . TABLE_ORDERS_STATUS . " public_flag");
 532          if (tep_db_num_rows($flags_query) == 1) {
 533            tep_db_query("update " . TABLE_ORDERS_STATUS . " set public_flag = 0 and downloads_flag = 0 where orders_status_id = '" . $status_id . "'");
 534          }
 535        } else {
 536          $check = tep_db_fetch_array($check_query);
 537  
 538          $status_id = $check['orders_status_id'];
 539        }
 540  
 541        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 WorldPay Select Junior', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_STATUS', 'False', 'Do you want to accept WorldPay Select Junior payments?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 542        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Installation ID', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_INSTALLATION_ID', '', 'Your WorldPay Installation ID', '6', '0', now())");
 543        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Callback Password', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD', '', 'A password that is sent back in the callback response (specified in the WorldPay Customer Management System)', '6', '0', now())");
 544        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('MD5 Password', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD', '', 'The MD5 secret encryption password used to validate transaction responses with (specified in the WorldPay Customer Management System)', '6', '0', now())");
 545        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 Method', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_TRANSACTION_METHOD', 'Capture', 'The processing method to use for each transaction', '6', '0', 'tep_cfg_select_option(array(\'Pre-Authorization\', \'Capture\'), ', now())");
 546        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 ('Test Mode', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE', 'True', 'Process transactions in test mode?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 547        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 of display.', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 548        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_WORLDPAY_JUNIOR_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())");
 549        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 Preparing Order Status', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID', '" . (int)$status_id . "', 'Set the status of prepared orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 550        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_WORLDPAY_JUNIOR_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())");
 551      }
 552  
 553      function remove() {
 554        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 555      }
 556  
 557      function keys() {
 558        return array('MODULE_PAYMENT_WORLDPAY_JUNIOR_STATUS', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_INSTALLATION_ID', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_CALLBACK_PASSWORD', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_MD5_PASSWORD', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_TRANSACTION_METHOD', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_TESTMODE', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_ZONE', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_PREPARE_ORDER_STATUS_ID', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_ORDER_STATUS_ID', 'MODULE_PAYMENT_WORLDPAY_JUNIOR_SORT_ORDER');
 559      }
 560  
 561  // format prices without currency formatting
 562      function format_raw($number, $currency_code = '', $currency_value = '') {
 563        global $currencies, $currency;
 564  
 565        if (empty($currency_code) || !$this->is_set($currency_code)) {
 566          $currency_code = $currency;
 567        }
 568  
 569        if (empty($currency_value) || !is_numeric($currency_value)) {
 570          $currency_value = $currencies->currencies[$currency_code]['value'];
 571        }
 572  
 573        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 574      }
 575    }
 576  ?>


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