コード例 #1
0
ファイル: ISO3166.php プロジェクト: gingerpayments/ginger-php
 /**
  * Check if provided value is ISO 3166-1 alpha-2 country standard
  *
  * @param string $value
  * @return bool
  */
 public static function isValid($value)
 {
     try {
         $ISO3166 = new Alcohol\ISO3166();
         $ISO3166->getByAlpha2($value);
         return true;
     } catch (\DomainException $e) {
         return false;
     }
 }
コード例 #2
0
 /**
  * Returns the country as the numeric ISO 3166-1 code
  *
  * @throws Omnipay\Common\Exception\InvalidRequestException
  *
  * @return int ISO 3166-1 numeric country
  */
 protected function formatCountry()
 {
     $country = $this->getCard()->getCountry();
     if (!is_null($country) && !is_numeric($country)) {
         $iso3166 = new ISO3166();
         if (strlen($country) == 2) {
             $country = $iso3166->getByAlpha2($country)['numeric'];
         } elseif (strlen($country) == 3) {
             $country = $iso3166->getByAlpha3($country)['numeric'];
         } else {
             throw new InvalidRequestException("The country parameter must be ISO 3166-1 numeric, aplha2 or alpha3.");
         }
     }
     return $country;
 }