Advertisement
Guest User

Untitled

a guest
Dec 9th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.18 KB | None | 0 0
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: checkout.index.php 2529 2010-09-05 15:48:16Z zanardi $
  6. * @package VirtueMart
  7. * @subpackage html
  8. * @copyright Copyright (C) 2004-2010 VirtueMart Dev Team - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. mm_showMyFileName( __FILE__ );
  19.  
  20. require_once( CLASSPATH . "ps_checkout.php" );
  21.  
  22. global $mainframe, $vmLogger, $vars;
  23.  
  24. // PayPal API / Express
  25.  
  26. if( file_exists(CLASSPATH . 'payment/ps_paypal_api.php'))
  27. {
  28.     $lang = jfactory::getLanguage();
  29.     $name= $lang->getBackwardLang();
  30.     if( file_exists(CLASSPATH ."payment/paypal_api/languages/lang.".$name.".php"))
  31.         include(CLASSPATH ."payment/paypal_api/languages/lang.".$name.".php");
  32.     else
  33.         include(CLASSPATH ."payment/paypal_api/languages/lang.english.php");
  34.  
  35.     if( file_exists(CLASSPATH . "payment/ps_paypal_api.cfg.php"))
  36.     {
  37.         include_once( CLASSPATH . "payment/ps_paypal_api.cfg.php");
  38.     }
  39.     require_once( CLASSPATH . 'payment/ps_paypal_api.php');
  40.     $paypalActive = ps_paypal_api::isActive();
  41.     $ppex_checkout_details=ps_paypal_api::ppex_getCheckoutDetails();
  42. }
  43. else
  44. {
  45.     $paypalActive = false;
  46. }
  47.  
  48. $paypal_express_checkout = vmGet($_REQUEST, 'ppex',null);
  49. $paypal_express_checkout_payment = vmGet($_REQUEST, 'payment_method_ppex', null);
  50. $paypal_express_checkout_cancel = vmGet($_REQUEST, 'ppex_cancel',null);
  51. if($paypal_express_checkout_cancel) {
  52.     //$GLOBALS['vmLogger']->warning( 'PayPal Zahlung abgebrochen!' );
  53.     require_once( CLASSPATH . 'payment/ps_paypal_api.php');
  54.     ps_paypal_api::destroyPaypalSession();
  55.     $payment_method_id= $_GET['payment_method_id'] = $_REQUEST['payment_method_id'] = 0;
  56.     if( !empty($_GET['ship_to_info_id']) && !empty( $_GET['shipping_rate_id'] ) ) {
  57.         $_POST['checkout_this_step'][] = 'CHECK_OUT_GET_SHIPPING_ADDR';
  58.         $_REQUEST['checkout_last_step'] = 2;
  59.     }
  60. }
  61.  
  62. if($paypal_express_checkout) {
  63.     // Check for token and redirect to PayPal to get one, if not available yet
  64.     $_SESSION['ppex_token'] = $ppex_token=ps_paypal_api::gettoken(1);
  65. }
  66. else if($paypal_express_checkout_payment === "2")
  67. {
  68.     // Check for token at payment select screen and redirect to PayPal to get one, if not available yet
  69.     $_SESSION['ppex_token'] = $ppex_token=ps_paypal_api::gettoken(2);
  70. }
  71.  
  72. $paypal_express_checkout = vmGet($_REQUEST, 'ppex_gecd',null);
  73.  
  74. if(isset($_SESSION['ppex_userdata']) && is_array($_SESSION['ppex_userdata']) && isset($_SESSION['ppex_token']) && $paypalActive) {
  75.  
  76.     if(!isset($auth['user_id']) || $auth['user_id'] <= 0)
  77.     {
  78.         ps_paypal_api::ppex_userLogin($auth);
  79.     }
  80.  
  81.     ps_paypal_api::checkAddress($auth);
  82.  
  83.     $ship_to_info_id = vmGet( $_REQUEST, 'ship_to_info_id');
  84.     $shipping_rate_id = urldecode(vmGet( $_REQUEST, "shipping_rate_id", null ));
  85.  
  86.     $paypal_api_payment_method_id = $payment_method_id = ps_paypal_api::getPaymentMethodId();
  87.  
  88.     $_REQUEST['payment_method_id'] = $payment_method_id;
  89.  
  90.     $Itemid = $sess->getShopItemid();
  91.     if( $auth['user_id'] > 0 ) {
  92.         $show_basket = true;
  93.     } else {
  94.         $show_basket = false;
  95.     }
  96.  
  97.     $current_stage = ps_checkout::get_current_stage();
  98.     $checkout_steps = ps_checkout::get_checkout_steps();
  99.     /*if ($shipping_rate_id && $ship_to_info_id && $payment_method_id && !isset($_GET['checkout_stage'])) {
  100.         $current_stage=count($checkout_steps);
  101.     } elseif( $ship_to_info_id && $payment_method_id && empty($shipping_rate_id) && isset( $_GET['checkout_last_step'] ) && !isset($_GET['checkout_stage'])) {
  102.         $_POST['checkout_this_step'] = $checkout_steps[$current_stage];
  103.         $current_stage++;
  104.     }*/
  105.  
  106.     if(isset($_SESSION['ppex_userdata']['payer_id']))
  107.     {
  108.         ps_paypal_api::checkOutStatus($auth, $checkout_steps, $current_stage, $ship_to_info_id, $paypal_express_checkout);
  109.     }
  110. } else {
  111.     $ship_to_info_id = vmGet( $_REQUEST, 'ship_to_info_id');
  112.     $shipping_rate_id = urldecode(vmGet( $_REQUEST, "shipping_rate_id", null ));
  113.     $payment_method_id = vmGet( $_REQUEST, 'payment_method_id');
  114.  
  115.     if( file_exists(CLASSPATH . "payment/ps_paypal_api.cfg.php")) {
  116.         include_once( CLASSPATH . "payment/ps_paypal_api.cfg.php");
  117.         require_once( CLASSPATH . 'payment/ps_paypal_api.php');
  118.         $paypal_api_payment_method_id = ps_paypal_api::getPaymentMethodId('ps_paypal_api');
  119.     }
  120.  
  121.     $Itemid = $sess->getShopItemid();
  122.  
  123.     /* Decide, which Checkout Step is the next one
  124.     * $checkout_this_step controls the step thru the checkout process
  125.     * we have the following steps
  126.  
  127.     * -CHECK_OUT_GET_SHIPPING_ADDR
  128.     * let the user choose a shipto address
  129.  
  130.     * -CHECK_OUT_GET_SHIPPING_METHOD
  131.     * let the user choose a shipto metho for the ship to address
  132.  
  133.     * -CHECK_OUT_GET_PAYMENT_METHOD
  134.     * let the user choose a payment method
  135.  
  136.     * -CHECK_OUT_GET_FINAL_CONFIRMATION
  137.     * shows a total summary including all payments, taxes, fees etc. and let the user confirm
  138.     */
  139.     if( $auth['user_id'] > 0 ) {
  140.         $show_basket = true;
  141.     } else {
  142.         $show_basket = false;
  143.     }
  144.     $current_stage = ps_checkout::get_current_stage();
  145.     $checkout_steps = ps_checkout::get_checkout_steps();
  146.  
  147. }
  148.  
  149. if( !empty( $paypal_api_payment_method_id ) && in_array('CHECK_OUT_GET_PAYMENT_METHOD', $checkout_steps[$current_stage]) ) {
  150.     if($paypalActive)
  151.     {
  152.         // Paypal API / Express
  153.         echo '<script type="text/javascript">window.addEvent("domready", function() {
  154.         $$(\'label\').each( function(el) { if(el.htmlFor == "'.ps_paypal_api::getPaymentMethodName().'") { el.innerHTML = "Credit Card";} });
  155.         });</script>';
  156.     }
  157. }
  158.  
  159. if( in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]) ) {
  160.     $next_page = 'checkout.thankyou';
  161.     if( sizeof($checkout_steps[$current_stage]) > 1 ) {
  162.         include_once( PAGEPATH . 'basket.php' );
  163.     } else {
  164.         include_once( PAGEPATH . 'ro_basket.php' );
  165.     }
  166. } else {
  167.     $next_page = 'checkout.index';
  168.     include_once( PAGEPATH . 'basket.php' );
  169. }
  170.  
  171. // Get the zone quantity after it has been calculated in the basket
  172. $zone_qty = vmGet( $vars, 'zone_qty');
  173.  
  174. //Check for express checkout from paypal
  175. if(isset($_SESSION['ppex_userdata']) && is_array($_SESSION['ppex_userdata']) && isset($_SESSION['ppex_token']) && $paypalActive)
  176. {
  177.     //If the $paypal_express_checkout is equal to 2
  178.     //Then we just came from paypal express which originated from
  179.     //The payment selection screen
  180.     if((int)$paypal_express_checkout == 2)
  181.     {
  182.         if(in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]))
  183.         {
  184.             if($perm->is_registered_customer($auth['user_id']))
  185.             {
  186.  
  187.                 //Create our array like the form
  188.                 //Just in case so we don't mess anything up when
  189.                 //doing ps_checkout->process()
  190.                 $checkoutData = Array('option' => 'com_virtuemart',
  191.                                       'Itemid' => $Itemid,
  192.                                       'user_id' => (int)$auth['user_id'],
  193.                                       'page' => 'checkout.thankyou',
  194.                                       'func' => 'checkoutProcess',
  195.                                       'zone_qty' => $zone_qty,
  196.                                       'ship_to_info_id' => $ship_to_info_id,
  197.                                       'shipping_rate_id' => urlencode($shipping_rate_id),
  198.                                       'ship_method_id' => $shipping_rate_id,
  199.                                       'payment_method_id' => $payment_method_id,
  200.                                       'checkout_last_step' => '4',
  201.                                       'checkout_this_step' => array('CHECK_OUT_GET_FINAL_CONFIRMATION'));
  202.  
  203.  
  204.                 //Make sure to set the request variables before creating a new ps_checkout();
  205.                 //Just in case
  206.                 $_REQUEST['shipping_rate_id'] = urlencode($shipping_rate_id);
  207.                 $_REQUEST['ship_method_id'] = $shipping_rate_id;
  208.                 $_REQUEST['user_id'] = (int)$auth['user_id'];
  209.                 $_REQUEST['zone_qty'] = $zone_qty;
  210.                 $_REQUEST['ship_to_info_id'] = $ship_to_info_id;
  211.                 $_REQUEST['payment_method_id'] = $payment_method_id;
  212.  
  213.                 //Set our $_SESSION variable for DoExpressCheckout
  214.                 //So we know which way we came from
  215.                 $_SESSION['ppex_cart_ecm'] = '1';
  216.  
  217.                 $checkout = new ps_checkout();
  218.                 //Try to process the order
  219.                 //On Success redirect to checkout.thankyou
  220.                 if($checkout->process($checkoutData))
  221.                 {
  222.                     vmRedirect( $sess->url( 'index.php?page=checkout.thankyou&order_id='.$checkoutData['order_id'], false, false ) );
  223.                 }
  224.             }
  225.             else
  226.             {
  227.                 $vmLogger->err(@$nvp_common_015);
  228.             }
  229.         }
  230.     }
  231. }
  232.  
  233. $theme = new $GLOBALS['VM_THEMECLASS']();
  234.  
  235. $theme->set_vars( // Import these values into the template files
  236.     array( 'zone_qty' => $zone_qty,
  237.             'ship_to_info_id' => $ship_to_info_id,
  238.             'shipping_rate_id' => $shipping_rate_id,
  239.             'current_stage' => $current_stage,
  240.             'payment_method_id' => $payment_method_id,
  241.             'weight_total' => $weight_total,
  242.             'Itemid' => $Itemid
  243.             )
  244.     );
  245.  
  246. if ($cart["idx"] > 0) {
  247.  
  248.     echo '<h3>'. $VM_LANG->_('PHPSHOP_CHECKOUT_TITLE') .'</h3>';
  249.  
  250.     if (!defined('_MIN_POV_REACHED')) {
  251.         echo $basket_html;
  252.         ?>
  253.         <div align="center">
  254.             <script type="text/javascript">alert('<?php echo $VM_LANG->_('PHPSHOP_CHECKOUT_ERR_MIN_POV',false) ?>');</script>
  255.             <strong><?php echo $VM_LANG->_('PHPSHOP_CHECKOUT_ERR_MIN_POV') ?></strong><br />
  256.             <strong><?php echo $VM_LANG->_('PHPSHOP_CHECKOUT_ERR_MIN_POV2') . " ".$CURRENCY_DISPLAY->getFullValue($_SESSION['minimum_pov']) ?></strong>
  257.         </div><?php
  258.         return;
  259.     }
  260.  
  261.     // We have something in the Card so move on
  262.     if ($perm->is_registered_customer($auth['user_id'])) { // user is logged in and a registered customer
  263.  
  264.     $basket_html .= '<form action="'. $sess->url( SECUREURL."index.php?page=".$next_page."&checkout_last_step=".$current_stage) .'" method="post" name="adminForm">
  265.         <input type="hidden" name="option" value="com_virtuemart" />
  266.         <input type="hidden" name="Itemid" value="'. $Itemid .'" />
  267.         <input type="hidden" name="user_id" value="'. $auth['user_id'] .'" />
  268.         <input type="hidden" name="page" value="'. $next_page .'" />
  269.         <input type="hidden" name="func" value="checkoutProcess" />
  270.         <input type="hidden" name="zone_qty" value="'. $zone_qty .'" />
  271.        <input type="hidden" name="ship_to_info_id" value="'. $ship_to_info_id .'" />
  272.        <input type="hidden" name="shipping_rate_id" value="'. urlencode($shipping_rate_id) .'" />
  273.        <input type="hidden" name="payment_method_id" value="'. $payment_method_id .'" />
  274.        <input type="hidden" name="checkout_last_step" value="'. $current_stage .'" />';
  275.        
  276.  
  277.         $theme->set( 'basket_html', $basket_html );
  278.  
  279.         // CHECK_OUT_GET_SHIPPING_ADDR
  280.         // Lets the user pick or add an alternative Shipping Address
  281.         if( in_array('CHECK_OUT_GET_SHIPPING_ADDR', $checkout_steps[$current_stage]) ) {
  282.             echo '<a name="CHECK_OUT_GET_SHIPPING_ADDR"></a>';
  283.             echo $theme->fetch( 'checkout/get_shipping_address.tpl.php');
  284.             $theme->set('basket_html', '');
  285.         }
  286.         // CHECK_OUT_GET_SHIPPING_METHOD
  287.         // Let the user pick a shipping method
  288.         if( in_array('CHECK_OUT_GET_SHIPPING_METHOD', $checkout_steps[$current_stage]) ) {
  289.             echo '<a name="CHECK_OUT_GET_SHIPPING_METHOD"></a>';
  290.             echo $theme->fetch( 'checkout/get_shipping_method.tpl.php');
  291.             $theme->set('basket_html', '');
  292.         }
  293.  
  294.         // -CHECK_OUT_GET_PAYMENT_METHOD
  295.         // let the user choose a payment method
  296.         if( in_array('CHECK_OUT_GET_PAYMENT_METHOD', $checkout_steps[$current_stage]) ) {
  297.             echo '<a name="CHECK_OUT_GET_PAYMENT_METHOD"></a>';
  298.  
  299.                 if(!empty( $paypal_api_payment_method_id ) && $paypalActive)
  300.                 {
  301.                     echo $theme->fetch('checkout/get_payment_method_paypal_ex.tpl.php');
  302.                 }
  303.                 else
  304.                 {
  305.                     echo $theme->fetch( 'checkout/get_payment_method.tpl.php');
  306.                 }
  307.  
  308.             $theme->set('basket_html', '');
  309.         }
  310.         // -CHECK_OUT_GET_FINAL_CONFIRMATION
  311.         // shows a total summary including all payments, taxes, fees etc.
  312.         if( in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]) ) {
  313.             echo '<a name="CHECK_OUT_GET_FINAL_CONFIRMATION"></a>';
  314.             // Now let the user confirm
  315.             echo $theme->fetch( 'checkout/get_final_confirmation.tpl.php');
  316.             $theme->set('basket_html', '');
  317.         }
  318.         ?>
  319.     <br /><?php
  320.         foreach( $checkout_steps[$current_stage] as $this_step ) {
  321.             echo '<input type="hidden" name="checkout_this_step[]" value="'.$this_step.'" />';
  322.         }
  323.  
  324.         // Set Dynamic Page Title: "Checkout: Step x of x"
  325.         $ii = 0;
  326.         for( $i = 1; $i < 5; $i++ ) {
  327.             if( isset( $checkout_steps[$i] ) ) {
  328.                 $ii += 1;
  329.                 if( in_array($this_step, $checkout_steps[$i] ) ) {
  330.                     $mainframe->setPageTitle( sprintf( $VM_LANG->_('VM_CHECKOUT_TITLE_TAG'), $ii, count($checkout_steps) ));
  331.                     break;
  332.                 }
  333.             }
  334.         }
  335.  
  336.         if( !in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]) ) {
  337.             ?>
  338.                 <div align="center">
  339.                 <input type="submit" class="button" name="formSubmit" value="<?php echo $VM_LANG->_('PHPSHOP_CHECKOUT_NEXT');?> &gt;&gt;" />
  340.                 </div>
  341.             <?php
  342.         }
  343.         // Close the Checkout Form, which was opened in the first checkout template using the variable $basket_html
  344.         echo '</form>';
  345.  
  346.          if( !in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage]) ) {
  347.                 echo "<script type=\"text/javascript\"><!--
  348.                    function submit_order( form ) { return true; }
  349.                    --></script>";
  350.             }
  351.         }
  352.  
  353.         else {
  354.  
  355.           if (!empty($auth['user_id'])) {
  356.             // USER IS LOGGED IN, BUT NO REGISTERED CUSTOMER
  357.             // WE NEED SOME ADDITIONAL INFORMATION HERE,
  358.             // SO REDIRECT HIM TO shop/shopper_add
  359.             $vmLogger->info( $VM_LANG->_('PHPSHOP_NO_CUSTOMER',false) );
  360.  
  361.             include(PAGEPATH. 'checkout_register_form.php');
  362.           }
  363.  
  364.           else {
  365.             // user is not logged in
  366.             echo $theme->fetch( 'checkout/login_registration.tpl.php' );
  367.           }
  368.     }
  369. }
  370. else {
  371.     vmRedirect( $sess->url( 'index.php?page=shop.cart', false, false ) );
  372. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement