예제 #1
0
 function gettoken($ppex = 1, $order_total = 0)
 {
     global $mainframe, $vendor_currency, $vars;
     include_once CLASSPATH . "payment/" . __CLASS__ . ".cfg.php";
     require_once dirname(__FILE__) . '/paypal_api/CallerService.php';
     require_once CLASSPATH . 'ps_checkout.php';
     $serverName = $_SERVER['SERVER_NAME'];
     $serverPort = $_SERVER['SERVER_PORT'];
     $url = dirname('http://' . $serverName . ':' . $serverPort . $_SERVER['REQUEST_URI']);
     /* The returnURL is the location where buyers return when a
     		payment has been succesfully authorized.
     		The cancelURL is the location buyers are sent to when they hit the
     		cancel button during authorization of payment during the PayPal flow
     		*/
     $ship_to_info_id = vmGet($_REQUEST, 'ship_to_info_id');
     $shipping_rate_id = urldecode(vmGet($_REQUEST, "shipping_rate_id", null));
     $payment_method_id = vmGet($_REQUEST, 'payment_method_id');
     $checkout_this_step = ps_checkout::get_current_stage();
     $returnURL = urlencode($url . '/index.php?page=checkout.index&option=com_virtuemart&checkout_stage=' . $checkout_this_step . '&ship_to_info_id=' . $ship_to_info_id . '&shipping_rate_id=' . urlencode($shipping_rate_id) . '&ppex_gecd=' . $ppex);
     $lastpage = vmGet($_SERVER, 'HTTP_REFERER');
     if (strpos($lastpage, 'page=shop.cart') !== false) {
         $cancelURL = urlencode($url . '/index.php?page=shop.cart&option=com_virtuemart&ppex_cancel=1');
     } else {
         $cancelURL = urlencode($url . '/index.php?page=checkout.index&option=com_virtuemart&checkout_stage=' . ($checkout_this_step - 1) . '&ship_to_info_id=' . $ship_to_info_id . '&shipping_rate_id=' . $shipping_rate_id . '&ppex_cancel=1');
     }
     $gp_returnURL = urlencode($url . '/index.php?page=checkout.generic_result&option=com_virtuemart&result=success');
     $gp_cancelURL = urlencode($url . '/index.php?page=checkout.generic_result&option=com_virtuemart&result=cancel');
     $bank_pending_URL = urlencode($url . '/index.php?page=checkout.generic_result&option=com_virtuemart&result=pending');
     require_once CLASSPATH . 'ps_checkout.php';
     $ps_checkout = new ps_checkout();
     $order_totals = $ps_checkout->calc_order_totals($vars);
     $useshipping = PAYPAL_API_USE_SHIPPING;
     $lang = jfactory::getLanguage();
     $lang_arr = explode('-', $lang->gettag());
     $localecode = strtoupper($lang_arr[1]);
     $nvpstr = "&CALLBACKTIMEOUT=4&CALLBACK=&ReturnUrl=" . $returnURL . "&CANCELURL=" . $cancelURL . "&HDRIMG=" . PAYPAL_API_IMAGEURL . "&GIROPAYCANCELURL=" . $gp_cancelURL . "&GIROPAYSUCCESSURL=" . $gp_returnURL . "&BANKTXNPENDINGURL=" . $bank_pending_URL . "&LOCALECODE={$localecode}&CURRENCYCODE={$vendor_currency}&PAYMENTACTION=" . PAYPAL_API_PAYMENTTYPE;
     if (!empty($ship_to_info_id) && $useshipping == '1') {
         $dbst = new ps_DB();
         $qt = "SELECT * FROM #__{vm}_user_info WHERE user_info_id='" . $ship_to_info_id . "'";
         $dbst->query($qt);
         if ($dbst->next_record()) {
             $db_new = new ps_DB();
             $db_new->query("SELECT `country_2_code` FROM `#__{vm}_country` WHERE `country_3_code`='" . substr($dbst->f("country"), 0, 60) . "'");
             $db_new->next_record();
             $nvpstr .= '&ADDROVERRIDE=1&SHIPTONAME=' . urlencode($dbst->f('first_name') . ' ' . $dbst->f('last_name')) . "&SHIPTOSTREET=" . urlencode($dbst->f('address_1')) . "&SHIPTOSTREET2=" . urlencode($dbst->f('address_2')) . "&SHIPTOCITY=" . urlencode($dbst->f('city')) . "&SHIPTOSTATE=" . urlencode($dbst->f('state')) . "&SHIPTOZIP=" . urlencode($dbst->f('zip')) . "&SHIPTOCOUNTRYCODE=" . urlencode($db_new->f('country_2_code'));
         }
     }
     $nvpstr .= ps_paypal_api::getCartnvpstr($order_totals);
     $amt = round($order_totals['order_total'], 2);
     $shippingamt = round($order_totals['order_shipping'] + $order_totals['order_shipping_tax'], 2);
     //$taxamt = $order_totals['order_tax'];
     // to avoid rounding issues, calculates tax as a differenct between total amount and other items
     $taxamt = $amt - $shippingamt - $order_totals['item_total'];
     $nvpstr .= "&AMT={$amt}" . "&TAXAMT={$taxamt}" . "&SHIPPINGAMT={$shippingamt}";
     /* Make the call to PayPal to set the Express Checkout token
     		If the API call succeded, then redirect the buyer to PayPal
     		to begin to authorize payment.  If an error occured, show the
     		resulting errors
     		*/
     $resArray = hash_call("SetExpressCheckout", $nvpstr);
     $_SESSION['reshash'] = $resArray;
     $ack = strtoupper($resArray["ACK"]);
     if ($ack == "SUCCESS") {
         // Redirect to paypal.com here
         $token = urldecode($resArray["TOKEN"]);
         $_SESSION['ppex_token'] = $token;
         $DOMAIN = PAYPAL_API_DEBUG == 1 ? 'www.sandbox.paypal.com' : 'www.paypal.com';
         if ((int) $ppex == 2) {
             $payPalURL = 'https://' . $DOMAIN . '/webscr?cmd=_express-checkout&useraction=commit&token=' . $token;
         } else {
             $payPalURL = 'https://' . $DOMAIN . '/webscr?cmd=_express-checkout&token=' . $token;
         }
         header("Location: " . $payPalURL);
         $mainframe->close();
     } else {
         //Redirecting to APIError.php to display errors.
         $location = $url . "/index.php?option=com_virtuemart&page=shop.cart&ppex_error=1";
         if ($_SERVER['SERVER_NAME'] == 'localhost') {
             echo "<pre>";
             print_r($resArray);
             echo "</pre>";
             echo "<p>" . str_replace("&", "<br />&", $nvpstr) . "</p>";
         }
         $error = ps_paypal_api::NVP_ErrorToText($resArray['L_ERRORCODE0'], 'setexpress');
         if (empty($error)) {
             // Unkown PayPal Error
             $GLOBALS['vmLogger']->err('PayPal returned: ' . $resArray['L_LONGMESSAGE0']);
         } else {
             $GLOBALS['vmLogger']->err($error);
         }
         //header("Location: $location");
         //$mainframe->close();
     }
 }
예제 #2
0
 /**
  * Displays the "checkout bar" using the checkout bar template
  *
  * @param array $steps_to_do Array holding all steps the customer has to make
  * @param array $step_msg Array containing the step messages
  * @param int $step_count Number of steps to make
  * @param int $highlighted_step The index of the recent step
  */
 function show_checkout_bar($highlighted_step = null)
 {
     global $sess, $ship_to_info_id, $shipping_rate_id, $VM_LANG;
     if (SHOW_CHECKOUT_BAR != '1' || defined('VM_CHECKOUT_BAR_LOADED')) {
         return;
     }
     // Let's assemble the steps
     $steps = ps_checkout::get_checkout_steps();
     $step_count = sizeof($steps);
     $steps_tmp = $steps;
     $i = 0;
     foreach ($steps as $step) {
         foreach ($step as $step_name) {
             switch ($step_name) {
                 case 'CHECK_OUT_GET_SHIPPING_ADDR':
                     $step_msg = $VM_LANG->_('PHPSHOP_ADD_SHIPTO_2');
                     break;
                 case 'CHECK_OUT_GET_SHIPPING_METHOD':
                     $step_msg = $VM_LANG->_('PHPSHOP_ISSHIP_LIST_CARRIER_LBL');
                     break;
                 case 'CHECK_OUT_GET_PAYMENT_METHOD':
                     $step_msg = $VM_LANG->_('PHPSHOP_ORDER_PRINT_PAYMENT_LBL');
                     break;
                 case 'CHECK_OUT_GET_FINAL_CONFIRMATION':
                     $step_msg = $VM_LANG->_('PHPSHOP_CHECKOUT_CONF_PAYINFO_COMPORDER');
                     break;
             }
             $steps_to_do[$i][] = array('step_name' => $step_name, 'step_msg' => $step_msg, 'step_order' => key($steps_tmp));
         }
         next($steps_tmp);
         $i++;
     }
     if (!$highlighted_step) {
         $highlighted_step = ps_checkout::get_current_stage();
     }
     $theme = new $GLOBALS['VM_THEMECLASS']();
     $theme->set_vars(array('step_count' => $step_count, 'steps_to_do' => $steps_to_do, 'steps' => $steps, 'highlighted_step' => $highlighted_step, 'ship_to_info_id' => vmGet($_REQUEST, 'ship_to_info_id'), 'shipping_rate_id' => vmGet($_REQUEST, 'shipping_rate_id')));
     echo $theme->fetch('checkout/checkout_bar.tpl.php');
     define('VM_CHECKOUT_BAR_LOADED', 1);
 }
예제 #3
0
* -CHECK_OUT_GET_SHIPPING_METHOD
* let the user choose a shipto metho for the ship to address

* -CHECK_OUT_GET_PAYMENT_METHOD
* let the user choose a payment method

* -CHECK_OUT_GET_FINAL_CONFIRMATION
* shows a total summary including all payments, taxes, fees etc. and let the user confirm
*/
if ($auth['user_id'] > 0) {
    $show_basket = true;
} else {
    $show_basket = false;
}
$current_stage = ps_checkout::get_current_stage();
$checkout_steps = ps_checkout::get_checkout_steps();
if (in_array('CHECK_OUT_GET_FINAL_CONFIRMATION', $checkout_steps[$current_stage])) {
    $next_page = 'checkout.thankyou';
    if (sizeof($checkout_steps[$current_stage]) > 1) {
        include_once PAGEPATH . 'basket.php';
    } else {
        include_once PAGEPATH . 'ro_basket.php';
    }
} else {
    $next_page = 'checkout.index';
    include_once PAGEPATH . 'basket.php';
}
// Get the zone quantity after it has been calculated in the basket
$zone_qty = vmGet($_REQUEST, 'zone_qty');
$theme = new $GLOBALS['VM_THEMECLASS']();