Converts ISO 3166-2 codes to the codes the PayPal API requires

1.0.0 2018-09-12 11:59 UTC

This package is auto-updated.

Last update: 2021-04-06 13:04:50 UTC


Converts ISO 3166-2 alpha 2 codes to the codes the PayPal API requires to identify your customers state.

License PHP v5.6 PHP v7.0 PHP v7.1


The library can be installed using Composer.
If you have not installed Composer, you can follow the offical instructions.

Once composer is installed, run this in your terminal/command-line tool:

composer require wirecard/iso-paypal-converter


In your application load the vendor/autoload.php that Composer provides.
You can then initialize the Converter class like so:

use Wirecard\IsoToPayPal\Converter;

$converter = new Converter();

This automatically loads all the state mappings.


To convert an ISO 3166-2 code to the correct PayPal identifier, you need only pass the country code and state identifier to the convert function like so:

$converter->convert("TH", "50");
// => "Chiang Mai"

Alternatively you can pass in a fully formed ISO 3166-2 code with state identifier like so:

// => "HOKKAIDO"


Note that if you omit the state parameter, the first argument must include a state identifer, otherwise you will receive an InvalidArgumentException:

// => InvalidArgumentException

A fully formed ISO 3166-2 code takes the form XX-YY.

If a country is not found in the conversion table, you will receive a CountryNotFoundException:

// => CountryNotFoundException

And finally, if the state cannot be found in the country you stated, you will receive a StateNotFoundException like so:

// => StateNotFoundException

// => "NY"