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')); }
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(); }
private function _calculate($set_shipping = true) { $OSCOM_Weight = Registry::get('Weight'); $OSCOM_Tax = Registry::get('Tax'); $OSCOM_Currencies = Registry::get('Currencies'); $this->_sub_total = 0; $this->_total = 0; $this->_weight = 0; $this->_tax = 0; $this->_tax_groups = array(); $this->_shipping_boxes_weight = 0; $this->_shipping_boxes = 0; $this->_shipping_quotes = array(); $this->_order_totals = array(); $_SESSION['cartID'] = $this->generateCartID(); if ($this->hasContents()) { foreach ($this->_contents as $data) { $products_weight = $OSCOM_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT); $this->_weight += $products_weight * $data['quantity']; $tax = $OSCOM_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); $tax_description = $OSCOM_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id')); $shown_price = $OSCOM_Currencies->addTaxRateToPrice($data['price'], $tax, $data['quantity']); $this->_sub_total += $shown_price; $this->_total += $shown_price; if (DISPLAY_PRICE_WITH_TAX == '1') { $tax_amount = $shown_price - $shown_price / ($tax < 10 ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax)); } else { $tax_amount = $tax / 100 * $shown_price; $this->_total += $tax_amount; } $this->_tax += $tax_amount; if (isset($this->_tax_groups[$tax_description])) { $this->_tax_groups[$tax_description] += $tax_amount; } else { $this->_tax_groups[$tax_description] = $tax_amount; } } $this->_shipping_boxes_weight = $this->_weight; $this->_shipping_boxes = 1; if (SHIPPING_BOX_WEIGHT >= $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100) { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT; } else { $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100; } if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT); $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes; } if ($set_shipping === true) { if (!$this->hasShippingMethod() || $this->getShippingMethod('is_cheapest') === true) { $OSCOM_Shipping = new Shipping(); $this->setShippingMethod($OSCOM_Shipping->getCheapestQuote(), false); } else { $OSCOM_Shipping = new Shipping($this->getShippingMethod('id')); $this->setShippingMethod($OSCOM_Shipping->getQuote(), false); } Registry::set('Shipping', $OSCOM_Shipping, true); } $OSCOM_OrderTotal = new OrderTotal(); $this->_order_totals = $OSCOM_OrderTotal->getResult(); Registry::set('OrderTotal', $OSCOM_OrderTotal, true); } }