public static function execute()
 {
     $OSCOM_ShoppingCart = Registry::get('ShoppingCart');
     $OSCOM_PDO = Registry::get('PDO');
     $OSCOM_Currencies = Registry::get('Currencies');
     $OSCOM_Tax = Registry::get('Tax');
     $OSCOM_ShoppingCart->reset();
     $OSCOM_Payment = new PayPalExpressCheckout();
     if ($OSCOM_Payment->isEnabled() && MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_INSTANT_UPDATE == '1') {
         $counter = 0;
         while (true) {
             if (isset($_POST['L_NUMBER' . $counter])) {
                 $OSCOM_ShoppingCart->add($_POST['L_NUMBER' . $counter], $_POST['L_QTY' . $counter]);
             } else {
                 break;
             }
             $counter++;
         }
         if ($OSCOM_ShoppingCart->hasContents()) {
             $Qcountry = $OSCOM_PDO->prepare('select countries_id from :table_countries where countries_iso_code_2 = :countries_iso_code_2 limit 1');
             $Qcountry->bindValue(':countries_iso_code_2', $_POST['SHIPTOCOUNTRY']);
             $Qcountry->execute();
             if ($Qcountry->fetch() !== false) {
                 $address = array('firstname' => '', 'lastname' => '', 'gender' => '', 'company' => '', 'street_address' => '', 'suburb' => '', 'city' => $_POST['SHIPTOCITY'], 'postcode' => $_POST['SHIPTOZIP'], 'state' => $_POST['SHIPTOSTATE'], 'zone_id' => '', 'country_id' => $Qcountry->valueInt('countries_id'), 'telephone' => '', 'fax' => '');
                 $Qzone = $OSCOM_PDO->prepare('select * from :table_zones where zone_country_id = :zone_country_id and (zone_name = :zone_name or zone_code = :zone_code) limit 1');
                 $Qzone->bindInt(':zone_country_id', $address['country_id']);
                 $Qzone->bindValue(':zone_name', $address['state']);
                 $Qzone->bindValue(':zone_code', $address['state']);
                 $Qzone->execute();
                 if ($Qzone->fetch() !== false) {
                     $address['zone_id'] = $Qzone->valueInt('zone_id');
                     $address['state'] = $Qzone->value('zone_name');
                 }
                 $OSCOM_ShoppingCart->setShippingAddress($address);
                 $OSCOM_ShoppingCart->setBillingAddress($address);
                 $tax_total = 0;
                 foreach ($OSCOM_ShoppingCart->getProducts() as $product) {
                     $product_tax = $OSCOM_Currencies->formatRaw($product['price'] * ($OSCOM_Tax->getTaxRate($product['tax_class_id']) / 100));
                     $tax_total += $product_tax * $product['quantity'];
                 }
                 $quotes_array = array();
                 if ($OSCOM_ShoppingCart->getContentType() != 'virtual') {
                     $OSCOM_Shipping = new Shipping();
                     foreach ($OSCOM_Shipping->getQuotes() as $quote) {
                         if (!isset($quote['error'])) {
                             foreach ($quote['methods'] as $rate) {
                                 $quotes_array[] = array('id' => $quote['id'] . '_' . $rate['id'], 'name' => $quote['module'], 'label' => $rate['title'], 'cost' => $rate['cost'], 'tax' => $quote['tax']);
                             }
                         }
                     }
                 } else {
                     $quotes_array[] = array('id' => 'null', 'name' => 'No Shipping', 'label' => 'No Shipping', 'cost' => '0', 'tax' => '0');
                 }
                 $params = array('METHOD' => 'CallbackResponse', 'OFFERINSURANCEOPTION' => 'false');
                 $counter = 0;
                 $cheapest_rate = null;
                 $cheapest_counter = $counter;
                 foreach ($quotes_array as $quote) {
                     $shipping_rate = $OSCOM_Currencies->formatRaw($quote['cost'] + $quote['cost'] * ($quote['tax'] / 100));
                     $params['L_SHIPPINGOPTIONNAME' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
                     $params['L_SHIPINGPOPTIONLABEL' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
                     $params['L_SHIPPINGOPTIONAMOUNT' . $counter] = $OSCOM_Currencies->formatRaw($quote['cost']);
                     $params['L_SHIPPINGOPTIONISDEFAULT' . $counter] = 'false';
                     $params['L_TAXAMT' . $counter] = $OSCOM_Currencies->formatRaw($tax_total + $quote['cost'] * ($quote['tax'] / 100));
                     if (is_null($cheapest_rate) || $shipping_rate < $cheapest_rate) {
                         $cheapest_rate = $shipping_rate;
                         $cheapest_counter = $counter;
                     }
                     $counter++;
                 }
                 $params['L_SHIPPINGOPTIONISDEFAULT' . $cheapest_counter] = 'true';
                 $post_string = '';
                 foreach ($params as $key => $value) {
                     $post_string .= $key . '=' . urlencode(utf8_encode(trim($value))) . '&';
                 }
                 $post_string = substr($post_string, 0, -1);
                 echo $post_string;
             }
         }
     }
     $OSCOM_ShoppingCart->reset();
 }
 protected function initializeExpressCheckout()
 {
     $OSCOM_Currencies = Registry::get('Currencies');
     $OSCOM_ShoppingCart = Registry::get('ShoppingCart');
     $OSCOM_Tax = Registry::get('Tax');
     if (MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_TRANSACTION_SERVER == 'Live') {
         $paypal_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
     } else {
         $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout';
     }
     $params = array('CURRENCYCODE' => $OSCOM_Currencies->getCode());
     $line_item_no = 0;
     $items_total = 0;
     $tax_total = 0;
     foreach ($OSCOM_ShoppingCart->getProducts() as $product) {
         $params['L_NAME' . $line_item_no] = $product['name'];
         $params['L_AMT' . $line_item_no] = $OSCOM_Currencies->formatRaw($product['price']);
         $params['L_NUMBER' . $line_item_no] = $product['id'];
         $params['L_QTY' . $line_item_no] = $product['quantity'];
         $product_tax = $OSCOM_Currencies->formatRaw($product['price'] * ($OSCOM_Tax->getTaxRate($product['tax_class_id']) / 100));
         $params['L_TAXAMT' . $line_item_no] = $product_tax;
         $tax_total += $product_tax * $product['quantity'];
         $items_total += $OSCOM_Currencies->formatRaw($product['price']) * $product['quantity'];
         $line_item_no++;
     }
     $params['ITEMAMT'] = $items_total;
     $params['TAXAMT'] = $tax_total;
     if ($OSCOM_ShoppingCart->hasShippingAddress()) {
         $params['ADDROVERRIDE'] = '1';
         $params['SHIPTONAME'] = $OSCOM_ShoppingCart->getShippingAddress('firstname') . ' ' . $OSCOM_ShoppingCart->getShippingAddress('lastname');
         $params['SHIPTOSTREET'] = $OSCOM_ShoppingCart->getShippingAddress('street_address');
         $params['SHIPTOCITY'] = $OSCOM_ShoppingCart->getShippingAddress('city');
         $params['SHIPTOSTATE'] = $OSCOM_ShoppingCart->getShippingAddress('zone_code');
         $params['SHIPTOCOUNTRYCODE'] = $OSCOM_ShoppingCart->getShippingAddress('country_iso_code_2');
         $params['SHIPTOZIP'] = $OSCOM_ShoppingCart->getShippingAddress('postcode');
     }
     $OSCOM_Shipping = new Shipping();
     $quotes_array = array();
     foreach ($OSCOM_Shipping->getQuotes() as $quote) {
         if (!isset($quote['error'])) {
             foreach ($quote['methods'] as $rate) {
                 $quotes_array[] = array('id' => $quote['id'] . '_' . $rate['id'], 'name' => $quote['module'], 'label' => $rate['title'], 'cost' => $rate['cost'], 'tax' => $quote['tax']);
             }
         }
     }
     $counter = 0;
     $cheapest_rate = null;
     $expensive_rate = 0;
     $cheapest_counter = $counter;
     $default_shipping = null;
     foreach ($quotes_array as $quote) {
         $shipping_rate = $OSCOM_Currencies->formatRaw($quote['cost'] + $quote['cost'] * ($quote['tax'] / 100));
         $params['L_SHIPPINGOPTIONNAME' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
         $params['L_SHIPINGPOPTIONLABEL' . $counter] = $quote['name'] . ' (' . $quote['label'] . ')';
         $params['L_SHIPPINGOPTIONAMOUNT' . $counter] = $shipping_rate;
         $params['L_SHIPPINGOPTIONISDEFAULT' . $counter] = 'false';
         if (is_null($cheapest_rate) || $shipping_rate < $cheapest_rate) {
             $cheapest_rate = $shipping_rate;
             $cheapest_counter = $counter;
         }
         if ($shipping_rate > $expensive_rate) {
             $expensive_rate = $shipping_rate;
         }
         if ($OSCOM_ShoppingCart->getShippingMethod('id') == $quote['id']) {
             $default_shipping = $counter;
         }
         $counter++;
     }
     if (!is_null($default_shipping)) {
         $cheapest_rate = $params['L_SHIPPINGOPTIONAMOUNT' . $default_shipping];
         $cheapest_counter = $default_shipping;
     }
     if (!is_null($cheapest_rate)) {
         if (MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_INSTANT_UPDATE == '1' && (MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_TRANSACTION_SERVER != 'Live' || MODULE_PAYMENT_PAYPAL_EXPRESS_CHECKOUT_TRANSACTION_SERVER == 'Live' && ENABLE_SSL == true)) {
             // Live server requires SSL to be enabled
             $params['CALLBACK'] = OSCOM::getRPCLink(null, 'Cart', 'PayPal&ExpressCheckoutInstantUpdate', 'SSL', false, false);
             $params['CALLBACKTIMEOUT'] = '5';
         }
         $params['INSURANCEOPTIONSOFFERED'] = 'false';
         $params['L_SHIPPINGOPTIONISDEFAULT' . $cheapest_counter] = 'true';
     }
     // don't recalculate currency values as they have already been calculated
     $params['SHIPPINGAMT'] = $OSCOM_Currencies->formatRaw($OSCOM_ShoppingCart->getShippingMethod('cost'));
     $params['AMT'] = $OSCOM_Currencies->formatRaw($params['ITEMAMT'] + $params['TAXAMT'] + $params['SHIPPINGAMT'], '', 1);
     $params['MAXAMT'] = $OSCOM_Currencies->formatRaw($params['AMT'] + $expensive_rate + 100, '', 1);
     // safely pad higher for dynamic shipping rates (eg, USPS express)
     $response_array = $this->setExpressCheckout($params);
     if ($response_array['ACK'] == 'Success' || $response_array['ACK'] == 'SuccessWithWarning') {
         OSCOM::redirect($paypal_url . '&token=' . $response_array['TOKEN'] . '&useraction=commit');
     }
     OSCOM::redirect(OSCOM::getLink(null, 'Cart', 'error_message=' . stripslashes($response_array['L_LONGMESSAGE0']), 'SSL'));
 }