[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/ext/modules/payment/paypal/ -> express_uk.php (source)

   1  <?php
   2  /*
   3    $Id: express_uk.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    chdir('../../../../');
  14    require ('includes/application_top.php');
  15  
  16  // if the customer is not logged on, redirect them to the login page
  17    if (!tep_session_is_registered('customer_id')) {
  18      $snapshot = array('page' => 'ext/modules/payment/paypal/express_uk.php',
  19                        'mode' => $request_type,
  20                        'get' => $HTTP_GET_VARS,
  21                        'post' => $HTTP_POST_VARS);
  22  
  23      $navigation->set_snapshot($snapshot);
  24  
  25      tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
  26    }
  27  
  28  // if there is nothing in the customers cart, redirect them to the shopping cart page
  29    if ($cart->count_contents() < 1) {
  30      tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  31    }
  32  
  33    require(DIR_WS_LANGUAGES . $language . '/modules/payment/paypal_uk_express.php');
  34    require ('includes/modules/payment/paypal_uk_express.php');
  35  
  36    $paypal_uk_express = new paypal_uk_express();
  37  
  38    if (!$paypal_uk_express->check() || !$paypal_uk_express->enabled) {
  39      tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  40    }
  41  
  42    if (MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_SERVER == 'Live') {
  43      $api_url = 'https://payflowpro.verisign.com/transaction';
  44      $paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
  45    } else {
  46      $api_url = 'https://pilot-payflowpro.verisign.com/transaction';
  47      $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
  48    }
  49  
  50    if (!tep_session_is_registered('sendto')) {
  51      tep_session_register('sendto');
  52      $sendto = $customer_default_address_id;
  53    }
  54  
  55    if (!tep_session_is_registered('billto')) {
  56      tep_session_register('billto');
  57      $billto = $customer_default_address_id;
  58    }
  59  
  60  // register a random ID in the session to check throughout the checkout procedure
  61  // against alterations in the shopping cart contents
  62    if (!tep_session_is_registered('cartID')) tep_session_register('cartID');
  63    $cartID = $cart->cartID;
  64  
  65    $params = array('USER' => (tep_not_null(MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME) ? MODULE_PAYMENT_PAYPAL_UK_EXPRESS_USERNAME : MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR),
  66                    'VENDOR' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_VENDOR,
  67                    'PARTNER' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PARTNER,
  68                    'PWD' => MODULE_PAYMENT_PAYPAL_UK_EXPRESS_PASSWORD,
  69                    'TENDER' => 'P',
  70                    'TRXTYPE' => ((MODULE_PAYMENT_PAYPAL_UK_EXPRESS_TRANSACTION_METHOD == 'Sale') ? 'S' : 'A'));
  71  
  72    switch ($HTTP_GET_VARS['osC_Action']) {
  73      case 'retrieve':
  74        $params['ACTION'] = 'G';
  75        $params['TOKEN'] = $HTTP_GET_VARS['token'];
  76  
  77        $post_string = '';
  78  
  79        foreach ($params as $key => $value) {
  80          $post_string .= $key . '[' . strlen(trim($value)) . ']=' . trim($value) . '&';
  81        }
  82  
  83        $post_string = substr($post_string, 0, -1);
  84  
  85        $response = $paypal_uk_express->sendTransactionToGateway($api_url, $post_string, array('X-VPS-REQUEST-ID: ' . md5($cartID . tep_session_id() . rand())));
  86        $response_array = array();
  87        parse_str($response, $response_array);
  88  
  89        if ($response_array['RESULT'] == '0') {
  90          include (DIR_WS_CLASSES . 'order.php');
  91  
  92          if ($cart->get_content_type() != 'virtual') {
  93            $country_iso_code_2 = tep_db_prepare_input($response_array['SHIPTOCOUNTRY']);
  94            $zone_code = tep_db_prepare_input($response_array['SHIPTOSTATE']);
  95  
  96            $country_query = tep_db_query("select countries_id, countries_name, countries_iso_code_2, countries_iso_code_3, address_format_id from " . TABLE_COUNTRIES . " where countries_iso_code_2 = '" . tep_db_input($country_iso_code_2) . "'");
  97            $country = tep_db_fetch_array($country_query);
  98  
  99            $zone_name = $response_array['SHIPTOSTATE'];
 100            $zone_id = 0;
 101  
 102            $zone_query = tep_db_query("select zone_id, zone_name from " . TABLE_ZONES . " where zone_country_id = '" . (int)$country['countries_id'] . "' and zone_code = '" . tep_db_input($zone_code) . "'");
 103            if (tep_db_num_rows($zone_query)) {
 104              $zone = tep_db_fetch_array($zone_query);
 105  
 106              $zone_name = $zone['zone_name'];
 107              $zone_id = $zone['zone_id'];
 108            }
 109  
 110            $sendto = array('firstname' => $response_array['FIRSTNAME'],
 111                            'lastname' => $response_array['LASTNAME'],
 112                            'company' => '',
 113                            'street_address' => $response_array['SHIPTOSTREET'],
 114                            'suburb' => '',
 115                            'postcode' => $response_array['SHIPTOZIP'],
 116                            'city' => $response_array['SHIPTOCITY'],
 117                            'zone_id' => $zone_id,
 118                            'zone_name' => $zone_name,
 119                            'country_id' => $country['countries_id'],
 120                            'country_name' => $country['countries_name'],
 121                            'country_iso_code_2' => $country['countries_iso_code_2'],
 122                            'country_iso_code_3' => $country['countries_iso_code_3'],
 123                            'address_format_id' => ($country['address_format_id'] > 0 ? $country['address_format_id'] : '1'));
 124  
 125            $billto = $sendto;
 126  
 127            $order = new order;
 128  
 129            $total_weight = $cart->show_weight();
 130            $total_count = $cart->count_contents();
 131  
 132  // load all enabled shipping modules
 133            include (DIR_WS_CLASSES . 'shipping.php');
 134            $shipping_modules = new shipping;
 135  
 136            $free_shipping = false;
 137  
 138            if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
 139              $pass = false;
 140  
 141              switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
 142                case 'national':
 143                  if ($order->delivery['country_id'] == STORE_COUNTRY) {
 144                    $pass = true;
 145                  }
 146                  break;
 147  
 148                case 'international':
 149                  if ($order->delivery['country_id'] != STORE_COUNTRY) {
 150                    $pass = true;
 151                  }
 152                  break;
 153  
 154                case 'both':
 155                  $pass = true;
 156                  break;
 157              }
 158  
 159              if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
 160                $free_shipping = true;
 161  
 162                include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
 163              }
 164            }
 165  
 166            if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
 167            $shipping = false;
 168  
 169            if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
 170              if ($free_shipping == true) {
 171                $shipping = 'free_free';
 172              } else {
 173  // get all available shipping quotes
 174                $quotes = $shipping_modules->quote();
 175  
 176  // select cheapest shipping method
 177                $shipping = $shipping_modules->cheapest();
 178                $shipping = $shipping['id'];
 179              }
 180            }
 181  
 182            if (strpos($shipping, '_')) {
 183              list($module, $method) = explode('_', $shipping);
 184  
 185              if ( is_object($$module) || ($shipping == 'free_free') ) {
 186                if ($shipping == 'free_free') {
 187                  $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
 188                  $quote[0]['methods'][0]['cost'] = '0';
 189                } else {
 190                  $quote = $shipping_modules->quote($method, $module);
 191                }
 192  
 193                if (isset($quote['error'])) {
 194                  tep_session_unregister('shipping');
 195  
 196                  tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 197                } else {
 198                  if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
 199                    $shipping = array('id' => $shipping,
 200                                      'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
 201                                      'cost' => $quote[0]['methods'][0]['cost']);
 202                  }
 203                }
 204              }
 205            }
 206  
 207            if (!tep_session_is_registered('payment')) tep_session_register('payment');
 208            $payment = $paypal_uk_express->code;
 209  
 210            if (!tep_session_is_registered('ppeuk_token')) tep_session_register('ppeuk_token');
 211            $ppeuk_token = $response_array['TOKEN'];
 212  
 213            if (!tep_session_is_registered('ppeuk_payerid')) tep_session_register('ppeuk_payerid');
 214            $ppeuk_payerid = $response_array['PAYERID'];
 215  
 216            tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'));
 217          } else {
 218            if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
 219            $shipping = false;
 220  
 221            $sendto = false;
 222  
 223            if (!tep_session_is_registered('payment')) tep_session_register('payment');
 224            $payment = $paypal_uk_express->code;
 225  
 226            if (!tep_session_is_registered('ppeuk_token')) tep_session_register('ppeuk_token');
 227            $ppeuk_token = $response_array['TOKEN'];
 228  
 229            if (!tep_session_is_registered('ppeuk_payerid')) tep_session_register('ppeuk_payerid');
 230            $ppeuk_payerid = $response_array['PAYERID'];
 231  
 232            tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'));
 233          }
 234        } else {
 235          switch ($response_array['RESULT']) {
 236            case '1':
 237            case '26':
 238              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_CFG_ERROR;
 239              break;
 240  
 241            case '7':
 242              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_ADDRESS;
 243              break;
 244  
 245            case '12':
 246              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_DECLINED;
 247              break;
 248  
 249            case '1000':
 250              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_EXPRESS_DISABLED;
 251              break;
 252  
 253            default:
 254              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_GENERAL;
 255              break;
 256          }
 257  
 258          tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($error_message), 'SSL'));
 259        }
 260  
 261        break;
 262  
 263      default:
 264        include (DIR_WS_CLASSES . 'order.php');
 265        $order = new order;
 266  
 267        $params['ACTION'] = 'S';
 268        $params['CURRENCY'] = $order->info['currency'];
 269        $params['EMAIL'] = $order->customer['email_address'];
 270        $params['AMT'] = $paypal_uk_express->format_raw($order->info['total']);
 271        $params['RETURNURL'] = tep_href_link('ext/modules/payment/paypal/express_uk.php', 'osC_Action=retrieve', 'SSL', true, false);
 272        $params['CANCELURL'] = tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL', true, false);
 273  
 274        if ($order->content_type == 'virtual') {
 275          $params['NOSHIPPING'] = '1';
 276        }
 277  
 278        $post_string = '';
 279  
 280        foreach ($params as $key => $value) {
 281          $post_string .= $key . '[' . strlen(trim($value)) . ']=' . trim($value) . '&';
 282        }
 283  
 284        $post_string = substr($post_string, 0, -1);
 285  
 286        $response = $paypal_uk_express->sendTransactionToGateway($api_url, $post_string, array('X-VPS-REQUEST-ID: ' . md5($cartID . tep_session_id() . rand())));
 287        $response_array = array();
 288        parse_str($response, $response_array);
 289  
 290        if ($response_array['RESULT'] == '0') {
 291          tep_redirect($paypal_url . '&token=' . $response_array['TOKEN']);
 292        } else {
 293          switch ($response_array['RESULT']) {
 294            case '1':
 295            case '26':
 296              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_CFG_ERROR;
 297              break;
 298  
 299            case '1000':
 300              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_EXPRESS_DISABLED;
 301              break;
 302  
 303            default:
 304              $error_message = MODULE_PAYMENT_PAYPAL_UK_EXPRESS_ERROR_GENERAL;
 305              break;
 306          }
 307  
 308          tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($error_message), 'SSL'));
 309        }
 310  
 311        break;
 312    }
 313  
 314    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
 315  
 316    require (DIR_WS_INCLUDES . 'application_bottom.php');
 317  ?>


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