[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: paypal_uk_express.php 1803 2008-01-11 18:16:37Z 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 paypal_uk_express {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function paypal_uk_express() {
  18        global $order;
  19  
  20        $this->signature = 'paypal|paypal_uk_express|1.0|2.2';
  21  
  22        $this->code = 'paypal_uk_express';
  23        $this->title = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_PAYPAL_UK_EXPRESS_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34      }
  35  
  36  // class methods
  37      function update_status() {
  38        global $order;
  39  
  40        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ZONE > 0) ) {
  41          $check_flag = false;
  42          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  43          while ($check = tep_db_fetch_array($check_query)) {
  44            if ($check['zone_id'] < 1) {
  45              $check_flag = true;
  46              break;
  47            } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  48              $check_flag = true;
  49              break;
  50            }
  51          }
  52  
  53          if ($check_flag == false) {
  54            $this->enabled = false;
  55          }
  56        }
  57      }
  58  
  59      function checkout_initialization_method() {
  60        global $language;
  61  
  62        if (file_exists(DIR_FS_CATALOG . 'ext/modules/payment/paypal/images/btn_express_' . basename($language) . '.gif')) {
  63          $image = 'ext/modules/payment/paypal/images/btn_express_' . basename($language) . '.gif';
  64        } else {
  65          $image = 'ext/modules/payment/paypal/images/btn_express.gif';
  66        }
  67  
  68        $string = '<a href="' . tep_href_link('ext/modules/payment/paypal/express_uk.php', '', 'SSL') . '"><img src="' . $image . '" border="0" alt="" title="' . tep_output_string_protected(MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TEXT_BUTTON) . '" /></a>';
  69  
  70        return $string;
  71      }
  72  
  73      function javascript_validation() {
  74        return false;
  75      }
  76  
  77      function selection() {
  78        return array('id' => $this->code,
  79                     'module' => $this->public_title);
  80      }
  81  
  82      function pre_confirmation_check() {
  83        if (!tep_session_is_registered('ppeuk_token')) {
  84          tep_redirect(tep_href_link('ext/modules/payment/paypal/express_uk.php', '', 'SSL'));
  85        }
  86      }
  87  
  88      function confirmation() {
  89        global $comments;
  90  
  91        if (!isset($comments)) {
  92          $comments = null;
  93        }
  94  
  95        $confirmation = false;
  96  
  97        if (empty($comments)) {
  98          $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TEXT_COMMENTS,
  99                                                        'field' => tep_draw_textarea_field('ppecomments', 'soft', '60', '5', $comments))));
 100        }
 101  
 102        return $confirmation;
 103      }
 104  
 105      function process_button() {
 106        return false;
 107      }
 108  
 109      function before_process() {
 110        global $order, $sendto, $ppeuk_token, $ppeuk_payerid, $HTTP_POST_VARS, $comments;
 111  
 112        if (empty($comments)) {
 113          if (isset($HTTP_POST_VARS['ppecomments']) && tep_not_null($HTTP_POST_VARS['ppecomments'])) {
 114            $comments = tep_db_prepare_input($HTTP_POST_VARS['ppecomments']);
 115  
 116            $order->info['comments'] = $comments;
 117          }
 118        }
 119  
 120        if (MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_SERVER == 'Live') {
 121          $api_url = 'https://payflowpro.verisign.com/transaction';
 122        } else {
 123          $api_url = 'https://pilot-payflowpro.verisign.com/transaction';
 124        }
 125  
 126        $params = array('USER' => (tep_not_null(MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME) ? MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME : MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR),
 127                        'VENDOR' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR,
 128                        'PARTNER' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PARTNER,
 129                        'PWD' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PASSWORD,
 130                        'TENDER' => 'P',
 131                        'TRXTYPE' => ((MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_METHOD == 'Sale') ? 'S' : 'A'),
 132                        'EMAIL' => $order->customer['email_address'],
 133                        'TOKEN' => $ppeuk_token,
 134                        'ACTION' => 'D',
 135                        'PAYERID' => $ppeuk_payerid,
 136                        'AMT' => $this->format_raw($order->info['total']),
 137                        'CURRENCY' => $order->info['currency'],
 138                        'BUTTONSOURCE' => 'osCommerce22_Default_PRO2EC');
 139  
 140        if (is_numeric($sendto) && ($sendto > 0)) {
 141          $params['SHIPTOSTREET'] = $order->delivery['street_address'];
 142          $params['SHIPTOCITY'] = $order->delivery['city'];
 143          $params['SHIPTOSTATE'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']);
 144          $params['SHIPTOCOUNTRY'] = $order->delivery['country']['iso_code_2'];
 145          $params['SHIPTOZIP'] = $order->delivery['postcode'];
 146        }
 147  
 148        $post_string = '';
 149  
 150        foreach ($params as $key => $value) {
 151          $post_string .= $key . '[' . strlen(trim($value)) . ']=' . trim($value) . '&';
 152        }
 153  
 154        $post_string = substr($post_string, 0, -1);
 155  
 156        $response = $this->sendTransactionToGateway($api_url, $post_string, array('X-VPS-REQUEST-ID: ' . md5($cartID . tep_session_id() . rand())));
 157        $response_array = array();
 158        parse_str($response, $response_array);
 159  
 160        if ($response_array['RESULT'] != '0') {
 161          switch ($response_array['RESULT']) {
 162            case '1':
 163            case '26':
 164              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_CFG_ERROR;
 165              break;
 166  
 167            case '7':
 168              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_ADDRESS;
 169              break;
 170  
 171            case '12':
 172              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_DECLINED;
 173              break;
 174  
 175            case '1000':
 176              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_EXPRESS_DISABLED;
 177              break;
 178  
 179            default:
 180              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_GENERAL;
 181              break;
 182          }
 183  
 184          tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($error_message), 'SSL'));
 185        }
 186      }
 187  
 188      function after_process() {
 189        tep_session_unregister('ppeuk_token');
 190        tep_session_unregister('ppeuk_payerid');
 191      }
 192  
 193      function get_error() {
 194        return false;
 195      }
 196  
 197      function check() {
 198        if (!isset($this->_check)) {
 199          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_STATUS'");
 200          $this->_check = tep_db_num_rows($check_query);
 201        }
 202        return $this->_check;
 203      }
 204  
 205      function install() {
 206        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 PayPal Express Checkout (UK)', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_STATUS', 'False', 'Do you want to accept PayPal Express Checkout (UK) payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 207        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Vendor', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR', '', 'Your merchant login ID that you created when you registered for the Website Payments Pro account.', '6', '0', now())");
 208        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('User', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME', '', 'If you set up one or more additional users on the account, this value is the ID of the user authorised to process transactions. If, however, you have not set up additional users on the account, USER has the same value as VENDOR.', '6', '0', now())");
 209        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Password', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PASSWORD', '', 'The 6- to 32-character password that you defined while registering for the account.', '6', '0', now())");
 210        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Partner', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PARTNER', 'PayPalUK', 'The ID provided to you by the authorised PayPal Reseller who registered you for the Payflow SDK. If you purchased your account directly from PayPal, use PayPalUK.', '6', '0', now())");
 211        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 Server', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_SERVER', 'Live', 'Use the live or testing (sandbox) gateway server to process transactions?', '6', '0', 'tep_cfg_select_option(array(\'Live\', \'Sandbox\'), ', now())");
 212        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_PAYPAL_UK_EXPRESS_TRANSACTION_METHOD', 'Sale', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Sale\'), ', now())");
 213        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_PAYPAL_UK_EXPRESS_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())");
 214        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_PAYPAL_UK_EXPRESS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 215        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_PAYPAL_UK_EXPRESS_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())");
 216        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('cURL Program Location', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_CURL', '/usr/bin/curl', 'The location to the cURL program application.', '6', '0' , now())");
 217     }
 218  
 219      function remove() {
 220        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 221      }
 222  
 223      function keys() {
 224        return array('MODULE_PAYMENT_PAYPAL_UK_EXPRESS_STATUS', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PASSWORD', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PARTNER', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_SERVER', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_METHOD', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ZONE', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_SORT_ORDER', 'MODULE_PAYMENT_PAYPAL_UK_EXPRESS_CURL');
 225      }
 226  
 227      function sendTransactionToGateway($url, $parameters, $headers = null) {
 228        $header = array();
 229  
 230        $server = parse_url($url);
 231  
 232        if (!isset($server['port'])) {
 233          $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
 234        }
 235  
 236        if (!isset($server['path'])) {
 237          $server['path'] = '/';
 238        }
 239  
 240        if (isset($server['user']) && isset($server['pass'])) {
 241          $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
 242        }
 243  
 244        if (!empty($headers) && is_array($headers)) {
 245          $header = array_merge($header, $headers);
 246        }
 247  
 248        if (function_exists('curl_init')) {
 249          $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
 250          curl_setopt($curl, CURLOPT_PORT, $server['port']);
 251          curl_setopt($curl, CURLOPT_HEADER, 0);
 252          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
 253          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 254          curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
 255          curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
 256          curl_setopt($curl, CURLOPT_POST, 1);
 257          curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
 258  
 259          if (!empty($header)) {
 260            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
 261          }
 262  
 263          $result = curl_exec($curl);
 264  
 265          curl_close($curl);
 266        } else {
 267          exec(escapeshellarg(MODULE_PAYMENT_PAYPAL_UK_EXPRESS_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k' . (!empty($header) ? ' -H ' . escapeshellarg(implode("\r\n", $header)) : ''), $result);
 268          $result = implode("\n", $result);
 269        }
 270  
 271        return $result;
 272      }
 273  
 274  // format prices without currency formatting
 275      function format_raw($number, $currency_code = '', $currency_value = '') {
 276        global $currencies, $currency;
 277  
 278        if (empty($currency_code) || !$this->is_set($currency_code)) {
 279          $currency_code = $currency;
 280        }
 281  
 282        if (empty($currency_value) || !is_numeric($currency_value)) {
 283          $currency_value = $currencies->currencies[$currency_code]['value'];
 284        }
 285  
 286        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 287      }
 288    }
 289  ?>


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