Beispiel #1
0
$paypal = new Paypal();
$cart = new Cart((int) $cookie->id_cart);
$address = new Address((int) $cart->id_address_delivery);
$country = new Country((int) $address->id_country);
$state = NULL;
if ($address->id_state) {
    $state = new State((int) $address->id_state);
}
$customer = new Customer((int) $cart->id_customer);
$business = Configuration::get('PAYPAL_BUSINESS');
$header = Configuration::get('PAYPAL_HEADER');
$currency_order = new Currency((int) $cart->id_currency);
$currency_module = $paypal->getCurrency((int) $cart->id_currency);
if (empty($business) or !Validate::isEmail($business)) {
    die($paypal->getL('Paypal error: (invalid or undefined business account email)'));
}
if (!Validate::isLoadedObject($address) or !Validate::isLoadedObject($customer) or !Validate::isLoadedObject($currency_module)) {
    die($paypal->getL('Paypal error: (invalid address or customer)'));
}
// check currency of payment
if ($currency_order->id != $currency_module->id) {
    $cookie->id_currency = $currency_module->id;
    $cart->id_currency = $currency_module->id;
    $cart->update();
}
$smarty->assign(array('redirect_text' => $paypal->getL('Please wait, redirecting to Paypal... Thanks.'), 'cancel_text' => $paypal->getL('Cancel'), 'cart_text' => $paypal->getL('My cart'), 'return_text' => $paypal->getL('Return to shop'), 'paypal_url' => $paypal->getPaypalStandardUrl(), 'address' => $address, 'country' => $country, 'state' => $state, 'amount' => (double) $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), 'customer' => $customer, 'total' => (double) $cart->getOrderTotal(true, Cart::BOTH), 'shipping' => Tools::ps_round((double) $cart->getOrderShippingCost() + (double) $cart->getOrderTotal(true, Cart::ONLY_WRAPPING), 2), 'discount' => $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS), 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => (int) $cart->id . '_' . pSQL($cart->secure_key), 'products' => $cart->getProducts(), 'paypal_id' => (int) $paypal->id, 'header' => $header, 'url' => Tools::getShopDomain(true, true) . __PS_BASE_URI__));
if (is_file(_PS_THEME_DIR_ . 'modules/paypal/standard/redirect.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/' . $paypal->name . '/standard/redirect.tpl');
} else {
    $smarty->display(_PS_MODULE_DIR_ . $paypal->name . '/standard/redirect.tpl');
}
Beispiel #2
0
 protected function _deleteProduct($orderDetail, $quantity)
 {
     $price = $orderDetail->product_price * (1 + $orderDetail->tax_rate * 0.01);
     if ($orderDetail->reduction_percent != 0.0) {
         $reduction_amount = $price * $orderDetail->reduction_percent / 100;
     } elseif ($orderDetail->reduction_amount != '0.000000') {
         $reduction_amount = Tools::ps_round($orderDetail->reduction_amount, 2);
     }
     if (isset($reduction_amount) && $reduction_amount) {
         $price = Tools::ps_round($price - $reduction_amount, 2);
     }
     $productPriceWithoutTax = number_format($price / (1 + $orderDetail->tax_rate * 0.01), 2, '.', '');
     $price += Tools::ps_round($orderDetail->ecotax * (1 + $orderDetail->ecotax_tax_rate / 100), 2);
     $productPrice = number_format($quantity * $price, 2, '.', '');
     /* Update cart */
     $cart = new Cart($this->id_cart);
     $cart->updateQty($quantity, $orderDetail->product_id, $orderDetail->product_attribute_id, false, 'down');
     // customization are deleted in deleteCustomization
     $cart->update();
     /* Update order */
     $shippingDiff = $this->total_shipping - $cart->getOrderShippingCost();
     $this->total_products -= $productPriceWithoutTax;
     // After upgrading from old version
     // total_products_wt is null
     // removing a product made order total negative
     // and don't recalculating totals (on getTotalProductsWithTaxes)
     if ($this->total_products_wt != 0) {
         $this->total_products_wt -= $productPrice;
     }
     $this->total_shipping = $cart->getOrderShippingCost();
     /* It's temporary fix for 1.3 version... */
     if ($orderDetail->product_quantity_discount != '0.000000') {
         $this->total_paid -= $productPrice + $shippingDiff;
     } else {
         $this->total_paid = $cart->getOrderTotal();
     }
     $this->total_paid_real -= $productPrice + $shippingDiff;
     /* Prevent from floating precision issues (total_products has only 2 decimals) */
     if ($this->total_products < 0) {
         $this->total_products = 0;
     }
     if ($this->total_paid < 0) {
         $this->total_paid = 0;
     }
     if ($this->total_paid_real < 0) {
         $this->total_paid_real = 0;
     }
     /* Prevent from floating precision issues */
     $this->total_paid = number_format($this->total_paid, 2, '.', '');
     $this->total_paid_real = number_format($this->total_paid_real, 2, '.', '');
     $this->total_products = number_format($this->total_products, 2, '.', '');
     $this->total_products_wt = number_format($this->total_products_wt, 2, '.', '');
     /* Update order detail */
     $orderDetail->product_quantity -= (int) $quantity;
     if (!$orderDetail->product_quantity) {
         if (!$orderDetail->delete()) {
             return false;
         }
         if (count($this->getProductsDetail()) == 0) {
             $history = new OrderHistory();
             $history->id_order = (int) $this->id;
             $history->changeIdOrderState(Configuration::get('PS_OS_CANCELED'), (int) $this->id);
             if (!$history->addWithemail()) {
                 return false;
             }
         }
         return $this->update();
     }
     return $orderDetail->update() && $this->update();
 }
} else {
    $shippingAddress = new Address((int) $cart->id_address_delivery);
    $shippingCountry = new Country((int) $shippingAddress->id_country);
    $shippingState = NULL;
    if ($shippingAddress->id_state) {
        $shippingState = new State((int) $shippingAddress->id_state);
    }
}
$customer = new Customer((int) $cart->id_customer);
$business = Configuration::get('PAYPAL_BUSINESS');
$header = Configuration::get('PAYPAL_HEADER');
$currency_order = new Currency((int) $cart->id_currency);
$currency_module = $paypal->getCurrency((int) $cart->id_currency);
if (empty($business) or !Validate::isEmail($business)) {
    die($paypal->getL('Paypal error: (invalid or undefined business account email)'));
}
if (!Validate::isLoadedObject($billingAddress) or !Validate::isLoadedObject($shippingAddress) or !Validate::isLoadedObject($customer) or !Validate::isLoadedObject($currency_module)) {
    die($paypal->getL('Paypal error: (invalid address or customer)'));
}
// check currency of payment
if ($currency_order->id != $currency_module->id) {
    $cookie->id_currency = $currency_module->id;
    $cart->id_currency = $currency_module->id;
    $cart->update();
}
$smarty->assign(array('redirect_text' => $paypal->getL('Please wait, redirecting to Paypal... Thanks.'), 'cancel_text' => $paypal->getL('Cancel'), 'cart_text' => $paypal->getL('My cart'), 'return_text' => $paypal->getL('Return to shop'), 'paypal_url' => $paypal->getPaypalIntegralEvolutionUrl(), 'billing_address' => $billingAddress, 'billing_country' => $billingCountry, 'billing_state' => $billingState, 'shipping_address' => $shippingAddress, 'shipping_country' => $shippingCountry, 'shipping_state' => $shippingState, 'amount' => (double) $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), 'customer' => $customer, 'total' => (double) $cart->getOrderTotal(true, Cart::BOTH), 'shipping' => Tools::ps_round((double) $cart->getOrderShippingCost() + (double) $cart->getOrderTotal(true, Cart::ONLY_WRAPPING), 2), 'discount' => $cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS), 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => (int) $cart->id . '_' . pSQL($cart->secure_key), 'products' => $cart->getProducts(), 'paypal_id' => (int) $paypal->id, 'header' => $header, 'template' => 'Template' . Configuration::get('PAYPAL_TEMPLATE'), 'url' => Tools::getShopDomain(true, true) . __PS_BASE_URI__, 'paymentaction' => Configuration::get('PAYPAL_CAPTURE') ? 'authorization' : 'sale'));
if (is_file(_PS_THEME_DIR_ . 'modules/paypal/integral_evolution/redirect.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/' . $paypal->name . '/integral_evolution/redirect.tpl');
} else {
    $smarty->display(_PS_MODULE_DIR_ . $paypal->name . '/integral_evolution/redirect.tpl');
}
Beispiel #4
0
 public function makePayPalAPIValidation($cookie, $cart, $id_currency, $payerID, $type)
 {
     global $cookie;
     if (!$this->active) {
         return;
     }
     if (!$this->_isPayPalAPIAvailable()) {
         return;
     }
     // Filling-in vars
     $id_cart = (int) $cart->id;
     $currency = new Currency((int) $id_currency);
     $iso_currency = $currency->iso_code;
     $token = $cookie->paypal_token;
     $total = (double) $cart->getOrderTotal(true, PayPal::BOTH);
     $paymentType = Configuration::get('PAYPAL_CAPTURE') == 1 ? 'Authorization' : 'Sale';
     $serverName = urlencode($_SERVER['SERVER_NAME']);
     $bn = $type == 'express' ? 'ECS' : 'ECM';
     $notifyURL = urlencode(PayPal::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/paypal/ipn.php');
     // Getting address
     if (isset($cookie->id_cart) and $cookie->id_cart) {
         $cart = new Cart((int) $cookie->id_cart);
     }
     if (isset($cart->id_address_delivery) and $cart->id_address_delivery) {
         $address = new Address((int) $cart->id_address_delivery);
     }
     $requestAddress = '';
     if (Validate::isLoadedObject($address)) {
         $country = new Country((int) $address->id_country);
         $state = new State((int) $address->id_state);
         $requestAddress = '&SHIPTONAME=' . urlencode($address->company . ' ' . $address->firstname . ' ' . $address->lastname) . '&SHIPTOSTREET=' . urlencode($address->address1 . ' ' . $address->address2) . '&SHIPTOCITY=' . urlencode($address->city) . '&SHIPTOSTATE=' . urlencode($address->id_state ? $state->iso_code : $country->iso_code) . '&SHIPTOCOUNTRYCODE=' . urlencode($country->iso_code) . '&SHIPTOZIP=' . urlencode($address->postcode);
     }
     // Making request
     $request = '&TOKEN=' . urlencode($token) . '&PAYERID=' . urlencode($payerID) . '&PAYMENTACTION=' . $paymentType . '&AMT=' . $total . '&CURRENCYCODE=' . $iso_currency . '&IPADDRESS=' . $serverName . '&NOTIFYURL=' . $notifyURL . '&BUTTONSOURCE=PRESTASHOP_' . $bn . $requestAddress;
     $discounts = (double) $cart->getOrderTotal(true, PayPal::ONLY_DISCOUNTS);
     if ($discounts == 0) {
         $products = $cart->getProducts();
         $amt = 0;
         for ($i = 0; $i < sizeof($products); $i++) {
             $request .= '&L_NAME' . $i . '=' . substr(urlencode($products[$i]['name'] . (isset($products[$i]['attributes']) ? ' - ' . $products[$i]['attributes'] : '') . (isset($products[$i]['instructions']) ? ' - ' . $products[$i]['instructions'] : '')), 0, 127);
             $request .= '&L_AMT' . $i . '=' . urlencode($this->PayPalRound($products[$i]['price']));
             $request .= '&L_QTY' . $i . '=' . urlencode($products[$i]['cart_quantity']);
             $amt += $this->PayPalRound($products[$i]['price']) * $products[$i]['cart_quantity'];
         }
         $shipping = $this->PayPalRound($cart->getOrderShippingCost($cart->id_carrier, false));
         $request .= '&ITEMAMT=' . urlencode($amt);
         $request .= '&SHIPPINGAMT=' . urlencode($shipping);
         $request .= '&TAXAMT=' . urlencode((double) max($this->PayPalRound($total - $amt - $shipping), 0));
     } else {
         $products = $cart->getProducts();
         $description = 0;
         for ($i = 0; $i < sizeof($products); $i++) {
             $description .= ($description == '' ? '' : ', ') . $products[$i]['cart_quantity'] . " x " . $products[$i]['name'] . (isset($products[$i]['attributes']) ? ' - ' . $products[$i]['attributes'] : '') . (isset($products[$i]['instructions']) ? ' - ' . $products[$i]['instructions'] : '');
         }
         $request .= '&ORDERDESCRIPTION=' . urlencode(substr($description, 0, 120));
     }
     // Calling PayPal API
     include_once _PS_MODULE_DIR_ . 'paypal/api/paypallib.php';
     $ppAPI = new PaypalLib();
     $result = $ppAPI->makeCall($this->getAPIURL(), $this->getAPIScript(), 'DoExpressCheckoutPayment', $request);
     $this->_logs = array_merge($this->_logs, $ppAPI->getLogs());
     // Checking PayPal result
     if (!is_array($result) or !sizeof($result)) {
         $this->displayPayPalAPIError($this->l('Authorization to PayPal failed.'), $this->_logs);
     } elseif (!isset($result['ACK']) or strtoupper($result['ACK']) != 'SUCCESS') {
         $this->displayPayPalAPIError($this->l('PayPal return error.'), $this->_logs);
     } elseif (!isset($result['TOKEN']) or $result['TOKEN'] != $cookie->paypal_token) {
         $logs[] = '<b>' . $ppExpress->l('Token given by PayPal is not the same as the cookie token', 'submit') . '</b>';
         $ppExpress->displayPayPalAPIError($ppExpress->l('PayPal return error.', 'submit'), $logs);
     }
     // Making log
     $id_transaction = $result['TRANSACTIONID'];
     if (Configuration::get('PAYPAL_CAPTURE')) {
         $this->_logs[] = $this->l('Authorization for deferred payment granted by PayPal.');
     } else {
         $this->_logs[] = $this->l('Order finished with PayPal!');
     }
     $message = Tools::htmlentitiesUTF8(strip_tags(implode("\n", $this->_logs)));
     // Order status
     switch ($result['PAYMENTSTATUS']) {
         case 'Completed':
             $id_order_state = Configuration::get('PS_OS_PAYMENT');
             break;
         case 'Pending':
             if ($result['PENDINGREASON'] != 'authorization') {
                 $id_order_state = Configuration::get('PS_OS_PAYPAL');
             } else {
                 $id_order_state = (int) Configuration::get('PAYPAL_OS_AUTHORIZATION');
             }
             break;
         default:
             $id_order_state = Configuration::get('PS_OS_ERROR');
     }
     // Call payment validation method
     $this->validateOrder($id_cart, $id_order_state, (double) $cart->getOrderTotal(true, PayPal::BOTH), $this->displayName, $message, array('transaction_id' => $id_transaction, 'payment_status' => $result['PAYMENTSTATUS'], 'pending_reason' => $result['PENDINGREASON']), $id_currency, false, $cart->secure_key);
     // Clean cookie
     unset($cookie->paypal_token);
     // Displaying output
     $order = new Order((int) $this->currentOrder);
     Tools::redirectLink(__PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) $id_cart . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder . '&key=' . $order->secure_key);
 }
Beispiel #5
0
$address = new Address(intval($cart->id_address_invoice));
$country = new Country(intval($address->id_country));
$state = NULL;
if ($address->id_state) {
    $state = new State(intval($address->id_state));
}
$customer = new Customer(intval($cart->id_customer));
$affilie = Configuration::get('SMT_AFFILIE');
$currency_order = new Currency(intval($cart->id_currency));
$currency_module = $currency_order;
$Value = floatval($cart->getOrderTotal(true, 3));
$decimals = log10(abs($Value));
$decimals = -(intval(min($decimals, 0)) - 3);
$format = "%." . $decimals . "f";
$amount = sprintf($format, $Value);
if (!Validate::isLoadedObject($address) or !Validate::isLoadedObject($customer)) {
    die($smt->l('Erreur de paiement : Addresse ou Client inconnu'));
}
$ref = $cart->id + 22002;
$randNumber = rand(999, 100000);
$ref = "CMD" . $ref . "TN-" . $randNumber;
$smarty->assign(array('reference' => $ref, 'redirect_text' => $smt->l('Veuillez patienter nous allons vous rediriger vers le serveur de paiement... Merci.'), 'cancel_text' => $smt->l('Annuler'), 'cart_text' => $smt->l('Mon panier'), 'return_text' => $smt->l('Retour &agrave; la boutique'), 'smt_url' => $smt->getSMTUrl(), 'address' => $address, 'country' => $country, 'state' => $state, 'amount' => $amount, 'customer' => $customer, 'sid' => $customer->secure_key, 'total' => floatval($cart->getOrderTotal(true, 3)), 'shipping' => Tools::ps_round(floatval($cart->getOrderShippingCost()) + floatval($cart->getOrderTotal(true, 6)), 2), 'discount' => $cart->getOrderTotal(true, 2), 'affilie' => $affilie, 'currency_module' => $currency_module, 'cart_id' => intval($cart->id), 'products' => $cart->getProducts(), 'smt_id' => intval($smt->id), 'url' => Tools::getHttpHost(false, true) . __PS_BASE_URI__));
/*

			<input type="hidden" name="return" value="http://{$url}order-confirmation.php?key={$customer->secure_key}&id_cart={$cart_id}&id_module={$paypal_id}&slowvalidation" />
*/
if (is_file(_PS_THEME_DIR_ . 'modules/smtsps/redirect.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/' . $smt->name . '/redirect.tpl');
} else {
    $smarty->display(_PS_MODULE_DIR_ . $smt->name . '/redirect.tpl');
}
 public function agilepaypal_subscribe()
 {
     global $cookie, $cart, $smarty, $defaultCountry;
     $error_msg = '';
     $paypal = new AgilePaypal();
     $cart = new Cart(intval($cookie->id_cart));
     $expresscheckoutkey = md5(_PS_VERSION_ . $cookie->id_cart);
     $cycle_base = Tools::getValue('sl_agilepaypalexpress_cycle_base');
     $cycle = Tools::getValue('sl_agilepaypalexpress_cycle');
     $cycle_list = array('D', 'W', 'M', 'Y');
     if (!in_array($cycle, $cycle_list)) {
         $error_msg .= $paypal->getL('Recurring cycle error: (invalid or recurring cycle)') . "<BR>";
     }
     $cycle_num = Tools::getValue('sl_agilepaypalexpress_cycle_num');
     $address_override = 0;
     $islogged = Context::getContext()->customer->isLogged();
     if ($islogged) {
         $customer = new Customer(intval($cart->id_customer));
         $addresses = $customer->getAddresses($cookie->id_lang);
         if (!empty($addresses)) {
             $id_address = 0;
             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)') . "<BR>";
     }
     if (!Validate::isLoadedObject($currency_module)) {
         $error_msg .= $paypal->getL('Currency Restriction: (Invalid currency restriction setting for this module)') . "<BR>";
     }
     $customercurrency = $cookie->id_currency;
     $defaultCountryAgile = $defaultCountry;
     $defaultCountry = $country;
     $the_rate = $currency_order->conversion_rate / $currency_module->conversion_rate;
     $cartproducts = $cart->getProducts();
     $product1st = $cartproducts[0];
     $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 (_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' => abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)), 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => intval($cart->id), 'products' => $cartproducts, 'product1st' => $product1st, 'paypal_id' => intval($paypal->id), 'invoice' => intval(Configuration::get('AGILE_MS_PAYMENT_MODE')), 'header' => $header, 'cycle_base' => $cycle_base, 'cycle' => $cycle, 'cycle_num' => $cycle_num, 'expresscheckoutkey' => $expresscheckoutkey, '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;
 }
Beispiel #7
0
 private function _deleteProduct($orderDetail, $quantity)
 {
     $price = $orderDetail->product_price * (1 + $orderDetail->tax_rate * 0.01);
     if ($orderDetail->reduction_percent != 0.0) {
         $reduction_amount = $price * $orderDetail->reduction_percent / 100;
     } elseif ($orderDetail->reduction_amount != '0.000000') {
         $reduction_amount = Tools::ps_round($orderDetail->reduction_amount * (1 + $orderDetail->tax_rate * 0.01), 2);
     }
     if (isset($reduction_amount) and $reduction_amount) {
         $price = Tools::ps_round($price - $reduction_amount, 2);
     }
     $unitPrice = number_format($price, 2, '.', '');
     $productPrice = number_format($quantity * $price, 2, '.', '');
     $productPriceWithoutTax = number_format($productPrice / (1 + $orderDetail->tax_rate * 0.01), 2, '.', '');
     /* Update cart */
     $cart = new Cart($this->id_cart);
     $cart->updateQty($quantity, $orderDetail->product_id, $orderDetail->product_attribute_id, false, 'down');
     // customization are deleted in deleteCustomization
     $cart->update();
     /* Update order */
     $shippingDiff = $this->total_shipping - $cart->getOrderShippingCost();
     $this->total_products -= $productPriceWithoutTax;
     $this->total_products_wt -= $productPrice;
     $this->total_shipping = $cart->getOrderShippingCost();
     /* It's temporary fix for 1.3 version... waiting historization system on 1.4 version  */
     if ($orderDetail->product_quantity_discount != '0.000000') {
         $this->total_paid -= $productPrice + $shippingDiff;
     } else {
         $this->total_paid = $cart->getOrderTotal();
     }
     $this->total_paid_real -= $productPrice + $shippingDiff;
     /* Prevent from floating precision issues (total_products has only 2 decimals) */
     if ($this->total_products < 0) {
         $this->total_products = 0;
     }
     /* Prevent from floating precision issues */
     $this->total_paid = number_format($this->total_paid, 2, '.', '');
     $this->total_paid_real = number_format($this->total_paid_real, 2, '.', '');
     $this->total_products = number_format($this->total_products, 2, '.', '');
     $this->total_products_wt = number_format($this->total_products_wt, 2, '.', '');
     /* Update order detail */
     $orderDetail->product_quantity -= intval($quantity);
     if (!$orderDetail->product_quantity) {
         if (!$orderDetail->delete()) {
             return false;
         }
         if (count($this->getProductsDetail()) == 0) {
             global $cookie;
             $history = new OrderHistory();
             $history->id_order = intval($this->id);
             $history->changeIdOrderState(_PS_OS_CANCELED_, intval($this->id));
             if (!$history->addWithemail()) {
                 return false;
             }
         }
         return $this->update();
     }
     return $orderDetail->update() and $this->update();
 }
Beispiel #8
0
$paypal = new Paypal();
$cart = new Cart(intval($cookie->id_cart));
$address = new Address(intval($cart->id_address_invoice));
$country = new Country(intval($address->id_country));
$state = NULL;
if ($address->id_state) {
    $state = new State(intval($address->id_state));
}
$customer = new Customer(intval($cart->id_customer));
$business = Configuration::get('PAYPAL_BUSINESS');
$header = Configuration::get('PAYPAL_HEADER');
$currency_order = new Currency(intval($cart->id_currency));
$currency_module = $paypal->getCurrency();
if (!Validate::isEmail($business)) {
    die($paypal->getL('Paypal error: (invalid or undefined business account email)'));
}
if (!Validate::isLoadedObject($address) or !Validate::isLoadedObject($customer) or !Validate::isLoadedObject($currency_module)) {
    die($paypal->getL('Paypal error: (invalid address or customer)'));
}
// check currency of payment
if ($currency_order->id != $currency_module->id) {
    $cookie->id_currency = $currency_module->id;
    $cart->id_currency = $currency_module->id;
    $cart->update();
}
$smarty->assign(array('redirect_text' => $paypal->getL('Please wait, redirecting to Paypal... Thanks.'), '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, 'amount' => floatval($cart->getOrderTotal(true, 4)), 'customer' => $customer, 'total' => floatval($cart->getOrderTotal(true, 3)), 'shipping' => Tools::ps_round(floatval($cart->getOrderShippingCost()) + floatval($cart->getOrderTotal(true, 6)), 2), 'discount' => $cart->getOrderTotal(true, 2), 'business' => $business, 'currency_module' => $currency_module, 'cart_id' => intval($cart->id), 'products' => $cart->getProducts(), 'paypal_id' => intval($paypal->id), 'header' => $header, 'url' => Tools::getHttpHost(true, true) . __PS_BASE_URI__));
if (is_file(_PS_THEME_DIR_ . 'modules/paypal/redirect.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/' . $paypal->name . '/redirect.tpl');
} else {
    $smarty->display(_PS_MODULE_DIR_ . $paypal->name . '/redirect.tpl');
}
Beispiel #9
0
 /**
  * @param $iso_country_code
  * @return null|string
  */
 public function shippingCostRetrieveRequest($iso_country_code)
 {
     if ($iso_country_code) {
         $cart = new Cart($this->id_cart);
         if ($id_country = Country::getByIso($iso_country_code)) {
             if ($id_zone = Country::getIdZone($id_country)) {
                 $carriers = Carrier::getCarriersForOrder($id_zone);
                 $currency = Currency::getCurrency($cart->id_currency);
                 if ($carriers) {
                     $carrier_list = array();
                     foreach ($carriers as $carrier) {
                         $c = new Carrier((int) $carrier['id_carrier']);
                         $shipping_method = $c->getShippingMethod();
                         $price = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier']);
                         $price_tax_exc = $shipping_method == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int) $carrier['id_carrier'], false);
                         $carrier_list[]['ShippingCost'] = array('Type' => $carrier['name'] . ' (' . $carrier['id_carrier'] . ')', 'CountryCode' => Tools::strtoupper($iso_country_code), 'Price' => array('Gross' => $this->toAmount($price), 'Net' => $this->toAmount($price_tax_exc), 'Tax' => $this->toAmount($price) - $this->toAmount($price_tax_exc), 'CurrencyCode' => Tools::strtoupper($currency['iso_code'])));
                     }
                     $shipping_cost = array('CountryCode' => Tools::strtoupper($iso_country_code), 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $carrier_list);
                     $xml = OpenPayU::buildShippingCostRetrieveResponse($shipping_cost, $this->id_request, $iso_country_code);
                     return $xml;
                 } else {
                     Logger::addLog('carrier by id_zone is undefined');
                 }
             }
         }
     }
     return null;
 }