[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*
   3    $Id: 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    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.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 ('includes/modules/payment/paypal_express.php');
  34  
  35    $paypal_express = new paypal_express();
  36  
  37    if (!$paypal_express->check() || !$paypal_express->enabled) {
  38      tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
  39    }
  40  
  41    if (MODULE_PAYMENT_PAYPAL_EXPRESS_TRANSACTION_SERVER == 'Live') {
  42      $api_url = 'https://api-3t.paypal.com/nvp';
  43      $paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
  44    } else {
  45      $api_url = 'https://api-3t.sandbox.paypal.com/nvp';
  46      $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
  47    }
  48  
  49    if (!tep_session_is_registered('sendto')) {
  50      tep_session_register('sendto');
  51      $sendto = $customer_default_address_id;
  52    }
  53  
  54    if (!tep_session_is_registered('billto')) {
  55      tep_session_register('billto');
  56      $billto = $customer_default_address_id;
  57    }
  58  
  59  // register a random ID in the session to check throughout the checkout procedure
  60  // against alterations in the shopping cart contents
  61    if (!tep_session_is_registered('cartID')) tep_session_register('cartID');
  62    $cartID = $cart->cartID;
  63  
  64    $params = array('USER' => MODULE_PAYMENT_PAYPAL_EXPRESS_API_USERNAME,
  65                    'PWD' => MODULE_PAYMENT_PAYPAL_EXPRESS_API_PASSWORD,
  66                    'VERSION' => '3.2',
  67                    'SIGNATURE' => MODULE_PAYMENT_PAYPAL_EXPRESS_API_SIGNATURE);
  68  
  69    switch ($HTTP_GET_VARS['osC_Action']) {
  70      case 'retrieve':
  71        $params['METHOD'] = 'GetExpressCheckoutDetails';
  72        $params['TOKEN'] = $HTTP_GET_VARS['token'];
  73  
  74        $post_string = '';
  75  
  76        foreach ($params as $key => $value) {
  77          $post_string .= $key . '=' . urlencode(trim($value)) . '&';
  78        }
  79  
  80        $post_string = substr($post_string, 0, -1);
  81  
  82        $response = $paypal_express->sendTransactionToGateway($api_url, $post_string);
  83        $response_array = array();
  84        parse_str($response, $response_array);
  85  
  86        if (($response_array['ACK'] == 'Success') || ($response_array['ACK'] == 'SuccessWithWarning')) {
  87          include (DIR_WS_CLASSES . 'order.php');
  88  
  89          if ($cart->get_content_type() != 'virtual') {
  90            $country_iso_code_2 = tep_db_prepare_input($response_array['SHIPTOCOUNTRYCODE']);
  91            $zone_code = tep_db_prepare_input($response_array['SHIPTOSTATE']);
  92  
  93            $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) . "'");
  94            $country = tep_db_fetch_array($country_query);
  95  
  96            $zone_name = $response_array['SHIPTOSTATE'];
  97            $zone_id = 0;
  98  
  99            $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) . "'");
 100            if (tep_db_num_rows($zone_query)) {
 101              $zone = tep_db_fetch_array($zone_query);
 102  
 103              $zone_name = $zone['zone_name'];
 104              $zone_id = $zone['zone_id'];
 105            }
 106  
 107            $sendto = array('firstname' => substr($response_array['SHIPTONAME'], 0, strpos($response_array['SHIPTONAME'], ' ')),
 108                            'lastname' => substr($response_array['SHIPTONAME'], strpos($response_array['SHIPTONAME'], ' ')+1),
 109                            'company' => '',
 110                            'street_address' => $response_array['SHIPTOSTREET'],
 111                            'suburb' => '',
 112                            'postcode' => $response_array['SHIPTOZIP'],
 113                            'city' => $response_array['SHIPTOCITY'],
 114                            'zone_id' => $zone_id,
 115                            'zone_name' => $zone_name,
 116                            'country_id' => $country['countries_id'],
 117                            'country_name' => $country['countries_name'],
 118                            'country_iso_code_2' => $country['countries_iso_code_2'],
 119                            'country_iso_code_3' => $country['countries_iso_code_3'],
 120                            'address_format_id' => ($country['address_format_id'] > 0 ? $country['address_format_id'] : '1'));
 121  
 122            $billto = $sendto;
 123  
 124            $order = new order;
 125  
 126            $total_weight = $cart->show_weight();
 127            $total_count = $cart->count_contents();
 128  
 129  // load all enabled shipping modules
 130            include (DIR_WS_CLASSES . 'shipping.php');
 131            $shipping_modules = new shipping;
 132  
 133            $free_shipping = false;
 134  
 135            if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
 136              $pass = false;
 137  
 138              switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
 139                case 'national':
 140                  if ($order->delivery['country_id'] == STORE_COUNTRY) {
 141                    $pass = true;
 142                  }
 143                  break;
 144  
 145                case 'international':
 146                  if ($order->delivery['country_id'] != STORE_COUNTRY) {
 147                    $pass = true;
 148                  }
 149                  break;
 150  
 151                case 'both':
 152                  $pass = true;
 153                  break;
 154              }
 155  
 156              if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
 157                $free_shipping = true;
 158  
 159                include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
 160              }
 161            }
 162  
 163            if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
 164            $shipping = false;
 165  
 166            if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
 167              if ($free_shipping == true) {
 168                $shipping = 'free_free';
 169              } else {
 170  // get all available shipping quotes
 171                $quotes = $shipping_modules->quote();
 172  
 173  // select cheapest shipping method
 174                $shipping = $shipping_modules->cheapest();
 175                $shipping = $shipping['id'];
 176              }
 177            }
 178  
 179            if (strpos($shipping, '_')) {
 180              list($module, $method) = explode('_', $shipping);
 181  
 182              if ( is_object($$module) || ($shipping == 'free_free') ) {
 183                if ($shipping == 'free_free') {
 184                  $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
 185                  $quote[0]['methods'][0]['cost'] = '0';
 186                } else {
 187                  $quote = $shipping_modules->quote($method, $module);
 188                }
 189  
 190                if (isset($quote['error'])) {
 191                  tep_session_unregister('shipping');
 192  
 193                  tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
 194                } else {
 195                  if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
 196                    $shipping = array('id' => $shipping,
 197                                      'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
 198                                      'cost' => $quote[0]['methods'][0]['cost']);
 199                  }
 200                }
 201              }
 202            }
 203  
 204            if (!tep_session_is_registered('payment')) tep_session_register('payment');
 205            $payment = $paypal_express->code;
 206  
 207            if (!tep_session_is_registered('ppe_token')) tep_session_register('ppe_token');
 208            $ppe_token = $response_array['TOKEN'];
 209  
 210            if (!tep_session_is_registered('ppe_payerid')) tep_session_register('ppe_payerid');
 211            $ppe_payerid = $response_array['PAYERID'];
 212  
 213            tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'));
 214          } else {
 215            if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
 216            $shipping = false;
 217  
 218            $sendto = false;
 219  
 220            if (!tep_session_is_registered('payment')) tep_session_register('payment');
 221            $payment = $paypal_express->code;
 222  
 223            if (!tep_session_is_registered('ppe_token')) tep_session_register('ppe_token');
 224            $ppe_token = $response_array['TOKEN'];
 225  
 226            if (!tep_session_is_registered('ppe_payerid')) tep_session_register('ppe_payerid');
 227            $ppe_payerid = $response_array['PAYERID'];
 228  
 229            tep_redirect(tep_href_link(FILENAME_CHECKOUT_CONFIRMATION, '', 'SSL'));
 230          }
 231        } else {
 232          tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($response_array['L_LONGMESSAGE0']), 'SSL'));
 233        }
 234  
 235        break;
 236  
 237      default:
 238        include (DIR_WS_CLASSES . 'order.php');
 239        $order = new order;
 240  
 241        $params['METHOD'] = 'SetExpressCheckout';
 242        $params['PAYMENTACTION'] = ((MODULE_PAYMENT_PAYPAL_EXPRESS_TRANSACTION_METHOD == 'Sale') ? 'Sale' : 'Authorization');
 243        $params['RETURNURL'] = tep_href_link('ext/modules/payment/paypal/express.php', 'osC_Action=retrieve', 'SSL', true, false);
 244        $params['CANCELURL'] = tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL', true, false);
 245        $params['AMT'] = $paypal_express->format_raw($order->info['total']);
 246        $params['CURRENCYCODE'] = $order->info['currency'];
 247  
 248        if ($order->content_type == 'virtual') {
 249          $params['NOSHIPPING'] = '1';
 250        }
 251  
 252        $post_string = '';
 253  
 254        foreach ($params as $key => $value) {
 255          $post_string .= $key . '=' . urlencode(trim($value)) . '&';
 256        }
 257  
 258        $post_string = substr($post_string, 0, -1);
 259  
 260        $response = $paypal_express->sendTransactionToGateway($api_url, $post_string);
 261        $response_array = array();
 262        parse_str($response, $response_array);
 263  
 264        if (($response_array['ACK'] == 'Success') || ($response_array['ACK'] == 'SuccessWithWarning')) {
 265          tep_redirect($paypal_url . '&token=' . $response_array['TOKEN']);
 266        } else {
 267          tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . stripslashes($response_array['L_LONGMESSAGE0']), 'SSL'));
 268        }
 269  
 270        break;
 271    }
 272  
 273    tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
 274  
 275    require (DIR_WS_INCLUDES . 'application_bottom.php');
 276  ?>


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