public function agilepaypal_redirect() { global $cookie, $cart, $smarty, $defaultCountry; $error_msg = ''; if (Module::isInstalled('agilemultipleseller')) { include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/agilemultipleseller.php"; $original_id_cart = AgileMultipleSeller::backup_cart_for_subcart_payment(); } $paypal = new AgilePaypal(); $cart = new Cart(intval($cookie->id_cart)); $expresscheckoutkey = md5(_PS_VERSION_ . $cookie->id_cart); $address_override = 0; $islogged = Context::getContext()->customer->isLogged(); if ($islogged) { $customer = new Customer(intval($cart->id_customer)); $addresses = $customer->getAddresses($cookie->id_lang); $id_address = 0; if (!empty($addresses)) { foreach ($addresses as $addr) { if (intval($cart->id_address_delivery) == intval($addr['id_address'])) { $id_address = intval($addr['id_address']); break; } } if ($id_address > 0) { $address = new Address($id_address); } else { $address = new Address($addresses[0]['id_address']); } } } if (!isset($address) or !$address->id_country) { $address = new Address(); $address->id_country = intval(Tools::getValue('sl_expresscheckout_id_country')); } if (!isset($address) or !$address->id_country) { $address = new Address(); $address->id_country = (int) Configuration::get('PS_COUNTRY_DEFAULT'); } $country = new Country(intval($address->id_country)); $zone = new Zone(intval($country->id_zone)); $doSubmit = ($country->active == 1 and $zone->active == 1 or $cart->isVirtualCart()); $state = NULL; if ($address->id_state) { $state = new State(intval($address->id_state)); } if ($islogged) { $customer = new Customer(intval($cart->id_customer)); } else { $customer = new Customer(); $customer->secure_key = md5(uniqid(rand(), true)); } $business = $paypal->getSellerPaypalEmailAddress(); $header = Configuration::get('AGILE_PAYPAL_HEADER'); $currency_order = new Currency(intval($cart->id_currency)); $currency_module = new Currency((int) Configuration::get('AGILE_PAYPAL_CURRENCY')); if (!Validate::isEmail($business)) { $error_msg .= $paypal->getL('Paypal error: (invalid or undefined business account email)'); } if (!Validate::isLoadedObject($currency_module)) { $error_msg .= $paypal->getL('Currency Restriction: (Invalid currency restriction setting for this module)'); } $customercurrency = $cookie->id_currency; $defaultCountryAgile = $defaultCountry; $defaultCountry = $country; $the_rate = $currency_order->conversion_rate / $currency_module->conversion_rate; $cartproducts = $cart->getProducts(); $prod_total = $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); $discount = abs(floatval($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS))); $all_total = $cart->getOrderTotal(true, Cart::BOTH); $business2 = $paypal->getSellerPaypalMicroEmailAddress(); $micro_amount = floatval(Configuration::get('AGILE_PAYPAL_MICRO_AMOUNT')); if (isset($business2) and strlen(trim($business2)) > 0 and isset($micro_amount) and floatval($micro_amount) > 0 and floatval($all_total) <= $micro_amount) { $business = $business2; } if (version_compare(_PS_VERSION_, '1.5', '>=')) { $shipping = Tools::ps_round(floatval($cart->getOrderTotal(true, Cart::ONLY_SHIPPING)), 2); } else { $shipping = Tools::ps_round(floatval($cart->getOrderShippingCost()) + floatval($cart->getOrderTotal(true, Cart::ONLY_WRAPPING)), 2); } if (!empty($error_msg)) { $doSubmit = 0; } $smarty->assign(array('redirect_text' => $paypal->getL($doSubmit == 1 ? 'Please wait, redirecting to Paypal... Thanks.' : 'Sorry, we do not ship to your country.'), 'cancel_text' => $paypal->getL('Cancel'), 'cart_text' => $paypal->getL('My cart'), 'return_text' => $paypal->getL('Return to shop'), 'paypal_url' => $paypal->getPaypalUrl(), 'address' => $address, 'country' => $country, 'state' => $state, 'doSubmit' => $doSubmit, 'baseUrl' => __PS_BASE_URI__, 'address_override' => $address_override, 'amount' => floatval($cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING)), 'customer' => $customer, 'all_total' => $all_total, 'shipping' => $shipping, 'discount' => $discount, 'show_discount' => $prod_total > $discount ? 1 : 0, 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => intval($cart->id), 'products' => $cartproducts, 'paypal_id' => intval($paypal->id), 'invoice' => intval(Configuration::get('AGILE_MS_PAYMENT_MODE')), 'header' => $header, 'expresscheckoutkey' => $expresscheckoutkey, 'id_subcart' => intval(Tools::getValue('id_subcart')), 'PS_ALLOW_MOBILE_DEVICE' => 0, 'agile_url' => (_PS_VERSION_ > '1.4' ? Tools::getShopDomainSsl(true, true) : Tools::getHttpHost(true, true)) . __PS_BASE_URI__, 'agilepaypal_return_url' => $this->get_return_url(), 'error_msg' => $error_msg, 'the_rate' => $the_rate)); $cookie->id_currency = $customercurrency; $defaultCountry = $defaultCountryAgile; if (Module::isInstalled('agilemultipleseller')) { include_once _PS_ROOT_DIR_ . "/modules/agilemultipleseller/agilemultipleseller.php"; AgileMultipleSeller::restore_cart_for_subcart_payment($original_id_cart); } }