[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: paypal_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_direct {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function paypal_direct() {
  18        global $order;
  19  
  20        $this->signature = 'paypal|paypal_direct|1.1|2.2';
  21  
  22        $this->code = 'paypal_direct';
  23        $this->title = MODULE_PAYMENT_PAYPAL_DIRECT_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_PAYPAL_DIRECT_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_PAYPAL_DIRECT_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_PAYPAL_DIRECT_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_PAYPAL_DIRECT_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_PAYPAL_DIRECT_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_PAYPAL_DIRECT_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->cc_types = array('VISA' => 'Visa',
  36                                'MASTERCARD' => 'MasterCard',
  37                                'DISCOVER' => 'Discover Card',
  38                                'AMEX' => 'American Express',
  39                                'SWITCH' => 'Maestro',
  40                                'SOLO' => 'Solo');
  41      }
  42  
  43  // class methods
  44      function update_status() {
  45        global $order;
  46  
  47        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_PAYPAL_DIRECT_ZONE > 0) ) {
  48          $check_flag = false;
  49          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_PAYPAL_DIRECT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
  50          while ($check = tep_db_fetch_array($check_query)) {
  51            if ($check['zone_id'] < 1) {
  52              $check_flag = true;
  53              break;
  54            } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
  55              $check_flag = true;
  56              break;
  57            }
  58          }
  59  
  60          if ($check_flag == false) {
  61            $this->enabled = false;
  62          }
  63        }
  64      }
  65  
  66      function javascript_validation() {
  67        return false;
  68      }
  69  
  70      function selection() {
  71        $selection = array('id' => $this->code,
  72                           'module' => $this->public_title);
  73  
  74        if (MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE == 'Payment') {
  75          global $order;
  76  
  77          $types_array = array();
  78          while (list($key, $value) = each($this->cc_types)) {
  79            $types_array[] = array('id' => $key,
  80                                   'text' => $value);
  81          }
  82  
  83          $today = getdate();
  84  
  85          $months_array = array();
  86          for ($i=1; $i<13; $i++) {
  87            $months_array[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
  88          }
  89  
  90          $year_valid_from_array = array();
  91          for ($i=$today['year']-10; $i < $today['year']+1; $i++) {
  92            $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)));
  93          }
  94  
  95          $year_expires_array = array();
  96          for ($i=$today['year']; $i < $today['year']+10; $i++) {
  97            $year_expires_array[] = array('id' => strftime('%Y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
  98          }
  99  
 100          $selection['fields'] = array(array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_OWNER,
 101                                             'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
 102                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_TYPE,
 103                                             'field' => tep_draw_pull_down_menu('cc_type', $types_array)),
 104                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_NUMBER,
 105                                             'field' => tep_draw_input_field('cc_number_nh-dns')),
 106                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_VALID_FROM,
 107                                             '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_DIRECT_CARD_VALID_FROM_INFO),
 108                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_EXPIRES,
 109                                             'field' => tep_draw_pull_down_menu('cc_expires_month', $months_array) . '&nbsp;' . tep_draw_pull_down_menu('cc_expires_year', $year_expires_array)),
 110                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_CVC,
 111                                             'field' => tep_draw_input_field('cc_cvc_nh-dns', '', 'size="5" maxlength="4"')),
 112                                       array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_ISSUE_NUMBER,
 113                                             'field' => tep_draw_input_field('cc_issue_nh-dns', '', 'size="3" maxlength="2"') . ' ' . MODULE_PAYMENT_PAYPAL_DIRECT_CARD_ISSUE_NUMBER_INFO));
 114        }
 115  
 116        return $selection;
 117      }
 118  
 119      function pre_confirmation_check() {
 120        if (MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE == 'Payment') {
 121          global $HTTP_POST_VARS;
 122  
 123          if (!isset($HTTP_POST_VARS['cc_owner']) || empty($HTTP_POST_VARS['cc_owner']) || (strlen($HTTP_POST_VARS['cc_owner']) < CC_OWNER_MIN_LENGTH) || !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']) || (strlen($HTTP_POST_VARS['cc_number_nh-dns']) < CC_NUMBER_MIN_LENGTH)) {
 124            $payment_error_return = 'payment_error=' . $this->code . '&error=' . urlencode(MODULE_PAYMENT_PAYPAL_DIRECT_ERROR_ALL_FIELDS_REQUIRED) . '&cc_owner=' . urlencode($HTTP_POST_VARS['cc_owner']) . '&cc_starts_month=' . $HTTP_POST_VARS['cc_starts_month'] . '&cc_starts_year=' . $HTTP_POST_VARS['cc_starts_year'] . '&cc_expires_month=' . $HTTP_POST_VARS['cc_expires_month'] . '&cc_expires_year=' . $HTTP_POST_VARS['cc_expires_year'];
 125  
 126            tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, $payment_error_return, 'SSL', true, false));
 127          }
 128        }
 129  
 130        return false;
 131      }
 132  
 133      function confirmation() {
 134        $confirmation = array();
 135  
 136        if (MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE == 'Payment') {
 137          global $HTTP_POST_VARS;
 138  
 139          $confirmation['fields'] = array(array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_OWNER,
 140                                                'field' => $HTTP_POST_VARS['cc_owner']),
 141                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_TYPE,
 142                                                'field' => $this->cc_types[$HTTP_POST_VARS['cc_type']]),
 143                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_NUMBER,
 144                                                'field' => str_repeat('X', strlen($HTTP_POST_VARS['cc_number_nh-dns']) - 4) . substr($HTTP_POST_VARS['cc_number_nh-dns'], -4)),
 145                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_VALID_FROM,
 146                                                'field' => $HTTP_POST_VARS['cc_starts_month'] . '/' . $HTTP_POST_VARS['cc_starts_year']),
 147                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_EXPIRES,
 148                                                'field' => $HTTP_POST_VARS['cc_expires_month'] . '/' . $HTTP_POST_VARS['cc_expires_year']),
 149                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_CVC,
 150                                                'field' => $HTTP_POST_VARS['cc_cvc_nh-dns']));
 151  
 152          if (isset($HTTP_POST_VARS['cc_issue_nh-dns']) && !empty($HTTP_POST_VARS['cc_issue_nh-dns'])) {
 153            $confirmation['fields'][] = array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_ISSUE_NUMBER,
 154                                              'field' => $HTTP_POST_VARS['cc_issue_nh-dns']);
 155          }
 156        } else {
 157          global $order;
 158  
 159          $types_array = array();
 160          while (list($key, $value) = each($this->cc_types)) {
 161            $types_array[] = array('id' => $key,
 162                                   'text' => $value);
 163          }
 164  
 165          $today = getdate();
 166  
 167          $months_array = array();
 168          for ($i=1; $i<13; $i++) {
 169            $months_array[] = array('id' => sprintf('%02d', $i), 'text' => strftime('%B',mktime(0,0,0,$i,1,2000)));
 170          }
 171  
 172          $year_valid_from_array = array();
 173          for ($i=$today['year']-10; $i < $today['year']+1; $i++) {
 174            $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)));
 175          }
 176  
 177          $year_expires_array = array();
 178          for ($i=$today['year']; $i < $today['year']+10; $i++) {
 179            $year_expires_array[] = array('id' => strftime('%Y',mktime(0,0,0,1,1,$i)), 'text' => strftime('%Y',mktime(0,0,0,1,1,$i)));
 180          }
 181  
 182          $confirmation['fields'] = array(array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_OWNER,
 183                                                'field' => tep_draw_input_field('cc_owner', $order->billing['firstname'] . ' ' . $order->billing['lastname'])),
 184                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_TYPE,
 185                                                'field' => tep_draw_pull_down_menu('cc_type', $types_array)),
 186                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_NUMBER,
 187                                                'field' => tep_draw_input_field('cc_number_nh-dns')),
 188                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_VALID_FROM,
 189                                                '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_DIRECT_CARD_VALID_FROM_INFO),
 190                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_EXPIRES,
 191                                                'field' => tep_draw_pull_down_menu('cc_expires_month', $months_array) . '&nbsp;' . tep_draw_pull_down_menu('cc_expires_year', $year_expires_array)),
 192                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_CVC,
 193                                                'field' => tep_draw_input_field('cc_cvc_nh-dns', '', 'size="5" maxlength="4"')),
 194                                          array('title' => MODULE_PAYMENT_PAYPAL_DIRECT_CARD_ISSUE_NUMBER,
 195                                                'field' => tep_draw_input_field('cc_issue_nh-dns', '', 'size="3" maxlength="2"') . ' ' . MODULE_PAYMENT_PAYPAL_DIRECT_CARD_ISSUE_NUMBER_INFO));
 196        }
 197  
 198        return $confirmation;
 199      }
 200  
 201      function process_button() {
 202        if (MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE == 'Payment') {
 203          global $HTTP_POST_VARS;
 204  
 205          $process_button_string = tep_draw_hidden_field('cc_owner', $HTTP_POST_VARS['cc_owner']) .
 206                                   tep_draw_hidden_field('cc_type', $HTTP_POST_VARS['cc_type']) .
 207                                   tep_draw_hidden_field('cc_number_nh-dns', $HTTP_POST_VARS['cc_number_nh-dns']) .
 208                                   tep_draw_hidden_field('cc_starts_month', $HTTP_POST_VARS['cc_starts_month']) .
 209                                   tep_draw_hidden_field('cc_starts_year', $HTTP_POST_VARS['cc_starts_year']) .
 210                                   tep_draw_hidden_field('cc_expires_month', $HTTP_POST_VARS['cc_expires_month']) .
 211                                   tep_draw_hidden_field('cc_expires_year', $HTTP_POST_VARS['cc_expires_year']) .
 212                                   tep_draw_hidden_field('cc_cvc_nh-dns', $HTTP_POST_VARS['cc_cvc_nh-dns']) .
 213                                   tep_draw_hidden_field('cc_issue_nh-dns', $HTTP_POST_VARS['cc_issue_nh-dns']);
 214  
 215          return $process_button_string;
 216        }
 217  
 218        return false;
 219      }
 220  
 221      function before_process() {
 222        global $HTTP_POST_VARS, $order, $sendto;
 223  
 224        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'])) {
 225          if (MODULE_PAYMENT_PAYPAL_DIRECT_TRANSACTION_SERVER == 'Live') {
 226            $api_url = 'https://api-3t.paypal.com/nvp';
 227          } else {
 228            $api_url = 'https://api-3t.sandbox.paypal.com/nvp';
 229          }
 230  
 231          $params = array('USER' => MODULE_PAYMENT_PAYPAL_DIRECT_API_USERNAME,
 232                          'PWD' => MODULE_PAYMENT_PAYPAL_DIRECT_API_PASSWORD,
 233                          'VERSION' => '3.2',
 234                          'SIGNATURE' => MODULE_PAYMENT_PAYPAL_DIRECT_API_SIGNATURE,
 235                          'METHOD' => 'DoDirectPayment',
 236                          'PAYMENTACTION' => ((MODULE_PAYMENT_PAYPAL_DIRECT_TRANSACTION_METHOD == 'Sale') ? 'Sale' : 'Authorization'),
 237                          'IPADDRESS' => tep_get_ip_address(),
 238                          'AMT' => $this->format_raw($order->info['total']),
 239                          'CREDITCARDTYPE' => $HTTP_POST_VARS['cc_type'],
 240                          'ACCT' => $HTTP_POST_VARS['cc_number_nh-dns'],
 241                          'STARTDATE' => $HTTP_POST_VARS['cc_starts_month'] . $HTTP_POST_VARS['cc_starts_year'],
 242                          'EXPDATE' => $HTTP_POST_VARS['cc_expires_month'] . $HTTP_POST_VARS['cc_expires_year'],
 243                          'CVV2' => $HTTP_POST_VARS['cc_cvc_nh-dns'],
 244                          'FIRSTNAME' => substr($HTTP_POST_VARS['cc_owner'], 0, strpos($HTTP_POST_VARS['cc_owner'], ' ')),
 245                          'LASTNAME' => substr($HTTP_POST_VARS['cc_owner'], strpos($HTTP_POST_VARS['cc_owner'], ' ')+1),
 246                          'STREET' => $order->billing['street_address'],
 247                          'CITY' => $order->billing['city'],
 248                          'STATE' => tep_get_zone_code($order->billing['country']['id'], $order->billing['zone_id'], $order->billing['state']),
 249                          'COUNTRYCODE' => $order->billing['country']['iso_code_2'],
 250                          'ZIP' => $order->billing['postcode'],
 251                          'EMAIL' => $order->customer['email_address'],
 252                          'PHONENUM' => $order->customer['telephone'],
 253                          'CURRENCYCODE' => $order->info['currency'],
 254                          'BUTTONSOURCE' => 'osCommerce22_Default_DP');
 255  
 256          if ( ($HTTP_POST_VARS['cc_type'] == 'SWITCH') || ($HTTP_POST_VARS['cc_type'] == 'SOLO') ) {
 257            $params['ISSUENUMBER'] = $HTTP_POST_VARS['cc_issue_nh-dns'];
 258          }
 259  
 260          if (is_numeric($sendto) && ($sendto > 0)) {
 261            $params['SHIPTONAME'] = $order->delivery['firstname'] . ' ' . $order->delivery['lastname'];
 262            $params['SHIPTOSTREET'] = $order->delivery['street_address'];
 263            $params['SHIPTOCITY'] = $order->delivery['city'];
 264            $params['SHIPTOSTATE'] = tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], $order->delivery['state']);
 265            $params['SHIPTOCOUNTRYCODE'] = $order->delivery['country']['iso_code_2'];
 266            $params['SHIPTOZIP'] = $order->delivery['postcode'];
 267          }
 268  
 269          $post_string = '';
 270  
 271          foreach ($params as $key => $value) {
 272            $post_string .= $key . '=' . urlencode(trim($value)) . '&';
 273          }
 274  
 275          $post_string = substr($post_string, 0, -1);
 276  
 277          $response = $this->sendTransactionToGateway($api_url, $post_string);
 278          $response_array = array();
 279          parse_str($response, $response_array);
 280  
 281          if (($response_array['ACK'] != 'Success') && ($response_array['ACK'] != 'SuccessWithWarning')) {
 282            tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($response_array['L_LONGMESSAGE0']), 'SSL'));
 283          }
 284        } else {
 285          tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, 'error_message=' . MODULE_PAYMENT_PAYPAL_DIRECT_ERROR_ALL_FIELDS_REQUIRED, 'SSL'));
 286        }
 287      }
 288  
 289      function after_process() {
 290        return false;
 291      }
 292  
 293      function get_error() {
 294        if (MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE == 'Payment') {
 295          global $HTTP_GET_VARS;
 296  
 297          $error = array('error' => stripslashes(urldecode($HTTP_GET_VARS['error'])));
 298  
 299          return $error;
 300        }
 301  
 302        return false;
 303      }
 304  
 305      function check() {
 306        if (!isset($this->_check)) {
 307          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_DIRECT_STATUS'");
 308          $this->_check = tep_db_num_rows($check_query);
 309        }
 310        return $this->_check;
 311      }
 312  
 313      function install() {
 314        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', 'MODULE_PAYMENT_PAYPAL_DIRECT_STATUS', 'False', 'Do you want to accept PayPal Direct payments?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 315        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Username', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_USERNAME', '', 'The username to use for the PayPal API service.', '6', '0', now())");
 316        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Password', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_PASSWORD', '', 'The password to use for the PayPal API service.', '6', '0', now())");
 317        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('API Signature', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_SIGNATURE', '', 'The signature to use for the PayPal API service.', '6', '0', now())");
 318        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_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())");
 319        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_DIRECT_TRANSACTION_METHOD', 'Sale', 'The processing method to use for each transaction.', '6', '0', 'tep_cfg_select_option(array(\'Authorization\', \'Sale\'), ', now())");
 320        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 ('Card Acceptance Page', 'MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE', 'Confirmation', 'The location to accept card information. Either on the Checkout Confirmation page or the Checkout Payment page.', '6', '0', 'tep_cfg_select_option(array(\'Confirmation\', \'Payment\'), ', now())");
 321        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_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())");
 322        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_DIRECT_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 323        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_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())");
 324        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_DIRECT_CURL', '/usr/bin/curl', 'The location to the cURL program application.', '6', '0' , now())");
 325     }
 326  
 327      function remove() {
 328        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 329      }
 330  
 331      function keys() {
 332        return array('MODULE_PAYMENT_PAYPAL_DIRECT_STATUS', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_USERNAME', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_PASSWORD', 'MODULE_PAYMENT_PAYPAL_DIRECT_API_SIGNATURE', 'MODULE_PAYMENT_PAYPAL_DIRECT_TRANSACTION_SERVER', 'MODULE_PAYMENT_PAYPAL_DIRECT_TRANSACTION_METHOD', 'MODULE_PAYMENT_PAYPAL_DIRECT_CARD_INPUT_PAGE', 'MODULE_PAYMENT_PAYPAL_DIRECT_ZONE', 'MODULE_PAYMENT_PAYPAL_DIRECT_ORDER_STATUS_ID', 'MODULE_PAYMENT_PAYPAL_DIRECT_SORT_ORDER', 'MODULE_PAYMENT_PAYPAL_DIRECT_CURL');
 333      }
 334  
 335      function sendTransactionToGateway($url, $parameters) {
 336        $server = parse_url($url);
 337  
 338        if (!isset($server['port'])) {
 339          $server['port'] = ($server['scheme'] == 'https') ? 443 : 80;
 340        }
 341  
 342        if (!isset($server['path'])) {
 343          $server['path'] = '/';
 344        }
 345  
 346        if (isset($server['user']) && isset($server['pass'])) {
 347          $header[] = 'Authorization: Basic ' . base64_encode($server['user'] . ':' . $server['pass']);
 348        }
 349  
 350        if (function_exists('curl_init')) {
 351          $curl = curl_init($server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : ''));
 352          curl_setopt($curl, CURLOPT_PORT, $server['port']);
 353          curl_setopt($curl, CURLOPT_HEADER, 0);
 354          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
 355          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 356          curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
 357          curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
 358          curl_setopt($curl, CURLOPT_POST, 1);
 359          curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
 360  
 361          $result = curl_exec($curl);
 362  
 363          curl_close($curl);
 364        } else {
 365          exec(escapeshellarg(MODULE_PAYMENT_PAYPAL_DIRECT_CURL) . ' -d ' . escapeshellarg($parameters) . ' "' . $server['scheme'] . '://' . $server['host'] . $server['path'] . (isset($server['query']) ? '?' . $server['query'] : '') . '" -P ' . $server['port'] . ' -k', $result);
 366          $result = implode("\n", $result);
 367        }
 368  
 369        return $result;
 370      }
 371  
 372  // format prices without currency formatting
 373      function format_raw($number, $currency_code = '', $currency_value = '') {
 374        global $currencies, $currency;
 375  
 376        if (empty($currency_code) || !$this->is_set($currency_code)) {
 377          $currency_code = $currency;
 378        }
 379  
 380        if (empty($currency_value) || !is_numeric($currency_value)) {
 381          $currency_value = $currencies->currencies[$currency_code]['value'];
 382        }
 383  
 384        return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
 385      }
 386    }
 387  ?>


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