[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: paypal_uk_direct.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_direct {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function paypal_uk_direct() {
  18        global $order;
  19  
  20        $this->signature = 'paypal|paypal_uk_direct|1.0|2.2';
  21  
  22        $this->code = 'paypal_uk_direct';
  23        $this->title = MODULE_PAYMENT_PAYPAL_UK_DIRECT_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_PAYPAL_UK_DIRECT_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_PAYPAL_UK_DIRECT_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_PAYPAL_UK_DIRECT_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_PAYPAL_UK_DIRECT_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_PAYPAL_UK_DIRECT_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->cc_types = array('0' => 'Visa',
  36                                '1' => 'MasterCard',
  37                                '9' => 'Maestro',
  38                                'S' => 'Solo');
  39      }
  40  
  41  // class methods
  42      function update_status() {
  43        global $order;
  44  
  45        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_UK_DIRECT_ZONE > 0) ) {
  46          $check_flag = false;
  47          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_UK_DIRECT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  48          while ($check = tep_db_fetch_array($check_query)) {
  49            if ($check['zone_id'] < 1) {
  50              $check_flag = true;
  51              break;
  52            } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  53              $check_flag = true;
  54              break;
  55            }
  56          }
  57  
  58          if ($check_flag == false) {
  59            $this->enabled = false;
  60          }
  61        }
  62      }
  63  
  64      function javascript_validation() {
  65        return false;
  66      }
  67  
  68      function selection() {
  69        return array('id' => $this->code,
  70                     'module' => $this->public_title);
  71      }
  72  
  73      function pre_confirmation_check() {
  74        return false;
  75      }
  76  
  77      function confirmation() {
  78        global $order;
  79  
  80        $types_array = array();
  81        while (list($key, $value) = each($this->cc_types)) {
  82          $types_array[] = array('id' => $key,
  83                                 'text' => $value);
  84        }
  85  
  86        $today = getdate();
  87  
  88        $months_array = array();
  89        for ($i=1; $i<13; $i++) {
  90          $months_array[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
  91        }
  92  
  93        $year_valid_from_array = array();
  94        for ($i=$today['year']-10; $i < $today['year']+1; $i++) {
  95          $year_valid_from_array[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
  96        }
  97  
  98        $year_expires_array = array();
  99        for ($i=$today['year']; $i < $today['year']+10; $i++) {
 100          $year_expires_array[] = array('id' => strftime('%y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
 101        }
 102  
 103        $confirmation = array('fields' => array(array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_OWNER,
 104                                                      'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
 105                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_TYPE,
 106                                                      'field' => tep_draw_pull_down_menu('cc_type', $types_array)),
 107                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_NUMBER,
 108                                                      'field' => tep_draw_input_field('cc_number_nh-dns')),
 109                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_VALID_FROM,
 110                                                      'field' => tep_draw_pull_down_menu('cc_starts_month', $months_array) . '&nbsp;' . tep_draw_pull_down_menu('cc_starts_year', $year_valid_from_array) . ' ' . MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_VALID_FROM_INFO),
 111                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_EXPIRES,
 112                                                      'field' => tep_draw_pull_down_menu('cc_expires_month', $months_array) . '&nbsp;' . tep_draw_pull_down_menu('cc_expires_year', $year_expires_array)),
 113                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_CVC,
 114                                                      'field' => tep_draw_input_field('cc_cvc_nh-dns', '', 'size="5" maxlength="4"')),
 115                                                array('title' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_ISSUE_NUMBER,
 116                                                      'field' => tep_draw_input_field('cc_issue_nh-dns', '', 'size="3" maxlength="2"') . ' ' . MODULE_PAYMENT_PAYPAL_UK_DIRECT_CARD_ISSUE_NUMBER_INFO)));
 117  
 118        return $confirmation;
 119      }
 120  
 121      function process_button() {
 122        return false;
 123      }
 124  
 125      function before_process() {
 126        global $HTTP_POST_VARS, $order, $sendto;
 127  
 128        if (isset($HTTP_POST_VARS['cc_owner']) && !empty($HTTP_POST_VARS['cc_owner']) && isset($HTTP_POST_VARS['cc_type']) && isset($this->cc_types[$HTTP_POST_VARS['cc_type']]) && isset($HTTP_POST_VARS['cc_number_nh-dns']) && !empty($HTTP_POST_VARS['cc_number_nh-dns'])) {
 129          if (MODULE_PAYMENT_PAYPAL_UK_DIRECT_TRANSACTION_SERVER == 'Live') {
 130            $api_url = 'https://payflowpro.verisign.com/transaction';
 131          } else {
 132            $api_url = 'https://pilot-payflowpro.verisign.com/transaction';
 133          }
 134  
 135          $params = array('USER' => (tep_not_null(MODULE_PAYMENT_PAYPAL_UK_DIRECT_USERNAME) ? MODULE_PAYMENT_PAYPAL_UK_DIRECT_USERNAME : MODULE_PAYMENT_PAYPAL_UK_DIRECT_VENDOR),
 136                          'VENDOR' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_VENDOR,
 137                          'PARTNER' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_PARTNER,
 138                          'PWD' => MODULE_PAYMENT_PAYPAL_UK_DIRECT_PASSWORD,
 139                          'TENDER' => 'C',
 140                          'TRXTYPE' => ((MODULE_PAYMENT_PAYPAL_UK_DIRECT_TRANSACTION_METHOD == 'Sale') ? 'S' : 'A'),
 141                          'AMT' => $this->format_raw($order->info['total']),
 142                          'CURRENCY' => $order->info['currency'],
 143                          'NAME' => $HTTP_POST_VARS['cc_owner'],
 144                          'STREET' => $order->billing['street_address'],
 145                          'CITY' => $order->billing['city'],
 146                          'STATE' => tep_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']),
 147                          'COUNTRY' => $order->billing['country']['iso_code_2'],
 148                          'ZIP' => $order->billing['postcode'],
 149                          'CLIENTIP' => tep_get_ip_address(),
 150                          'EMAIL' => $order->customer['email_address'],
 151                          'ACCT' => $HTTP_POST_VARS['cc_number_nh-dns'],
 152                          'ACCTTYPE' => $HTTP_POST_VARS['cc_type'],
 153                          'CARDSTART' => $HTTP_POST_VARS['cc_starts_month'] . $HTTP_POST_VARS['cc_starts_year'],
 154                          'EXPDATE' => $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year'],
 155                          'CVV2' => $HTTP_POST_VARS['cc_cvc_nh-dns'],
 156                          'BUTTONSOURCE' => 'osCommerce22_Default_PRO2DP');
 157  
 158          if ( ($HTTP_POST_VARS['cc_type'] == '9') || ($HTTP_POST_VARS['cc_type'] == 'S') ) {
 159            $params['CARDISSUE'] = $HTTP_POST_VARS['cc_issue_nh-dns'];
 160          }
 161  
 162          if (is_numeric($sendto) && ($sendto > 0)) {
 163            $params['SHIPTOFIRSTNAME'] = $order->delivery['firstname'];
 164            $params['SHIPTOLASTNAME'] = $order->delivery['lastname'];
 165            $params['SHIPTOSTREET'] = $order->delivery['street_address'];
 166            $params['SHIPTOCITY'] = $order->delivery['city'];
 167            $params['SHIPTOSTATE'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']);
 168            $params['SHIPTOCOUNTRY'] = $order->delivery['country']['iso_code_2'];
 169            $params['SHIPTOZIP'] = $order->delivery['postcode'];
 170          }
 171  
 172          $post_string = '';
 173  
 174          foreach ($params as $key => $value) {
 175            $post_string .= $key . '[' . strlen(trim($value)) . ']=' . trim($value) . '&';
 176          }
 177  
 178          $post_string = substr($post_string, 0, -1);
 179  
 180          $response = $this->sendTransactionToGateway($api_url, $post_string, array('X-VPS-REQUEST-ID: ' . md5($cartID . tep_session_id() . rand())));
 181          $response_array = array();
 182          parse_str($response, $response_array);
 183  
 184          if ($response_array['RESULT'] != '0') {
 185            switch ($response_array['RESULT']) {
 186              case '1':
 187              case '26':
 188                $error_message = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_CFG_ERROR;
 189                break;
 190  
 191              case '7':
 192                $error_message = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_ADDRESS;
 193                break;
 194  
 195              case '12':
 196                $error_message = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_DECLINED;
 197                break;
 198  
 199              case '23':
 200              case '24':
 201                $error_message = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_INVALID_CREDIT_CARD;
 202                break;
 203  
 204              default:
 205                $error_message = MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_GENERAL;
 206                break;
 207            }
 208  
 209            tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'error_message=' . urlencode($error_message), 'SSL'));
 210          }
 211        } else {
 212          tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'error_message=' . MODULE_PAYMENT_PAYPAL_UK_DIRECT_ERROR_ALL_FIELDS_REQUIRED, 'SSL'));
 213        }
 214      }
 215  
 216      function after_process() {
 217        return false;
 218      }
 219  
 220      function get_error() {
 221        return false;
 222      }
 223  
 224      function check() {
 225        if (!isset($this->_check)) {
 226          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_STATUS'");
 227          $this->_check = tep_db_num_rows($check_query);
 228        }
 229        return $this->_check;
 230      }
 231  
 232      function install() {
 233        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 Direct (UK)', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_STATUS', 'False', 'Do you want to accept PayPal Direct (UK) payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 234        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_DIRECT_VENDOR', '', 'Your merchant login ID that you created when you registered for the Website Payments Pro account.', '6', '0', now())");
 235        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_DIRECT_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())");
 236        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_DIRECT_PASSWORD', '', 'The 6- to 32-character password that you defined while registering for the account.', '6', '0', now())");
 237        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_DIRECT_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())");
 238        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_DIRECT_TRANSACTION_SERVER', 'Live', 'Use the live or testing (sandbox) gateway server to process transactions?', '6', '0', 'tep_cfg_select_option(array(\'Live\', \'Sandbox\'), ', now())");
 239        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_DIRECT_TRANSACTION_METHOD', 'Sale', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Sale\'), ', now())");
 240        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_DIRECT_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())");
 241        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_DIRECT_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 242        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_DIRECT_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())");
 243        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_DIRECT_CURL', '/usr/bin/curl', 'The location to the cURL program application.', '6', '0' , now())");
 244     }
 245  
 246      function remove() {
 247        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 248      }
 249  
 250      function keys() {
 251        return array('MODULE_PAYMENT_PAYPAL_UK_DIRECT_STATUS', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_VENDOR', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_USERNAME', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_PASSWORD', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_PARTNER', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_TRANSACTION_SERVER', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_TRANSACTION_METHOD', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_ZONE', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_SORT_ORDER', 'MODULE_PAYMENT_PAYPAL_UK_DIRECT_CURL');
 252      }
 253  
 254      function sendTransactionToGateway($url, $parameters, $headers = null) {
 255        $header = array();
 256  
 257        $server = parse_url($url);
 258  
 259        if (!isset($server['port'])) {
 260          $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
 261        }
 262  
 263        if (!isset($server['path'])) {
 264          $server['path'] = '/';
 265        }
 266  
 267        if (isset($server['user']) && isset($server['pass'])) {
 268          $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
 269        }
 270  
 271        if (!empty($headers) && is_array($headers)) {
 272          $header = array_merge($header, $headers);
 273        }
 274  
 275        if (function_exists('curl_init')) {
 276          $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
 277          curl_setopt($curl, CURLOPT_PORT, $server['port']);
 278          curl_setopt($curl, CURLOPT_HEADER, 0);
 279          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
 280          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 281          curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
 282          curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
 283          curl_setopt($curl, CURLOPT_POST, 1);
 284          curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
 285  
 286          if (!empty($header)) {
 287            curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
 288          }
 289  
 290          $result = curl_exec($curl);
 291  
 292          curl_close($curl);
 293        } else {
 294          exec(escapeshellarg(MODULE_PAYMENT_PAYPAL_UK_DIRECT_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);
 295          $result = implode("\n", $result);
 296        }
 297  
 298        return $result;
 299      }
 300  
 301  // format prices without currency formatting
 302      function format_raw($number, $currency_code = '', $currency_value = '') {
 303        global $currencies, $currency;
 304  
 305        if (empty($currency_code) || !$this->is_set($currency_code)) {
 306          $currency_code = $currency;
 307        }
 308  
 309        if (empty($currency_value) || !is_numeric($currency_value)) {
 310          $currency_value = $currencies->currencies[$currency_code]['value'];
 311        }
 312  
 313        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 314      }
 315    }
 316  ?>


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