public function shipping() { $this->loadLibConfig(); if ($this->request->post['DOCUMENT']) { $xml = htmlspecialchars_decode($this->request->post['DOCUMENT']); $result = OpenPayU_Order::consumeMessage($xml); $countrycode = $result->getCountryCode(); $reqId = $result->getReqId(); $sessionId = $result->getSessionId(); $order_id = $this->model_payment_payu->getOrderIdBySessionId(substr($sessionId, 0, 32)); $this->load->model('localisation/country'); $country_list = $this->model_localisation_country->getCountries(); $country_id = 0; foreach ($country_list as $country) { if ($country['iso_code_2'] == $countrycode) { $country_id = $country['country_id']; } } $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($order_id); $shippingCostList = array(); $this->tax->setShippingAddress($country_id, 0); $this->tax->setPaymentAddress($country_id, 0); $this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id')); foreach ($this->getShippings($order_id, $country_id) as $onemethod) { $shipmethod = array('Type' => $onemethod['title'], 'CountryCode' => $countrycode, 'Price' => array('Gross' => str_ireplace('.', '', $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']), $order_info['currency_code'], false, false)), 'Net' => str_ireplace('.', '', $this->currency->format($onemethod['cost'], $order_info['currency_code'], false, false)), 'Tax' => str_ireplace('.', '', $this->currency->format($this->tax->calculate($onemethod['cost'], $onemethod['tax_class_id']) - $onemethod['cost'], $order_info['currency_code'], false, false)), 'CurrencyCode' => $order_info['currency_code'])); if (false) { $shipmethod[]['State'] = $order_info['shipping_zone']; $shipmethod[]['City'] = $order_info['shipping_city']; } $shippingCostList[]['ShippingCost'] = $shipmethod; } $shippingCost = array('CountryCode' => $countrycode, 'ShipToOtherCountry' => 'true', 'ShippingCostList' => $shippingCostList); $xml = OpenPayU::buildShippingCostRetrieveResponse($shippingCost, $reqId, $countrycode); if (!$result->getSuccess()) { $this->logger->write($result->getError() . ' [request: ' . serialize($result->getRequest()) . ', response: ' . serialize(OpenPayU::parseOpenPayUDocument($xml)) . ']'); } header("Content-type: text/xml"); echo $xml; } }
/** * @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; }