public function __construct(uspsShipping $plugin, array $params) { $str = strtolower($params['service']); $service_name = ''; foreach ($this->token_to_services as $token => $name) { if (strpos($str, $token) !== false) { $service_name = $name; break; } } if (!isset($this->services[$service_name])) { throw new waException($plugin->_w("Unsupported service: ") . $params['service'] . $plugin->_w(". Supported services by this API are: ") . implode(", ", $this->getSupportedServices())); } $this->service = $this->services[$service_name]; if (empty($params['items'])) { throw new waException($plugin->_w("Empty items of order")); } $this->plugin = $plugin; $this->params = $params; $address = $this->getAddress(); foreach ($address as $name => $value) { $address[$name] = $this->correctAddress($value); } $this->setAddress($address); }
public function __construct(uspsShipping $plugin, array $params) { $service = uspsServices::getServiceByCode(!empty($params['service']) ? $params['service'] : ''); if (!$service) { throw new waException($plugin->_w("Unknown service")); } $supported = $this->getSupportedServices(); if (is_array($supported) && !in_array($service['code'], $supported)) { throw new waException($plugin->_w("Unsupported service: ") . $service['code'] . $plugin->_w(". Supported services by this API are: ") . implode(", ", $supported)); } $this->service = $service; parent::__construct($plugin, $params); }
public function __construct(uspsShipping $plugin, array $params) { // tracking ID is obligatory if (!isset($params['tracking_id'])) { throw new waException($plugin->_w("Empty tracking ID")); } parent::__construct($plugin, $params); }
/** * @param string $code iso3 code * @throws waException * @return string */ protected function getCountryName($code) { $country_model = new waCountryModel(); $country = $country_model->get($code); if (!$country) { throw new waException($this->plugin->_w("Unknown country: ") . $code); } $iso2letter = strtoupper($country['iso2letter']); $country_list = $this->getCountryList(); if (!isset($country_list[$iso2letter])) { throw new waException($this->plugin->_w("Unknown country: ") . $code); } return $country_list[$iso2letter]; }