/** * @param AddressInterface $address */ public function validateRecipientAddress(AddressInterface $address) { try { $importCountry = $this->getImportCountry($address->getCountryCode()); } catch (InvalidArgumentException $e) { throw new InvalidRecipientAddressException('Can not send a package to this country.'); } if (!array_key_exists($importCountry->getZone(), $this->get('zone_calculators'))) { throw new InvalidRecipientAddressException('Can not send a package to this country.'); } }
/** * @param AddressInterface $address * @return ImportCountry|null */ protected function detectImportCountry(AddressInterface $address) { $countries = $this->get('import_countries'); $importCountry = null; if (array_key_exists($address->getCountryCode(), $countries)) { $importCountry = $countries[$address->getCountryCode()]; } return $importCountry; }