diff --git a/changelog/dev-7886-add-country-codes-enum b/changelog/dev-7886-add-country-codes-enum new file mode 100644 index 00000000000..e6e2b8aad22 --- /dev/null +++ b/changelog/dev-7886-add-country-codes-enum @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Added enum class for country codes diff --git a/includes/admin/class-wc-rest-payments-settings-controller.php b/includes/admin/class-wc-rest-payments-settings-controller.php index 057af86e3f5..aed37660980 100644 --- a/includes/admin/class-wc-rest-payments-settings-controller.php +++ b/includes/admin/class-wc-rest-payments-settings-controller.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Admin */ +use WCPay\Constants\Country_Code; use WCPay\Fraud_Prevention\Fraud_Risk_Tools; use WCPay\Constants\Track_Events; @@ -388,7 +389,7 @@ public function validate_business_support_phone( string $value, WP_REST_Request } // Japan accounts require Japanese phone numbers. - if ( 'JP' === $this->account->get_account_country() ) { + if ( Country_Code::JAPAN === $this->account->get_account_country() ) { if ( '+81' !== substr( $value, 0, 3 ) ) { return new WP_Error( 'rest_invalid_pattern', diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index db6ebb6bb45..4c6c3bc92d6 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -9,6 +9,7 @@ exit; // Exit if accessed directly. } +use WCPay\Constants\Country_Code; use WCPay\Constants\Fraud_Meta_Box_Type; use WCPay\Constants\Order_Mode; use WCPay\Constants\Order_Status; @@ -2877,7 +2878,7 @@ protected function get_deposit_delay_days( int $default_value = 7 ): int { * * @return string code of the country. */ - protected function get_account_country( string $default_value = 'US' ): string { + protected function get_account_country( string $default_value = Country_Code::UNITED_STATES ): string { try { if ( $this->is_connected() ) { return $this->account->get_account_country() ?? $default_value; diff --git a/includes/class-wc-payments-account.php b/includes/class-wc-payments-account.php index 690d186cfb6..6c590950da6 100644 --- a/includes/class-wc-payments-account.php +++ b/includes/class-wc-payments-account.php @@ -11,6 +11,7 @@ use Automattic\WooCommerce\Admin\Notes\DataStore; use Automattic\WooCommerce\Admin\Notes\Note; +use WCPay\Constants\Country_Code; use WCPay\Core\Server\Request\Get_Account; use WCPay\Core\Server\Request\Get_Account_Capital_Link; use WCPay\Core\Server\Request\Get_Account_Login_Data; @@ -277,7 +278,7 @@ public function get_account_status_data() { return [ 'email' => $account['email'] ?? '', - 'country' => $account['country'] ?? 'US', + 'country' => $account['country'] ?? Country_Code::UNITED_STATES, 'status' => $account['status'], 'created' => $account['created'] ?? '', 'paymentsEnabled' => $account['payments_enabled'], @@ -1795,7 +1796,7 @@ private function get_actioned_notes(): array { */ public function get_account_country() { $account = $this->get_cached_account_data(); - return $account['country'] ?? 'US'; + return $account['country'] ?? Country_Code::UNITED_STATES; } /** diff --git a/includes/class-wc-payments-features.php b/includes/class-wc-payments-features.php index 904164421e0..9038a5c4898 100644 --- a/includes/class-wc-payments-features.php +++ b/includes/class-wc-payments-features.php @@ -5,6 +5,8 @@ * @package WooCommerce\Payments */ +use WCPay\Constants\Country_Code; + if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } @@ -310,7 +312,7 @@ public static function is_stripe_billing_eligible() { } $store_base_location = wc_get_base_location(); - return ! empty( $store_base_location['country'] ) && 'US' === $store_base_location['country']; + return ! empty( $store_base_location['country'] ) && Country_Code::UNITED_STATES === $store_base_location['country']; } /** diff --git a/includes/class-wc-payments-payment-request-button-handler.php b/includes/class-wc-payments-payment-request-button-handler.php index b764ad4d1bb..135ea785bd4 100644 --- a/includes/class-wc-payments-payment-request-button-handler.php +++ b/includes/class-wc-payments-payment-request-button-handler.php @@ -13,6 +13,7 @@ exit; } +use WCPay\Constants\Country_Code; use WCPay\Exceptions\Invalid_Price_Exception; use WCPay\Fraud_Prevention\Fraud_Prevention_Service; use WCPay\Logger; @@ -442,7 +443,7 @@ public function get_normalized_postal_code( $postcode, $country ) { * when passing it back from the shippingcontactselected object. This causes WC to invalidate * the postal code and not calculate shipping zones correctly. */ - if ( 'GB' === $country ) { + if ( Country_Code::UNITED_KINGDOM === $country ) { // Replaces a redacted string with something like LN10***. return str_pad( preg_replace( '/\s+/', '', $postcode ), 7, '*' ); } diff --git a/includes/class-wc-payments-utils.php b/includes/class-wc-payments-utils.php index e49e6c65359..136f36b8d83 100644 --- a/includes/class-wc-payments-utils.php +++ b/includes/class-wc-payments-utils.php @@ -10,6 +10,7 @@ } use WCPay\Exceptions\{ Amount_Too_Small_Exception, API_Exception, Connection_Exception }; +use WCPay\Constants\Country_Code; /** * WC Payments Utils class @@ -223,44 +224,44 @@ public static function zero_decimal_currencies(): array { */ public static function supported_countries(): array { return [ - 'AE' => __( 'United Arab Emirates', 'woocommerce-payments' ), - 'AT' => __( 'Austria', 'woocommerce-payments' ), - 'AU' => __( 'Australia', 'woocommerce-payments' ), - 'BE' => __( 'Belgium', 'woocommerce-payments' ), - 'BG' => __( 'Bulgaria', 'woocommerce-payments' ), - 'CA' => __( 'Canada', 'woocommerce-payments' ), - 'CH' => __( 'Switzerland', 'woocommerce-payments' ), - 'CY' => __( 'Cyprus', 'woocommerce-payments' ), - 'CZ' => __( 'Czech Republic', 'woocommerce-payments' ), - 'DE' => __( 'Germany', 'woocommerce-payments' ), - 'DK' => __( 'Denmark', 'woocommerce-payments' ), - 'EE' => __( 'Estonia', 'woocommerce-payments' ), - 'FI' => __( 'Finland', 'woocommerce-payments' ), - 'ES' => __( 'Spain', 'woocommerce-payments' ), - 'FR' => __( 'France', 'woocommerce-payments' ), - 'HR' => __( 'Croatia', 'woocommerce-payments' ), - 'JP' => __( 'Japan', 'woocommerce-payments' ), - 'LU' => __( 'Luxembourg', 'woocommerce-payments' ), - 'GB' => __( 'United Kingdom (UK)', 'woocommerce-payments' ), - 'GR' => __( 'Greece', 'woocommerce-payments' ), - 'HK' => __( 'Hong Kong', 'woocommerce-payments' ), - 'HU' => __( 'Hungary', 'woocommerce-payments' ), - 'IE' => __( 'Ireland', 'woocommerce-payments' ), - 'IT' => __( 'Italy', 'woocommerce-payments' ), - 'LT' => __( 'Lithuania', 'woocommerce-payments' ), - 'LV' => __( 'Latvia', 'woocommerce-payments' ), - 'MT' => __( 'Malta', 'woocommerce-payments' ), - 'NL' => __( 'Netherlands', 'woocommerce-payments' ), - 'NO' => __( 'Norway', 'woocommerce-payments' ), - 'NZ' => __( 'New Zealand', 'woocommerce-payments' ), - 'PL' => __( 'Poland', 'woocommerce-payments' ), - 'PT' => __( 'Portugal', 'woocommerce-payments' ), - 'RO' => __( 'Romania', 'woocommerce-payments' ), - 'SE' => __( 'Sweden', 'woocommerce-payments' ), - 'SI' => __( 'Slovenia', 'woocommerce-payments' ), - 'SK' => __( 'Slovakia', 'woocommerce-payments' ), - 'SG' => __( 'Singapore', 'woocommerce-payments' ), - 'US' => __( 'United States (US)', 'woocommerce-payments' ), + Country_Code::UNITED_ARAB_EMIRATES => __( 'United Arab Emirates', 'woocommerce-payments' ), + Country_Code::AUSTRIA => __( 'Austria', 'woocommerce-payments' ), + Country_Code::AUSTRALIA => __( 'Australia', 'woocommerce-payments' ), + Country_Code::BELGIUM => __( 'Belgium', 'woocommerce-payments' ), + Country_Code::BULGARIA => __( 'Bulgaria', 'woocommerce-payments' ), + Country_Code::CANADA => __( 'Canada', 'woocommerce-payments' ), + Country_Code::SWITZERLAND => __( 'Switzerland', 'woocommerce-payments' ), + Country_Code::CYPRUS => __( 'Cyprus', 'woocommerce-payments' ), + Country_Code::CZECHIA => __( 'Czech Republic', 'woocommerce-payments' ), + Country_Code::GERMANY => __( 'Germany', 'woocommerce-payments' ), + Country_Code::DENMARK => __( 'Denmark', 'woocommerce-payments' ), + Country_Code::ESTONIA => __( 'Estonia', 'woocommerce-payments' ), + Country_Code::FINLAND => __( 'Finland', 'woocommerce-payments' ), + Country_Code::SPAIN => __( 'Spain', 'woocommerce-payments' ), + Country_Code::FRANCE => __( 'France', 'woocommerce-payments' ), + Country_Code::CROATIA => __( 'Croatia', 'woocommerce-payments' ), + Country_Code::JAPAN => __( 'Japan', 'woocommerce-payments' ), + Country_Code::LUXEMBOURG => __( 'Luxembourg', 'woocommerce-payments' ), + Country_Code::UNITED_KINGDOM => __( 'United Kingdom (UK)', 'woocommerce-payments' ), + Country_Code::GREECE => __( 'Greece', 'woocommerce-payments' ), + Country_Code::HONG_KONG => __( 'Hong Kong', 'woocommerce-payments' ), + Country_Code::HUNGARY => __( 'Hungary', 'woocommerce-payments' ), + Country_Code::IRELAND => __( 'Ireland', 'woocommerce-payments' ), + Country_Code::ITALY => __( 'Italy', 'woocommerce-payments' ), + Country_Code::LITHUANIA => __( 'Lithuania', 'woocommerce-payments' ), + Country_Code::LATVIA => __( 'Latvia', 'woocommerce-payments' ), + Country_Code::MALTA => __( 'Malta', 'woocommerce-payments' ), + Country_Code::NETHERLANDS => __( 'Netherlands', 'woocommerce-payments' ), + Country_Code::NORWAY => __( 'Norway', 'woocommerce-payments' ), + Country_Code::NEW_ZEALAND => __( 'New Zealand', 'woocommerce-payments' ), + Country_Code::POLAND => __( 'Poland', 'woocommerce-payments' ), + Country_Code::PORTUGAL => __( 'Portugal', 'woocommerce-payments' ), + Country_Code::ROMANIA => __( 'Romania', 'woocommerce-payments' ), + Country_Code::SWEDEN => __( 'Sweden', 'woocommerce-payments' ), + Country_Code::SLOVENIA => __( 'Slovenia', 'woocommerce-payments' ), + Country_Code::SLOVAKIA => __( 'Slovakia', 'woocommerce-payments' ), + Country_Code::SINGAPORE => __( 'Singapore', 'woocommerce-payments' ), + Country_Code::UNITED_STATES => __( 'United States (US)', 'woocommerce-payments' ), ]; } diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index cad21f86d9e..f5046144bed 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -414,6 +414,7 @@ public static function init() { include_once __DIR__ . '/exceptions/class-fraud-ruleset-exception.php'; include_once __DIR__ . '/exceptions/class-order-not-found-exception.php'; include_once __DIR__ . '/constants/class-base-constant.php'; + include_once __DIR__ . '/constants/class-country-code.php'; include_once __DIR__ . '/constants/class-fraud-meta-box-type.php'; include_once __DIR__ . '/constants/class-order-mode.php'; include_once __DIR__ . '/constants/class-order-status.php'; diff --git a/includes/constants/class-country-code.php b/includes/constants/class-country-code.php new file mode 100644 index 00000000000..790059d65ef --- /dev/null +++ b/includes/constants/class-country-code.php @@ -0,0 +1,231 @@ + [], + Country_Code::AFGHANISTAN => [], // Angola. - 'AO' => [], + Country_Code::ANDORRA => [], // Argentina. - 'AR' => [ + Country_Code::ARGENTINA => [ 'C' => [ 'Ciudad Autónoma de Buenos Aires', 'Ciudad Autónoma de Buenos Aires', NULL ], 'B' => [ 'Buenos Aires', 'Buenos Aires', NULL ], 'K' => [ 'Catamarca', 'Catamarca', NULL ], @@ -78,9 +78,9 @@ class Payment_Request_Button_States { 'T' => [ 'Tucumán', 'Tucumán', NULL ], ], // Austria. - 'AT' => [], + Country_Code::AUSTRIA => [], // Australia. - 'AU' =>[ + Country_Code::AUSTRALIA =>[ 'ACT' => [ 'ACT', 'Australian Capital Territory', NULL ], 'NSW' => [ 'NSW', 'New South Wales', NULL ], 'NT' => [ 'NT', 'Northern Territory', NULL ], @@ -94,21 +94,21 @@ class Payment_Request_Button_States { // Aland Islands. 'AX' => [], // Bangladesh. - 'BD' => [], + Country_Code::BANGLADESH => [], // Belgium. - 'BE' => [], + Country_Code::BELGIUM => [], // Bulgaria. - 'BG' => [], + Country_Code::BULGARIA => [], // Bahrain. - 'BH' => [], + Country_Code::BAHRAIN => [], // Burundi. - 'BI' => [], + Country_Code::BURUNDI => [], // Benin. - 'BJ' => [], + Country_Code::BENIN => [], // Bolivia. - 'BO' => [], + Country_Code::BOLIVIA => [], // Brazil. - 'BR' => [ + Country_Code::BRAZIL => [ 'AC' => [ 'AC', 'Acre', NULL ], 'AL' => [ 'AL', 'Alagoas', NULL ], 'AP' => [ 'AP', 'Amapá', NULL ], @@ -138,7 +138,7 @@ class Payment_Request_Button_States { 'TO' => [ 'TO', 'Tocantins', NULL ], ], // Canada. - 'CA' => [ + Country_Code::CANADA => [ 'AB' => [ 'AB', 'Alberta', 'Alberta' ], 'BC' => [ 'BC', 'British Columbia', 'Colombie-Britannique' ], 'MB' => [ 'MB', 'Manitoba', 'Manitoba' ], @@ -154,9 +154,9 @@ class Payment_Request_Button_States { 'YT' => [ 'YT', 'Yukon', 'Yukon' ], ], // Switzerland. - 'CH' => [], + Country_Code::SWITZERLAND => [], // China. - 'CN' => [ + Country_Code::CHINA => [ 'CN1' => [ 'Yunnan Sheng', 'Yunnan Sheng', '云南省' ], 'CN2' => [ 'Beijing Shi', 'Beijing Shi', '北京市' ], 'CN3' => [ 'Tianjin Shi', 'Tianjin Shi', '天津市' ], @@ -193,19 +193,19 @@ class Payment_Request_Button_States { // [ 'Hong Kong', 'Hong Kong', '香港' ], ], // Czech Republic. - 'CZ' => [], + Country_Code::CZECHIA => [], // Germany. - 'DE' => [], + Country_Code::GERMANY => [], // Denmark. - 'DK' => [], + Country_Code::DENMARK => [], // Dominican Republic. - 'DO' => [], + Country_Code::DOMINICAN_REPUBLIC => [], // Algeria. - 'DZ' => [], + Country_Code::ALGERIA => [], // Estonia. - 'EE' => [], + Country_Code::ESTONIA => [], // Egypt. - 'EG' => [ + Country_Code::EGYPT => [ 'EGALX' => [ 'Alexandria Governorate', 'Alexandria Governorate', 'الإسكندرية' ], 'EGASN' => [ 'Aswan Governorate', 'Aswan Governorate', 'أسوان' ], 'EGAST' => [ 'Asyut Governorate', 'Asyut Governorate', 'أسيوط' ], @@ -235,7 +235,7 @@ class Payment_Request_Button_States { 'EGWAD' => [ 'New Valley Governorate', 'New Valley Governorate', 'الوادي الجديد' ], ], // Spain. - 'ES' => [ + Country_Code::SPAIN => [ 'C' => [ 'A Coruña', 'A Coruña', NULL ], 'VI' => [ 'Álava', 'Álava', NULL ], 'AB' => [ 'Albacete', 'Albacete', NULL ], @@ -290,19 +290,19 @@ class Payment_Request_Button_States { 'Z' => [ 'Zaragoza', 'Zaragoza', NULL ], ], // Finland. - 'FI' => [], + Country_Code::FINLAND => [], // France. - 'FR' => [], + Country_Code::FRANCE => [], // French Guiana. 'GF' => [], // Ghana. - 'GH' => [], + Country_Code::GHANA => [], // Guadeloupe. 'GP' => [], // Greece. - 'GR' => [], + Country_Code::GREECE => [], // Guatemala. - 'GT' => [], + Country_Code::GUATEMALA => [], // Hong Kong. 'HK' => [ 'HONG KONG' => [ 'Hong Kong Island', 'Hong Kong Island', '香港島' ], @@ -310,9 +310,9 @@ class Payment_Request_Button_States { 'NEW TERRITORIES' => [ 'New Territories', 'New Territories', '新界' ], ], // Hungary. - 'HU' => [], + Country_Code::HUNGARY => [], // Indonesia. - 'ID' => [ + Country_Code::INDONESIA => [ 'AC' => [ 'Aceh', 'Aceh', NULL ], 'SU' => [ 'Sumatera Utara', 'Sumatera Utara', NULL ], 'SB' => [ 'Sumatera Barat', 'Sumatera Barat', NULL ], @@ -351,7 +351,7 @@ class Payment_Request_Button_States { // [ 'Kalimantan Timur', 'Kalimantan Timur', NULL ], ], // Ireland. - 'IE' => [ + Country_Code::IRELAND => [ 'CW' => [ 'Co. Carlow', 'Co. Carlow', NULL ], 'CN' => [ 'Co. Cavan', 'Co. Cavan', NULL ], 'CE' => [ 'Co. Clare', 'Co. Clare', NULL ], @@ -380,11 +380,11 @@ class Payment_Request_Button_States { 'WW' => [ 'Co. Wicklow', 'Co. Wicklow', NULL ], ], // Israel. - 'IL' => [], + Country_Code::ISRAEL => [], // Isle of Man. 'IM' => [], // India. - 'IN' => [ + Country_Code::INDIA => [ 'AP' => [ 'Andhra Pradesh', 'Andhra Pradesh', NULL ], 'AR' => [ 'Arunachal Pradesh', 'Arunachal Pradesh', NULL ], 'AS' => [ 'Assam', 'Assam', NULL ], @@ -424,7 +424,7 @@ class Payment_Request_Button_States { 'PY' => [ 'Puducherry', 'Puducherry', NULL ], ], // Iran. - 'IR' => [ + Country_Code::IRAN => [ 'KHZ' => [ 'Khuzestan Province', 'Khuzestan Province', 'استان خوزستان' ], 'THR' => [ 'Tehran Province', 'Tehran Province', 'استان تهران' ], 'ILM' => [ 'Ilam Province', 'Ilam Province', 'استان ایلام' ], @@ -458,9 +458,9 @@ class Payment_Request_Button_States { 'SBN' => [ 'Sistan and Baluchestan Province', 'Sistan and Baluchestan Province', 'استان سیستان و بلوچستان' ], ], // Iceland. - 'IS' => [], + Country_Code::ICELAND => [], // Italy. - 'IT' => [ + Country_Code::ITALY => [ 'AG' => [ 'AG', 'Agrigento', NULL ], 'AL' => [ 'AL', 'Alessandria', NULL ], 'AN' => [ 'AN', 'Ancona', NULL ], @@ -570,7 +570,7 @@ class Payment_Request_Button_States { 'VT' => [ 'VT', 'Viterbo', NULL ], ], // Jamaica. - 'JM' => [ + Country_Code::JAMAICA => [ 'JM-01' => [ 'Kingston', 'Kingston', NULL ], 'JM-02' => [ 'St. Andrew', 'St. Andrew', NULL ], 'JM-03' => [ 'St. Thomas', 'St. Thomas', NULL ], @@ -587,7 +587,7 @@ class Payment_Request_Button_States { 'JM-14' => [ 'St. Catherine', 'St. Catherine', NULL ], ], // Japan. - 'JP' => [ + Country_Code::JAPAN => [ 'JP01' => [ 'Hokkaido', 'Hokkaido', '北海道' ], 'JP02' => [ 'Aomori', 'Aomori', '青森県' ], 'JP03' => [ 'Iwate', 'Iwate', '岩手県' ], @@ -637,29 +637,29 @@ class Payment_Request_Button_States { 'JP47' => [ 'Okinawa', 'Okinawa', '沖縄県' ], ], // Kenya. - 'KE' => [], + Country_Code::KENYA => [], // South Korea. - 'KR' => [], + Country_Code::SOUTH_KOREA => [], // Kuwait. - 'KW' => [], + Country_Code::KUWAIT => [], // Laos. - 'LA' => [], + Country_Code::LAOS => [], // Lebanon. - 'LB' => [], + Country_Code::LEBANON => [], // Sri Lanka. 'LK' => [], // Liberia. - 'LR' => [], + Country_Code::LIBERIA => [], // Luxembourg. - 'LU' => [], + Country_Code::LUXEMBOURG => [], // Moldova. - 'MD' => [], + Country_Code::MOLDOVA => [], // Martinique. 'MQ' => [], // Malta. - 'MT' => [], + Country_Code::MALTA => [], // Mexico. - 'MX' => [ + Country_Code::MEXICO => [ 'DF' => [ 'CDMX', 'Ciudad de México', NULL ], 'JA' => [ 'Jal.', 'Jalisco', NULL ], 'NL' => [ 'N.L.', 'Nuevo León', NULL ], @@ -694,7 +694,7 @@ class Payment_Request_Button_States { 'ZA' => [ 'Zac.', 'Zacatecas', NULL ], ], // Malaysia. - 'MY' => [ + Country_Code::MALAYSIA => [ 'JHR' => [ 'Johor', 'Johor', NULL ], 'KDH' => [ 'Kedah', 'Kedah', NULL ], 'KTN' => [ 'Kelantan', 'Kelantan', NULL ], @@ -713,7 +713,7 @@ class Payment_Request_Button_States { 'KUL' => [ 'Kuala Lumpur', 'Kuala Lumpur', NULL ], ], // Mozambique. - 'MZ' => [ + Country_Code::MOZAMBIQUE => [ 'MZP' => [ 'Cabo Delgado', 'Cabo Delgado', NULL ], 'MZG' => [ 'Gaza', 'Gaza', NULL ], 'MZI' => [ 'Inhambane', 'Inhambane', NULL ], @@ -727,9 +727,9 @@ class Payment_Request_Button_States { 'MZQ' => [ 'Zambezia', 'Zambezia', NULL ], ], // Namibia. - 'NA' => [], + Country_Code::NAMIBIA => [], // Nigeria. - 'NG' => [ + Country_Code::NIGERIA => [ 'AB' => [ 'Abia', 'Abia', NULL ], 'FC' => [ 'Federal Capital Territory', 'Federal Capital Territory', NULL ], 'AD' => [ 'Adamawa', 'Adamawa', NULL ], @@ -769,15 +769,15 @@ class Payment_Request_Button_States { 'ZA' => [ 'Zamfara', 'Zamfara', NULL ], ], // Netherlands. - 'NL' => [], + Country_Code::NETHERLANDS => [], // Norway. - 'NO' => [], + Country_Code::NORWAY => [], // Nepal. - 'NP' => [], + Country_Code::NEPAL => [], // New Zealand. - 'NZ' => [], + Country_Code::NEW_ZEALAND => [], // Peru. - 'PE' => [ + Country_Code::PERU => [ 'CAL' => [ 'Callao', 'Callao', NULL ], 'LMA' => [ 'Municipalidad Metropolitana de Lima', 'Municipalidad Metropolitana de Lima', NULL ], 'AMA' => [ 'Amazonas', 'Amazonas', NULL ], @@ -806,7 +806,7 @@ class Payment_Request_Button_States { 'UCA' => [ 'Ucayali', 'Ucayali', NULL ], ], // Philippines. - 'PH' => [ + Country_Code::PHILIPPINES => [ 'ABR' => [ 'Abra', 'Abra', NULL ], 'AGN' => [ 'Agusan del Norte', 'Agusan del Norte', NULL ], 'AGS' => [ 'Agusan del Sur', 'Agusan del Sur', NULL ], @@ -891,31 +891,31 @@ class Payment_Request_Button_States { '00' => [ 'Metro Manila', 'Metro Manila', NULL ], ], // Pakistan. - 'PK' => [], + Country_Code::PAKISTAN => [], // Poland. - 'PL' => [], + Country_Code::POLAND => [], // Puerto Rico. 'PR' => [], // Portugal. - 'PT' => [], + Country_Code::PORTUGAL => [], // Paraguay. - 'PY' => [], + Country_Code::PARAGUAY => [], // Reunion. 'RE' => [], // Romania. - 'RO' => [], + Country_Code::ROMANIA => [], // Serbia. - 'RS' => [], + Country_Code::SERBIA => [], // Sweden. - 'SE' => [], + Country_Code::SWEDEN => [], // Singapore. - 'SG' => [], + Country_Code::SINGAPORE => [], // Slovenia. - 'SI' => [], + Country_Code::SLOVENIA => [], // Slovakia. - 'SK' => [], + Country_Code::SLOVAKIA => [], // Thailand. - 'TH' => [ + Country_Code::THAILAND => [ 'TH-37' => [ 'Amnat Charoen', 'Amnat Charoen', 'อำนาจเจริญ' ], 'TH-15' => [ 'Ang Thong', 'Ang Thong', 'อ่างทอง' ], 'TH-14' => [ 'Phra Nakhon Si Ayutthaya', 'Phra Nakhon Si Ayutthaya', 'พระนครศรีอยุธยา' ], @@ -995,7 +995,7 @@ class Payment_Request_Button_States { 'TH-35' => [ 'Yasothon', 'Yasothon', 'ยโสธร' ], ], // Turkey. - 'TR' => [ + Country_Code::TURKEY => [ 'TR01' => [ 'Adana', 'Adana', NULL ], 'TR02' => [ 'Adıyaman', 'Adıyaman', NULL ], 'TR03' => [ 'Afyon', 'Afyon', NULL ], @@ -1079,13 +1079,13 @@ class Payment_Request_Button_States { 'TR81' => [ 'Düzce', 'Düzce', NULL ], ], // Tanzania. - 'TZ' => [], + Country_Code::TANZANIA => [], // Uganda. - 'UG' => [], + Country_Code::UGANDA => [], // United States Minor Outlying Islands. 'UM' => [], // United States. - 'US' => [ + Country_Code::UNITED_STATES => [ 'AL' => [ 'AL', 'Alabama', NULL ], 'AK' => [ 'AK', 'Alaska', NULL ], 'AZ' => [ 'AZ', 'Arizona', NULL ], @@ -1150,13 +1150,13 @@ class Payment_Request_Button_States { //[ 'VI', 'Virgin Islands', NULL ], ], // Vietnam. - 'VN' => [], + Country_Code::VIETNAM => [], // Mayotte. 'YT' => [], // South Africa. - 'ZA' => [], + Country_Code::SOUTH_AFRICA => [], // Zambia. - 'ZM' => [], + Country_Code::ZAMBIA => [], ]; // phpcs:enable } diff --git a/includes/multi-currency/CountryFlags.php b/includes/multi-currency/CountryFlags.php index 286e77dfbe2..5bc494b3dd4 100644 --- a/includes/multi-currency/CountryFlags.php +++ b/includes/multi-currency/CountryFlags.php @@ -7,6 +7,8 @@ namespace WCPay\MultiCurrency; +use WCPay\Constants\Country_Code; + defined( 'ABSPATH' ) || exit; /** @@ -15,257 +17,257 @@ class CountryFlags { const EMOJI_COUNTRIES_FLAGS = [ - 'AD' => '🇦🇩', - 'AE' => '🇦🇪', - 'AF' => '🇦🇫', - 'AG' => '🇦🇬', - 'AI' => '🇦🇮', - 'AL' => '🇦🇱', - 'AM' => '🇦🇲', - 'AO' => '🇦🇴', - 'AQ' => '🇦🇶', - 'AR' => '🇦🇷', - 'AS' => '🇦🇸', - 'AT' => '🇦🇹', - 'AU' => '🇦🇺', - 'AW' => '🇦🇼', - 'AX' => '🇦🇽', - 'AZ' => '🇦🇿', - 'BA' => '🇧🇦', - 'BB' => '🇧🇧', - 'BD' => '🇧🇩', - 'BE' => '🇧🇪', - 'BF' => '🇧🇫', - 'BG' => '🇧🇬', - 'BH' => '🇧🇭', - 'BI' => '🇧🇮', - 'BJ' => '🇧🇯', - 'BL' => '🇧🇱', - 'BM' => '🇧🇲', - 'BN' => '🇧🇳', - 'BO' => '🇧🇴', - 'BQ' => '🇧🇶', - 'BR' => '🇧🇷', - 'BS' => '🇧🇸', - 'BT' => '🇧🇹', - 'BV' => '🇧🇻', - 'BW' => '🇧🇼', - 'BY' => '🇧🇾', - 'BZ' => '🇧🇿', - 'CA' => '🇨🇦', - 'CC' => '🇨🇨', - 'CD' => '🇨🇩', - 'CF' => '🇨🇫', - 'CG' => '🇨🇬', - 'CH' => '🇨🇭', - 'CI' => '🇨🇮', - 'CK' => '🇨🇰', - 'CL' => '🇨🇱', - 'CM' => '🇨🇲', - 'CN' => '🇨🇳', - 'CO' => '🇨🇴', - 'CR' => '🇨🇷', - 'CU' => '🇨🇺', - 'CV' => '🇨🇻', - 'CW' => '🇨🇼', - 'CX' => '🇨🇽', - 'CY' => '🇨🇾', - 'CZ' => '🇨🇿', - 'DE' => '🇩🇪', - 'DJ' => '🇩🇯', - 'DK' => '🇩🇰', - 'DM' => '🇩🇲', - 'DO' => '🇩🇴', - 'DZ' => '🇩🇿', - 'EC' => '🇪🇨', - 'EE' => '🇪🇪', - 'EG' => '🇪🇬', - 'EH' => '🇪🇭', - 'ER' => '🇪🇷', - 'ES' => '🇪🇸', - 'ET' => '🇪🇹', - 'EU' => '🇪🇺', - 'FI' => '🇫🇮', - 'FJ' => '🇫🇯', - 'FK' => '🇫🇰', - 'FM' => '🇫🇲', - 'FO' => '🇫🇴', - 'FR' => '🇫🇷', - 'GA' => '🇬🇦', - 'GB' => '🇬🇧', - 'GD' => '🇬🇩', - 'GE' => '🇬🇪', - 'GF' => '🇬🇫', - 'GG' => '🇬🇬', - 'GH' => '🇬🇭', - 'GI' => '🇬🇮', - 'GL' => '🇬🇱', - 'GM' => '🇬🇲', - 'GN' => '🇬🇳', - 'GP' => '🇬🇵', - 'GQ' => '🇬🇶', - 'GR' => '🇬🇷', - 'GS' => '🇬🇸', - 'GT' => '🇬🇹', - 'GU' => '🇬🇺', - 'GW' => '🇬🇼', - 'GY' => '🇬🇾', - 'HK' => '🇭🇰', - 'HM' => '🇭🇲', - 'HN' => '🇭🇳', - 'HR' => '🇭🇷', - 'HT' => '🇭🇹', - 'HU' => '🇭🇺', - 'ID' => '🇮🇩', - 'IE' => '🇮🇪', - 'IL' => '🇮🇱', - 'IM' => '🇮🇲', - 'IN' => '🇮🇳', - 'IO' => '🇮🇴', - 'IQ' => '🇮🇶', - 'IR' => '🇮🇷', - 'IS' => '🇮🇸', - 'IT' => '🇮🇹', - 'JE' => '🇯🇪', - 'JM' => '🇯🇲', - 'JO' => '🇯🇴', - 'JP' => '🇯🇵', - 'KE' => '🇰🇪', - 'KG' => '🇰🇬', - 'KH' => '🇰🇭', - 'KI' => '🇰🇮', - 'KM' => '🇰🇲', - 'KN' => '🇰🇳', - 'KP' => '🇰🇵', - 'KR' => '🇰🇷', - 'KW' => '🇰🇼', - 'KY' => '🇰🇾', - 'KZ' => '🇰🇿', - 'LA' => '🇱🇦', - 'LB' => '🇱🇧', - 'LC' => '🇱🇨', - 'LI' => '🇱🇮', - 'LK' => '🇱🇰', - 'LR' => '🇱🇷', - 'LS' => '🇱🇸', - 'LT' => '🇱🇹', - 'LU' => '🇱🇺', - 'LV' => '🇱🇻', - 'LY' => '🇱🇾', - 'MA' => '🇲🇦', - 'MC' => '🇲🇨', - 'MD' => '🇲🇩', - 'ME' => '🇲🇪', - 'MF' => '🇲🇫', - 'MG' => '🇲🇬', - 'MH' => '🇲🇭', - 'MK' => '🇲🇰', - 'ML' => '🇲🇱', - 'MM' => '🇲🇲', - 'MN' => '🇲🇳', - 'MO' => '🇲🇴', - 'MP' => '🇲🇵', - 'MQ' => '🇲🇶', - 'MR' => '🇲🇷', - 'MS' => '🇲🇸', - 'MT' => '🇲🇹', - 'MU' => '🇲🇺', - 'MV' => '🇲🇻', - 'MW' => '🇲🇼', - 'MX' => '🇲🇽', - 'MY' => '🇲🇾', - 'MZ' => '🇲🇿', - 'NA' => '🇳🇦', - 'NC' => '🇳🇨', - 'NE' => '🇳🇪', - 'NF' => '🇳🇫', - 'NG' => '🇳🇬', - 'NI' => '🇳🇮', - 'NL' => '🇳🇱', - 'NO' => '🇳🇴', - 'NP' => '🇳🇵', - 'NR' => '🇳🇷', - 'NU' => '🇳🇺', - 'NZ' => '🇳🇿', - 'OM' => '🇴🇲', - 'PA' => '🇵🇦', - 'PE' => '🇵🇪', - 'PF' => '🇵🇫', - 'PG' => '🇵🇬', - 'PH' => '🇵🇭', - 'PK' => '🇵🇰', - 'PL' => '🇵🇱', - 'PM' => '🇵🇲', - 'PN' => '🇵🇳', - 'PR' => '🇵🇷', - 'PS' => '🇵🇸', - 'PT' => '🇵🇹', - 'PW' => '🇵🇼', - 'PY' => '🇵🇾', - 'QA' => '🇶🇦', - 'RE' => '🇷🇪', - 'RO' => '🇷🇴', - 'RS' => '🇷🇸', - 'RU' => '🇷🇺', - 'RW' => '🇷🇼', - 'SA' => '🇸🇦', - 'SB' => '🇸🇧', - 'SC' => '🇸🇨', - 'SD' => '🇸🇩', - 'SE' => '🇸🇪', - 'SG' => '🇸🇬', - 'SH' => '🇸🇭', - 'SI' => '🇸🇮', - 'SJ' => '🇸🇯', - 'SK' => '🇸🇰', - 'SL' => '🇸🇱', - 'SM' => '🇸🇲', - 'SN' => '🇸🇳', - 'SO' => '🇸🇴', - 'SR' => '🇸🇷', - 'SS' => '🇸🇸', - 'ST' => '🇸🇹', - 'SV' => '🇸🇻', - 'SX' => '🇸🇽', - 'SY' => '🇸🇾', - 'SZ' => '🇸🇿', - 'TC' => '🇹🇨', - 'TD' => '🇹🇩', - 'TF' => '🇹🇫', - 'TG' => '🇹🇬', - 'TH' => '🇹🇭', - 'TJ' => '🇹🇯', - 'TK' => '🇹🇰', - 'TL' => '🇹🇱', - 'TM' => '🇹🇲', - 'TN' => '🇹🇳', - 'TO' => '🇹🇴', - 'TR' => '🇹🇷', - 'TT' => '🇹🇹', - 'TV' => '🇹🇻', - 'TW' => '🇹🇼', - 'TZ' => '🇹🇿', - 'UA' => '🇺🇦', - 'UG' => '🇺🇬', - 'UM' => '🇺🇲', - 'US' => '🇺🇸', - 'UY' => '🇺🇾', - 'UZ' => '🇺🇿', - 'VA' => '🇻🇦', - 'VC' => '🇻🇨', - 'VE' => '🇻🇪', - 'VG' => '🇻🇬', - 'VI' => '🇻🇮', - 'VN' => '🇻🇳', - 'VU' => '🇻🇺', - 'WF' => '🇼🇫', - 'WS' => '🇼🇸', - 'XK' => '🇽🇰', - 'YE' => '🇾🇪', - 'YT' => '🇾🇹', - 'ZA' => '🇿🇦', - 'ZM' => '🇿🇲', - 'ZW' => '🇿🇼', + Country_Code::ANDORRA => '🇦🇩', + Country_Code::UNITED_ARAB_EMIRATES => '🇦🇪', + Country_Code::AFGHANISTAN => '🇦🇫', + Country_Code::ANTIGUA_AND_BARBUDA => '🇦🇬', + Country_Code::ANGUILLA => '🇦🇮', + Country_Code::ALBANIA => '🇦🇱', + Country_Code::ARMENIA => '🇦🇲', + Country_Code::ANGOLA => '🇦🇴', + Country_Code::ANTARCTICA => '🇦🇶', + Country_Code::ARGENTINA => '🇦🇷', + Country_Code::AMERICAN_SAMOA => '🇦🇸', + Country_Code::AUSTRIA => '🇦🇹', + Country_Code::AUSTRALIA => '🇦🇺', + Country_Code::ARUBA => '🇦🇼', + Country_Code::ALAND_ISLANDS => '🇦🇽', + Country_Code::AZERBAIJAN => '🇦🇿', + Country_Code::BOSNIA_AND_HERZEGOVINA => '🇧🇦', + Country_Code::BARBADOS => '🇧🇧', + Country_Code::BANGLADESH => '🇧🇩', + Country_Code::BELGIUM => '🇧🇪', + Country_Code::BURKINA_FASO => '🇧🇫', + Country_Code::BULGARIA => '🇧🇬', + Country_Code::BAHRAIN => '🇧🇭', + Country_Code::BURUNDI => '🇧🇮', + Country_Code::BENIN => '🇧🇯', + Country_Code::SAINT_BARTHELEMY => '🇧🇱', + Country_Code::BERMUDA => '🇧🇲', + Country_Code::BRUNEI => '🇧🇳', + Country_Code::BOLIVIA => '🇧🇴', + Country_Code::CARIBBEAN_NETHERLANDS => '🇧🇶', + Country_Code::BRAZIL => '🇧🇷', + Country_Code::BAHAMAS => '🇧🇸', + Country_Code::BHUTAN => '🇧🇹', + Country_Code::BOUVET_ISLAND => '🇧🇻', + Country_Code::BOTSWANA => '🇧🇼', + Country_Code::BELARUS => '🇧🇾', + Country_Code::BELIZE => '🇧🇿', + Country_Code::CANADA => '🇨🇦', + Country_Code::COCOS_KEELING_ISLANDS => '🇨🇨', + Country_Code::DEMOCRATIC_REPUBLIC_OF_THE_CONGO => '🇨🇩', + Country_Code::CENTRAL_AFRICAN_REPUBLIC => '🇨🇫', + Country_Code::CONGO => '🇨🇬', + Country_Code::SWITZERLAND => '🇨🇭', + Country_Code::IVORY_COAST => '🇨🇮', + Country_Code::COOK_ISLANDS => '🇨🇰', + Country_Code::CHILE => '🇨🇱', + Country_Code::CAMEROON => '🇨🇲', + Country_Code::CHINA => '🇨🇳', + Country_Code::COLOMBIA => '🇨🇴', + Country_Code::COSTA_RICA => '🇨🇷', + Country_Code::CUBA => '🇨🇺', + Country_Code::CABO_VERDE => '🇨🇻', + 'CW' => '🇨🇼', + 'CX' => '🇨🇽', + Country_Code::CYPRUS => '🇨🇾', + Country_Code::CZECHIA => '🇨🇿', + Country_Code::GERMANY => '🇩🇪', + Country_Code::DJIBOUTI => '🇩🇯', + Country_Code::DENMARK => '🇩🇰', + Country_Code::DOMINICA => '🇩🇲', + Country_Code::DOMINICAN_REPUBLIC => '🇩🇴', + Country_Code::ALGERIA => '🇩🇿', + Country_Code::ECUADOR => '🇪🇨', + Country_Code::ESTONIA => '🇪🇪', + Country_Code::EGYPT => '🇪🇬', + 'EH' => '🇪🇭', + Country_Code::ERITREA => '🇪🇷', + Country_Code::SPAIN => '🇪🇸', + Country_Code::ETHIOPIA => '🇪🇹', + 'EU' => '🇪🇺', + Country_Code::FINLAND => '🇫🇮', + Country_Code::FIJI => '🇫🇯', + 'FK' => '🇫🇰', + Country_Code::MICRONESIA => '🇫🇲', + 'FO' => '🇫🇴', + Country_Code::FRANCE => '🇫🇷', + Country_Code::GABON => '🇬🇦', + Country_Code::UNITED_KINGDOM => '🇬🇧', + Country_Code::GRENADA => '🇬🇩', + Country_Code::GEORGIA => '🇬🇪', + 'GF' => '🇬🇫', + 'GG' => '🇬🇬', + Country_Code::GHANA => '🇬🇭', + Country_Code::GIBRALTAR => '🇬🇮', + 'GL' => '🇬🇱', + Country_Code::GAMBIA => '🇬🇲', + Country_Code::GUINEA => '🇬🇳', + 'GP' => '🇬🇵', + Country_Code::EQUATORIAL_GUINEA => '🇬🇶', + Country_Code::GREECE => '🇬🇷', + 'GS' => '🇬🇸', + Country_Code::GUATEMALA => '🇬🇹', + 'GU' => '🇬🇺', + Country_Code::GUINEA_BISSAU => '🇬🇼', + Country_Code::GUYANA => '🇬🇾', + Country_Code::HONG_KONG => '🇭🇰', + 'HM' => '🇭🇲', + Country_Code::HONDURAS => '🇭🇳', + Country_Code::CROATIA => '🇭🇷', + Country_Code::HAITI => '🇭🇹', + Country_Code::HUNGARY => '🇭🇺', + Country_Code::INDONESIA => '🇮🇩', + Country_Code::IRELAND => '🇮🇪', + Country_Code::ISRAEL => '🇮🇱', + 'IM' => '🇮🇲', + Country_Code::INDIA => '🇮🇳', + Country_Code::BRITISH_INDIAN_OCEAN_TERRITORY => '🇮🇴', + Country_Code::IRAQ => '🇮🇶', + Country_Code::IRAN => '🇮🇷', + Country_Code::ICELAND => '🇮🇸', + Country_Code::ITALY => '🇮🇹', + 'JE' => '🇯🇪', + Country_Code::JAMAICA => '🇯🇲', + Country_Code::JORDAN => '🇯🇴', + Country_Code::JAPAN => '🇯🇵', + Country_Code::KENYA => '🇰🇪', + Country_Code::KYRGYZSTAN => '🇰🇬', + Country_Code::CAMBODIA => '🇰🇭', + Country_Code::KIRIBATI => '🇰🇮', + Country_Code::COMOROS => '🇰🇲', + Country_Code::SAINT_KITTS_AND_NEVIS => '🇰🇳', + Country_Code::NORTH_KOREA => '🇰🇵', + Country_Code::SOUTH_KOREA => '🇰🇷', + Country_Code::KUWAIT => '🇰🇼', + 'KY' => '🇰🇾', + Country_Code::KAZAKHSTAN => '🇰🇿', + Country_Code::LAOS => '🇱🇦', + Country_Code::LEBANON => '🇱🇧', + Country_Code::SAINT_LUCIA => '🇱🇨', + Country_Code::LIECHTENSTEIN => '🇱🇮', + Country_Code::SRI_LANKA => '🇱🇰', + Country_Code::LIBERIA => '🇱🇷', + Country_Code::LESOTHO => '🇱🇸', + Country_Code::LITHUANIA => '🇱🇹', + Country_Code::LUXEMBOURG => '🇱🇺', + Country_Code::LATVIA => '🇱🇻', + Country_Code::LIBYA => '🇱🇾', + Country_Code::MOROCCO => '🇲🇦', + Country_Code::MONACO => '🇲🇨', + Country_Code::MOLDOVA => '🇲🇩', + Country_Code::MONTENEGRO => '🇲🇪', + 'MF' => '🇲🇫', + Country_Code::MADAGASCAR => '🇲🇬', + Country_Code::MARSHALL_ISLANDS => '🇲🇭', + Country_Code::NORTH_MACEDONIA => '🇲🇰', + Country_Code::MALI => '🇲🇱', + Country_Code::MYANMAR => '🇲🇲', + Country_Code::MONGOLIA => '🇲🇳', + 'MO' => '🇲🇴', + 'MP' => '🇲🇵', + 'MQ' => '🇲🇶', + Country_Code::MAURITANIA => '🇲🇷', + 'MS' => '🇲🇸', + Country_Code::MALTA => '🇲🇹', + Country_Code::MAURITIUS => '🇲🇺', + Country_Code::MALDIVES => '🇲🇻', + Country_Code::MALAWI => '🇲🇼', + Country_Code::MEXICO => '🇲🇽', + Country_Code::MALAYSIA => '🇲🇾', + Country_Code::MOZAMBIQUE => '🇲🇿', + Country_Code::NAMIBIA => '🇳🇦', + 'NC' => '🇳🇨', + Country_Code::NIGER => '🇳🇪', + 'NF' => '🇳🇫', + Country_Code::NIGERIA => '🇳🇬', + Country_Code::NICARAGUA => '🇳🇮', + Country_Code::NETHERLANDS => '🇳🇱', + Country_Code::NORWAY => '🇳🇴', + Country_Code::NEPAL => '🇳🇵', + Country_Code::NAURU => '🇳🇷', + 'NU' => '🇳🇺', + Country_Code::NEW_ZEALAND => '🇳🇿', + Country_Code::OMAN => '🇴🇲', + Country_Code::PANAMA => '🇵🇦', + Country_Code::PERU => '🇵🇪', + 'PF' => '🇵🇫', + Country_Code::PAPUA_NEW_GUINEA => '🇵🇬', + Country_Code::PHILIPPINES => '🇵🇭', + Country_Code::PAKISTAN => '🇵🇰', + Country_Code::POLAND => '🇵🇱', + 'PM' => '🇵🇲', + 'PN' => '🇵🇳', + 'PR' => '🇵🇷', + Country_Code::PALESTINE => '🇵🇸', + Country_Code::PORTUGAL => '🇵🇹', + Country_Code::PALAU => '🇵🇼', + Country_Code::PARAGUAY => '🇵🇾', + Country_Code::QATAR => '🇶🇦', + 'RE' => '🇷🇪', + Country_Code::ROMANIA => '🇷🇴', + Country_Code::SERBIA => '🇷🇸', + Country_Code::RUSSIA => '🇷🇺', + Country_Code::RWANDA => '🇷🇼', + Country_Code::SAUDI_ARABIA => '🇸🇦', + Country_Code::SOLOMON_ISLANDS => '🇸🇧', + Country_Code::SEYCHELLES => '🇸🇨', + Country_Code::SUDAN => '🇸🇩', + Country_Code::SWEDEN => '🇸🇪', + Country_Code::SINGAPORE => '🇸🇬', + 'SH' => '🇸🇭', + Country_Code::SLOVENIA => '🇸🇮', + 'SJ' => '🇸🇯', + Country_Code::SLOVAKIA => '🇸🇰', + Country_Code::SIERRA_LEONE => '🇸🇱', + Country_Code::SAN_MARINO => '🇸🇲', + Country_Code::SENEGAL => '🇸🇳', + Country_Code::SOMALIA => '🇸🇴', + Country_Code::SURINAME => '🇸🇷', + Country_Code::SOUTH_SUDAN => '🇸🇸', + Country_Code::SAO_TOME_AND_PRINCIPE => '🇸🇹', + Country_Code::EL_SALVADOR => '🇸🇻', + 'SX' => '🇸🇽', + Country_Code::SYRIA => '🇸🇾', + Country_Code::ESWATINI => '🇸🇿', + 'TC' => '🇹🇨', + Country_Code::CHAD => '🇹🇩', + 'TF' => '🇹🇫', + Country_Code::TOGO => '🇹🇬', + Country_Code::THAILAND => '🇹🇭', + Country_Code::TAJIKISTAN => '🇹🇯', + 'TK' => '🇹🇰', + Country_Code::EAST_TIMOR => '🇹🇱', + Country_Code::TURKMENISTAN => '🇹🇲', + Country_Code::TUNISIA => '🇹🇳', + Country_Code::TONGA => '🇹🇴', + Country_Code::TURKEY => '🇹🇷', + Country_Code::TRINIDAD_AND_TOBAGO => '🇹🇹', + Country_Code::TUVALU => '🇹🇻', + Country_Code::TAIWAN => '🇹🇼', + Country_Code::TANZANIA => '🇹🇿', + Country_Code::UKRAINE => '🇺🇦', + Country_Code::UGANDA => '🇺🇬', + 'UM' => '🇺🇲', + Country_Code::UNITED_STATES => '🇺🇸', + Country_Code::URUGUAY => '🇺🇾', + Country_Code::UZBEKISTAN => '🇺🇿', + Country_Code::VATICAN_CITY => '🇻🇦', + Country_Code::SAINT_VINCENT_AND_THE_GRENADINES => '🇻🇨', + Country_Code::VENEZUELA => '🇻🇪', + 'VG' => '🇻🇬', + 'VI' => '🇻🇮', + Country_Code::VIETNAM => '🇻🇳', + Country_Code::VANUATU => '🇻🇺', + 'WF' => '🇼🇫', + Country_Code::SAMOA => '🇼🇸', + Country_Code::KOSOVO => '🇽🇰', + Country_Code::YEMEN => '🇾🇪', + 'YT' => '🇾🇹', + Country_Code::SOUTH_AFRICA => '🇿🇦', + Country_Code::ZAMBIA => '🇿🇲', + Country_Code::ZIMBABWE => '🇿🇼', ]; /** diff --git a/includes/multi-currency/MultiCurrency.php b/includes/multi-currency/MultiCurrency.php index c862cc9f131..f1c890a656e 100644 --- a/includes/multi-currency/MultiCurrency.php +++ b/includes/multi-currency/MultiCurrency.php @@ -12,6 +12,7 @@ use WC_Payments_Utils; use WC_Payments_API_Client; use WC_Payments_Localization_Service; +use WCPay\Constants\Country_Code; use WCPay\Exceptions\API_Exception; use WCPay\Database_Cache; use WCPay\Logger; @@ -1392,8 +1393,8 @@ private function simulate_client_currency() { $countries = WC_Payments_Utils::supported_countries(); $predefined_simulation_currencies = [ - 'USD' => $countries['US'], - 'GBP' => $countries['GB'], + 'USD' => $countries[ Country_Code::UNITED_STATES ], + 'GBP' => $countries[ Country_Code::UNITED_KINGDOM ], ]; $simulation_currency = 'USD' === get_option( 'woocommerce_currency', 'USD' ) ? 'GBP' : 'USD'; diff --git a/includes/payment-methods/class-affirm-payment-method.php b/includes/payment-methods/class-affirm-payment-method.php index 68c4f785ddd..4be64bf653d 100644 --- a/includes/payment-methods/class-affirm-payment-method.php +++ b/includes/payment-methods/class-affirm-payment-method.php @@ -9,6 +9,7 @@ use WC_Payments_Token_Service; use WC_Payments_Utils; +use WCPay\Constants\Country_Code; use WCPay\MultiCurrency\MultiCurrency; /** @@ -33,19 +34,19 @@ public function __construct( $token_service ) { $this->accept_only_domestic_payment = true; $this->limits_per_currency = [ 'CAD' => [ - 'CA' => [ + Country_Code::CANADA => [ 'min' => 5000, 'max' => 3000000, ], // Represents CAD 50 - 30,000 CAD. ], 'USD' => [ - 'US' => [ + Country_Code::UNITED_STATES => [ 'min' => 5000, 'max' => 3000000, ], // Represents USD 50 - 30,000 USD. ], ]; - $this->countries = [ 'US', 'CA' ]; + $this->countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA ]; } /** diff --git a/includes/payment-methods/class-afterpay-payment-method.php b/includes/payment-methods/class-afterpay-payment-method.php index 628ca444075..9984ae212b7 100644 --- a/includes/payment-methods/class-afterpay-payment-method.php +++ b/includes/payment-methods/class-afterpay-payment-method.php @@ -9,6 +9,7 @@ use WC_Payments_Token_Service; use WC_Payments_Utils; +use WCPay\Constants\Country_Code; /** * Afterpay Payment Method class extending UPE base class @@ -32,31 +33,31 @@ public function __construct( $token_service ) { $this->accept_only_domestic_payment = true; $this->limits_per_currency = [ 'AUD' => [ - 'AU' => [ + Country_Code::AUSTRALIA => [ 'min' => 100, 'max' => 200000, ], // Represents AUD 1 - 2,000 AUD. ], 'CAD' => [ - 'CA' => [ + Country_Code::CANADA => [ 'min' => 100, 'max' => 200000, ], // Represents CAD 1 - 2,000 CAD. ], 'NZD' => [ - 'NZ' => [ + Country_Code::NEW_ZEALAND => [ 'min' => 100, 'max' => 200000, ], // Represents NZD 1 - 2,000 NZD. ], 'GBP' => [ - 'GB' => [ + Country_Code::UNITED_KINGDOM => [ 'min' => 100, 'max' => 120000, ], // Represents GBP 1 - 1,200 GBP. ], 'USD' => [ - 'US' => [ + Country_Code::UNITED_STATES => [ 'min' => 100, 'max' => 400000, ], // Represents USD 1 - 4,000 USD. diff --git a/includes/payment-methods/class-klarna-payment-method.php b/includes/payment-methods/class-klarna-payment-method.php index 0300a2dfd74..9127cd16d48 100644 --- a/includes/payment-methods/class-klarna-payment-method.php +++ b/includes/payment-methods/class-klarna-payment-method.php @@ -9,6 +9,7 @@ use WC_Payments_Token_Service; use WC_Payments_Utils; +use WCPay\Constants\Country_Code; use WCPay\MultiCurrency\MultiCurrency; /** @@ -31,68 +32,68 @@ public function __construct( $token_service ) { $this->icon_url = plugins_url( 'assets/images/payment-methods/klarna.svg', WCPAY_PLUGIN_FILE ); $this->currencies = [ 'USD', 'GBP', 'EUR', 'DKK', 'NOK', 'SEK' ]; $this->accept_only_domestic_payment = true; - $this->countries = [ 'US', 'GB', 'AT', 'DE', 'NL', 'BE', 'ES', 'IT', 'IE', 'DK', 'FI', 'NO', 'SE' ]; + $this->countries = [ Country_Code::UNITED_STATES, Country_Code::UNITED_KINGDOM, Country_Code::AUSTRIA, Country_Code::GERMANY, Country_Code::NETHERLANDS, Country_Code::BELGIUM, Country_Code::SPAIN, Country_Code::ITALY, Country_Code::IRELAND, Country_Code::DENMARK, Country_Code::FINLAND, Country_Code::NORWAY, Country_Code::SWEDEN ]; $this->limits_per_currency = [ 'USD' => [ - 'US' => [ + Country_Code::UNITED_STATES => [ 'min' => 0, 'max' => 1000000, ], ], 'GBP' => [ - 'GB' => [ + Country_Code::UNITED_KINGDOM => [ 'min' => 0, 'max' => 1150000, ], ], 'EUR' => [ - 'AT' => [ + Country_Code::AUSTRIA => [ 'min' => 1, 'max' => 1000000, ], - 'BE' => [ + Country_Code::BELGIUM => [ 'min' => 1, 'max' => 1000000, ], - 'DE' => [ + Country_Code::GERMANY => [ 'min' => 1, 'max' => 1000000, ], - 'NL' => [ + Country_Code::NETHERLANDS => [ 'min' => 1, 'max' => 1500000, ], - 'FI' => [ + Country_Code::FINLAND => [ 'min' => 0, 'max' => 1000000, ], - 'ES' => [ + Country_Code::SPAIN => [ 'min' => 0, 'max' => 1000000, ], - 'IE' => [ + Country_Code::IRELAND => [ 'min' => 0, 'max' => 400000, ], - 'IT' => [ + Country_Code::ITALY => [ 'min' => 0, 'max' => 1000000, ], ], 'DKK' => [ - 'DK' => [ + Country_Code::DENMARK => [ 'min' => 100, 'max' => 100000000, ], ], 'NOK' => [ - 'NO' => [ + Country_Code::NORWAY => [ 'min' => 0, 'max' => 100000000, ], ], 'SEK' => [ - 'SE' => [ + Country_Code::SWEDEN => [ 'min' => 0, 'max' => 15000000, ], diff --git a/tests/unit/admin/tasks/test-class-wc-payments-task-disputes.php b/tests/unit/admin/tasks/test-class-wc-payments-task-disputes.php index ff5971fdc49..2774d3e1b04 100644 --- a/tests/unit/admin/tasks/test-class-wc-payments-task-disputes.php +++ b/tests/unit/admin/tasks/test-class-wc-payments-task-disputes.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WooCommerce\Payments\Tasks\WC_Payments_Task_Disputes; /** @@ -45,7 +46,7 @@ public function test_disputes_task_with_single_dispute_outside_7days() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+9 days' ) ), @@ -72,7 +73,7 @@ public function test_disputes_task_with_single_dispute_within_7days() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+6 days' ) ), @@ -104,7 +105,7 @@ public function test_disputes_task_with_single_dispute_within_24h() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+23 hours' ) ), @@ -136,7 +137,7 @@ public function test_disputes_task_with_multiple_disputes_within_7days() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+6 days' ) ), @@ -153,7 +154,7 @@ public function test_disputes_task_with_multiple_disputes_within_7days() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'warning_needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+3 days' ) ), @@ -183,7 +184,7 @@ public function test_disputes_task_with_multiple_disputes_within_24h() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+23 hours' ) ), @@ -200,7 +201,7 @@ public function test_disputes_task_with_multiple_disputes_within_24h() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'warning_needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+23 hours' ) ), @@ -217,7 +218,7 @@ public function test_disputes_task_with_multiple_disputes_within_24h() { 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'warning_needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+9 days' ) ), @@ -247,7 +248,7 @@ public function test_disputes_task_with_multiple_disputes_within_7days_multicurr 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+6 days' ) ), @@ -264,7 +265,7 @@ public function test_disputes_task_with_multiple_disputes_within_7days_multicurr 'order_number' => 14, 'customer_name' => 'customer', 'customer_email' => 'email@email.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'status' => 'warning_needs_response', 'created' => gmdate( 'Y-m-d H:i:s', strtotime( '-14 days' ) ), 'due_by' => gmdate( 'Y-m-d H:i:s', strtotime( '+3 days' ) ), diff --git a/tests/unit/admin/test-class-wc-rest-payments-accounts-controller.php b/tests/unit/admin/test-class-wc-rest-payments-accounts-controller.php index 7b5886e6eed..42560d5da90 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-accounts-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-accounts-controller.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Core\Server\Request\Get_Account; use WCPay\Core\Server\Response; use WCPay\Exceptions\API_Exception; @@ -76,7 +77,7 @@ public function test_get_account_data_with_connected_account() { new Response( [ 'is_live' => true, - 'country' => 'DE', + 'country' => Country_Code::GERMANY, 'status' => 'complete', 'store_currencies' => [ 'default' => 'EUR' ], ] @@ -89,7 +90,7 @@ public function test_get_account_data_with_connected_account() { $this->assertSame( 200, $response->status ); $this->assertTrue( $response_data['test_mode'] ); $this->assertSame( 'complete', $response_data['status'] ); - $this->assertSame( 'DE', $response_data['country'] ); + $this->assertSame( Country_Code::GERMANY, $response_data['country'] ); $this->assertSame( 'EUR', $response_data['store_currencies']['default'] ); } @@ -114,7 +115,7 @@ public function test_get_account_data_without_connected_account_and_enabled_onbo $this->assertTrue( $response_data['test_mode'] ); $this->assertSame( 'NOACCOUNT', $response_data['status'] ); // The default country and currency have changed in WC 5.3, hence multiple options in assertions. - $this->assertContains( $response_data['country'], [ 'US', 'GB' ] ); + $this->assertContains( $response_data['country'], [ Country_Code::UNITED_STATES, Country_Code::UNITED_KINGDOM ] ); $this->assertContains( $response_data['store_currencies']['default'], [ 'USD', 'GBP' ] ); } @@ -138,7 +139,7 @@ public function test_get_account_data_without_connected_account_and_disabled_onb $this->assertTrue( $response_data['test_mode'] ); $this->assertSame( 'ONBOARDING_DISABLED', $response_data['status'] ); // The default country and currency have changed in WC 5.3, hence multiple options in assertions. - $this->assertContains( $response_data['country'], [ 'US', 'GB' ] ); + $this->assertContains( $response_data['country'], [ Country_Code::UNITED_STATES, Country_Code::UNITED_KINGDOM ] ); $this->assertContains( $response_data['store_currencies']['default'], [ 'USD', 'GBP' ] ); } diff --git a/tests/unit/admin/test-class-wc-rest-payments-customer-controller.php b/tests/unit/admin/test-class-wc-rest-payments-customer-controller.php index 11b9eb84669..0ab08a25597 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-customer-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-customer-controller.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; /** * WC_REST_Payments_Customer_Controller_Test unit tests. @@ -55,7 +56,7 @@ public function test_get_customer_payment_methods_endpoint_will_return_correct_r 'address_postal_code_check' => 'unchecked', 'cvc_check' => 'pass', ], - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'exp_month' => 11, 'exp_year' => 2030, 'fingerprint' => 'RSTUvWXZa1b2c3Y4', @@ -105,7 +106,7 @@ private function get_base_payment_method_data() { 'billing_details' => [ 'address' => [ 'city' => 'Los Angeles', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'line1' => '123 Sunset Blvd', 'line2' => 'Apt 456', 'postal_code' => '90028', diff --git a/tests/unit/admin/test-class-wc-rest-payments-onboarding-controller.php b/tests/unit/admin/test-class-wc-rest-payments-onboarding-controller.php index 7fd44cfa063..ee220f5b43c 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-onboarding-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-onboarding-controller.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; /** * WC_REST_Payments_Onboarding_Controller unit tests. @@ -105,7 +106,7 @@ public function test_get_required_verification_information() { $request = new WP_REST_Request( 'GET' ); $request->set_url_params( [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'type' => 'company', 'structure' => 'sole_proprietor', ] @@ -131,7 +132,7 @@ public function test_get_progressive_onboarding_eligible() { $request->set_body_params( [ 'business' => [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'type' => 'company', 'mcc' => 'most_popular__software_services', ], @@ -170,7 +171,7 @@ public function test_get_progressive_onboarding_not_eligible() { [ 'business' => [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'type' => 'company', 'mcc' => 'most_popular__software_services', ], diff --git a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php index 8c1628a9f91..0f8714c6b6b 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php @@ -8,6 +8,7 @@ use Automattic\WooCommerce\Blocks\Package; use Automattic\WooCommerce\Blocks\RestApi; use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Constants\Payment_Method; use WCPay\Database_Cache; use WCPay\Duplicate_Payment_Prevention_Service; @@ -741,7 +742,7 @@ public function account_business_support_address_validation_provider() { [ [ 'city' => 'test city', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], $request, 'account_business_support_address', diff --git a/tests/unit/contants/test-class-country-code.php b/tests/unit/contants/test-class-country-code.php new file mode 100644 index 00000000000..bf3f67a2ecf --- /dev/null +++ b/tests/unit/contants/test-class-country-code.php @@ -0,0 +1,67 @@ +assertEquals( 'AU', Country_Code::AUSTRALIA ); + $this->assertEquals( 'AT', Country_Code::AUSTRIA ); + $this->assertEquals( 'BE', Country_Code::BELGIUM ); + $this->assertEquals( 'BR', Country_Code::BRAZIL ); + $this->assertEquals( 'BG', Country_Code::BULGARIA ); + $this->assertEquals( 'CA', Country_Code::CANADA ); + $this->assertEquals( 'HR', Country_Code::CROATIA ); + $this->assertEquals( 'CY', Country_Code::CYPRUS ); + $this->assertEquals( 'CZ', Country_Code::CZECHIA ); + $this->assertEquals( 'DK', Country_Code::DENMARK ); + $this->assertEquals( 'EE', Country_Code::ESTONIA ); + $this->assertEquals( 'FI', Country_Code::FINLAND ); + $this->assertEquals( 'FR', Country_Code::FRANCE ); + $this->assertEquals( 'DE', Country_Code::GERMANY ); + $this->assertEquals( 'GH', Country_Code::GHANA ); + $this->assertEquals( 'GI', Country_Code::GIBRALTAR ); + $this->assertEquals( 'GR', Country_Code::GREECE ); + $this->assertEquals( 'HK', Country_Code::HONG_KONG ); + $this->assertEquals( 'HU', Country_Code::HUNGARY ); + $this->assertEquals( 'IN', Country_Code::INDIA ); + $this->assertEquals( 'ID', Country_Code::INDONESIA ); + $this->assertEquals( 'IE', Country_Code::IRELAND ); + $this->assertEquals( 'IT', Country_Code::ITALY ); + $this->assertEquals( 'JP', Country_Code::JAPAN ); + $this->assertEquals( 'KE', Country_Code::KENYA ); + $this->assertEquals( 'LV', Country_Code::LATVIA ); + $this->assertEquals( 'LI', Country_Code::LIECHTENSTEIN ); + $this->assertEquals( 'LT', Country_Code::LITHUANIA ); + $this->assertEquals( 'LU', Country_Code::LUXEMBOURG ); + $this->assertEquals( 'MY', Country_Code::MALAYSIA ); + $this->assertEquals( 'MT', Country_Code::MALTA ); + $this->assertEquals( 'MX', Country_Code::MEXICO ); + $this->assertEquals( 'NL', Country_Code::NETHERLANDS ); + $this->assertEquals( 'NZ', Country_Code::NEW_ZEALAND ); + $this->assertEquals( 'NG', Country_Code::NIGERIA ); + $this->assertEquals( 'NO', Country_Code::NORWAY ); + $this->assertEquals( 'PL', Country_Code::POLAND ); + $this->assertEquals( 'PT', Country_Code::PORTUGAL ); + $this->assertEquals( 'RO', Country_Code::ROMANIA ); + $this->assertEquals( 'SG', Country_Code::SINGAPORE ); + $this->assertEquals( 'SK', Country_Code::SLOVAKIA ); + $this->assertEquals( 'SI', Country_Code::SLOVENIA ); + $this->assertEquals( 'ZA', Country_Code::SOUTH_AFRICA ); + $this->assertEquals( 'ES', Country_Code::SPAIN ); + $this->assertEquals( 'SE', Country_Code::SWEDEN ); + $this->assertEquals( 'CH', Country_Code::SWITZERLAND ); + $this->assertEquals( 'TH', Country_Code::THAILAND ); + $this->assertEquals( 'AE', Country_Code::UNITED_ARAB_EMIRATES ); + $this->assertEquals( 'GB', Country_Code::UNITED_KINGDOM ); + $this->assertEquals( 'US', Country_Code::UNITED_STATES ); + } +} diff --git a/tests/unit/core/server/request/test-class-list-transactions-request.php b/tests/unit/core/server/request/test-class-list-transactions-request.php index 0d932deafcf..899e87ea4df 100644 --- a/tests/unit/core/server/request/test-class-list-transactions-request.php +++ b/tests/unit/core/server/request/test-class-list-transactions-request.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Core\Exceptions\Server\Request\Invalid_Request_Parameter_Exception; use WCPay\Core\Server\Request\List_Transactions; @@ -70,8 +71,8 @@ public function test_list_transactions_request_will_be_date() { $device_is_not = 'android'; $channel = 'online'; $channel_is_not = 'in_person'; - $country = 'US'; - $country_is_not = 'CA'; + $country = Country_Code::UNITED_STATES; + $country_is_not = Country_Code::CANADA; $risk_level = '0'; $risk_level_is_not = '1'; $search = [ 'search' ]; @@ -151,8 +152,8 @@ public function test_list_transactions_request_will_be_date_using_from_rest_requ $device_is_not = 'android'; $channel = 'online'; $channel_is_not = 'in_person'; - $country = 'US'; - $country_is_not = 'CA'; + $country = Country_Code::UNITED_STATES; + $country_is_not = Country_Code::CANADA; $risk_level = '0'; $risk_level_is_not = '1'; $search = [ 'search' ]; diff --git a/tests/unit/core/service/test-class-wc-payments-customer-service-api.php b/tests/unit/core/service/test-class-wc-payments-customer-service-api.php index a1b8847a41e..298549c6873 100644 --- a/tests/unit/core/service/test-class-wc-payments-customer-service-api.php +++ b/tests/unit/core/service/test-class-wc-payments-customer-service-api.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Database_Cache; use WCPay\Exceptions\API_Exception; use WCPay\Core\WC_Payments_Customer_Service_API; @@ -474,7 +475,7 @@ private function get_mock_customer_data() { 'postal_code' => '09876', 'city' => 'City', 'state' => 'State', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'shipping' => [ 'name' => 'Shipping Ship', @@ -484,7 +485,7 @@ private function get_mock_customer_data() { 'postal_code' => '76543', 'city' => 'City2', 'state' => 'State2', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], ], ]; diff --git a/tests/unit/fraud-prevention/test-class-buyer-fingerprinting-service.php b/tests/unit/fraud-prevention/test-class-buyer-fingerprinting-service.php index 271acc2bb9a..327187167e4 100644 --- a/tests/unit/fraud-prevention/test-class-buyer-fingerprinting-service.php +++ b/tests/unit/fraud-prevention/test-class-buyer-fingerprinting-service.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\Fraud_Prevention\Buyer_Fingerprinting_Service; use WCPay\Fraud_Prevention\Fraud_Prevention_Service; @@ -45,7 +46,7 @@ public function test_it_hashes_using_sha512() { public function test_it_hashes_order_info() { $fingerprint = 'abc123'; - $ip_country = 'GB'; + $ip_country = Country_Code::UNITED_KINGDOM; add_filter( 'woocommerce_geolocate_ip', function() use ( $ip_country ) { diff --git a/tests/unit/fraud-prevention/test-class-fraud-risk-tools.php b/tests/unit/fraud-prevention/test-class-fraud-risk-tools.php index 7af9c4b76a1..249e56badd2 100644 --- a/tests/unit/fraud-prevention/test-class-fraud-risk-tools.php +++ b/tests/unit/fraud-prevention/test-class-fraud-risk-tools.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\Fraud_Prevention\Fraud_Risk_Tools; /** @@ -331,7 +332,7 @@ public function test_it_gets_high_protection_empty_allowed_countries_settings() public function test_it_gets_the_correct_for_specific_allowed_selling_locations_type() { update_option( 'woocommerce_allowed_countries', 'specific' ); - update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] ); + update_option( 'woocommerce_specific_allowed_countries', [ Country_Code::UNITED_STATES, Country_Code::CANADA ] ); $settings = $this->fraud_risk_tools->get_standard_protection_settings(); @@ -340,7 +341,7 @@ public function test_it_gets_the_correct_for_specific_allowed_selling_locations_ public function test_it_gets_the_correct_for_all_except_selling_locations_type() { update_option( 'woocommerce_allowed_countries', 'all_except' ); - update_option( 'woocommerce_all_except_countries', [ 'US', 'CA' ] ); + update_option( 'woocommerce_all_except_countries', [ Country_Code::UNITED_STATES, Country_Code::CANADA ] ); $settings = $this->fraud_risk_tools->get_standard_protection_settings(); diff --git a/tests/unit/helpers/class-wc-helper-order.php b/tests/unit/helpers/class-wc-helper-order.php index 93499fb901f..f7f02e23d74 100644 --- a/tests/unit/helpers/class-wc-helper-order.php +++ b/tests/unit/helpers/class-wc-helper-order.php @@ -5,6 +5,7 @@ * @package WooCommerce/Tests */ +use WCPay\Constants\Country_Code; use WCPay\Constants\Order_Status; /** @@ -96,7 +97,7 @@ public static function create_order( $customer_id = 1, $total = 50, $product = n $order->set_billing_city( 'WooCity' ); $order->set_billing_state( 'NY' ); $order->set_billing_postcode( '12345' ); - $order->set_billing_country( 'US' ); + $order->set_billing_country( Country_Code::UNITED_STATES ); $order->set_billing_email( 'admin@example.org' ); $order->set_billing_phone( '555-32123' ); diff --git a/tests/unit/migrations/test-class-update-service-data-from-server.php b/tests/unit/migrations/test-class-update-service-data-from-server.php index 998fcb39dc3..b7a7ca0c7f4 100644 --- a/tests/unit/migrations/test-class-update-service-data-from-server.php +++ b/tests/unit/migrations/test-class-update-service-data-from-server.php @@ -8,6 +8,7 @@ namespace WCPay\Migrations; use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPAY_UnitTestCase; /** @@ -74,7 +75,7 @@ public function test_does_nothing_if_account_data_contains_giropay_fees() { 'discount' => [], ], ], - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ] ) ); @@ -106,7 +107,7 @@ public function test_updates_service_data_if_account_data_does_not_contain_girop 'discount' => [], ], ], - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ] ) ); diff --git a/tests/unit/multi-currency/test-class-country-flags.php b/tests/unit/multi-currency/test-class-country-flags.php index cd3adff8feb..0ebe63fb8ef 100644 --- a/tests/unit/multi-currency/test-class-country-flags.php +++ b/tests/unit/multi-currency/test-class-country-flags.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\MultiCurrency\CountryFlags; /** @@ -12,7 +13,7 @@ */ class Country_Flags_Test extends WCPAY_UnitTestCase { public function test_get_by_country_returns_emoji_flag() { - $this->assertEquals( CountryFlags::get_by_country( 'US' ), '🇺🇸' ); + $this->assertEquals( CountryFlags::get_by_country( Country_Code::UNITED_STATES ), '🇺🇸' ); } public function test_get_by_country_returns_empty_string() { diff --git a/tests/unit/multi-currency/test-class-frontend-prices.php b/tests/unit/multi-currency/test-class-frontend-prices.php index db34cc1b40d..8c76d8a8ec4 100644 --- a/tests/unit/multi-currency/test-class-frontend-prices.php +++ b/tests/unit/multi-currency/test-class-frontend-prices.php @@ -5,6 +5,8 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; + /** * WCPay\MultiCurrency\FrontendPrices unit tests. */ @@ -206,7 +208,7 @@ function() { ); WC()->session->init(); - WC()->customer->set_location( 'US', 'CA' ); + WC()->customer->set_location( Country_Code::UNITED_STATES, 'CA' ); $shipping_method = new \WC_Shipping_Flat_Rate(); $shipping_method->tax_status = 'taxable'; @@ -250,7 +252,7 @@ function() { ); WC()->session->init(); - WC()->customer->set_location( 'US', 'CA' ); + WC()->customer->set_location( Country_Code::UNITED_STATES, 'CA' ); $shipping_method = new \WC_Shipping_Flat_Rate(); $shipping_method->tax_status = 'taxable'; diff --git a/tests/unit/multi-currency/test-class-geolocation.php b/tests/unit/multi-currency/test-class-geolocation.php index 0c663f17fcf..386787f6a3c 100644 --- a/tests/unit/multi-currency/test-class-geolocation.php +++ b/tests/unit/multi-currency/test-class-geolocation.php @@ -5,6 +5,8 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; + /** * WCPay\MultiCurrency\Geolocation unit tests. */ @@ -37,10 +39,10 @@ public function test_get_country_by_customer_location_returns_geolocation_countr add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); - $this->assertSame( 'CA', $this->geolocation->get_country_by_customer_location() ); + $this->assertSame( Country_Code::CANADA, $this->geolocation->get_country_by_customer_location() ); } public function test_get_country_by_customer_location_returns_default_country_when_no_geolocation() { @@ -54,20 +56,20 @@ function() { add_filter( 'woocommerce_customer_default_location', function() { - return 'BR'; + return Country_Code::BRAZIL; } ); - $this->assertSame( 'BR', $this->geolocation->get_country_by_customer_location() ); + $this->assertSame( Country_Code::BRAZIL, $this->geolocation->get_country_by_customer_location() ); } public function test_get_currency_by_customer_location_returns_geolocation_currency_code() { - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'CA' )->willReturn( [ 'currency_code' => 'CAD' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::CANADA )->willReturn( [ 'currency_code' => 'CAD' ] ); add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); @@ -75,7 +77,7 @@ function() { } public function test_get_currency_by_customer_location_returns_default_currency_code() { - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'BR' )->willReturn( [ 'currency_code' => 'BRL' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::BRAZIL )->willReturn( [ 'currency_code' => 'BRL' ] ); add_filter( 'woocommerce_geolocate_ip', @@ -86,7 +88,7 @@ function() { add_filter( 'woocommerce_customer_default_location', function() { - return 'BR'; + return Country_Code::BRAZIL; } ); diff --git a/tests/unit/multi-currency/test-class-multi-currency.php b/tests/unit/multi-currency/test-class-multi-currency.php index e5a360e2f5a..a6964e951ad 100644 --- a/tests/unit/multi-currency/test-class-multi-currency.php +++ b/tests/unit/multi-currency/test-class-multi-currency.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\MultiCurrency\Utils; use WCPay\Database_Cache; use WCPay\MultiCurrency\Exceptions\InvalidCurrencyException; @@ -451,11 +452,11 @@ function() { public function test_update_selected_currency_by_geolocation_does_not_set_session_cookie() { update_option( 'wcpay_multi_currency_enable_auto_currency', 'yes' ); - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'CA' )->willReturn( [ 'currency_code' => 'CAD' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::CANADA )->willReturn( [ 'currency_code' => 'CAD' ] ); add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); @@ -472,11 +473,11 @@ public function test_update_selected_currency_by_geolocation_updates_session_whe add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'CA' )->willReturn( [ 'currency_code' => 'CAD' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::CANADA )->willReturn( [ 'currency_code' => 'CAD' ] ); $this->multi_currency->update_selected_currency_by_geolocation(); @@ -489,11 +490,11 @@ public function test_update_selected_currency_by_geolocation_displays_notice() { add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'CA' )->willReturn( [ 'currency_code' => 'CAD' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::CANADA )->willReturn( [ 'currency_code' => 'CAD' ] ); $this->multi_currency->update_selected_currency_by_geolocation(); @@ -512,14 +513,14 @@ public function test_update_selected_currency_by_geolocation_does_not_update_if_ add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); // Arrange: Set the expected calls and retruns for our mock classes. $this->mock_localization_service ->method( 'get_country_locale_data' ) - ->with( 'CA' ) + ->with( Country_Code::CANADA ) ->willReturn( [ 'currency_code' => 'CAD' ] ); $this->mock_utils @@ -542,11 +543,11 @@ public function test_display_geolocation_currency_update_notice() { add_filter( 'woocommerce_geolocate_ip', function() { - return 'CA'; + return Country_Code::CANADA; } ); - $this->mock_localization_service->method( 'get_country_locale_data' )->with( 'CA' )->willReturn( [ 'currency_code' => 'CAD' ] ); + $this->mock_localization_service->method( 'get_country_locale_data' )->with( Country_Code::CANADA )->willReturn( [ 'currency_code' => 'CAD' ] ); $this->multi_currency->display_geolocation_currency_update_notice(); @@ -554,11 +555,11 @@ function() { } public function test_display_geolocation_currency_update_notice_does_not_display_if_using_default_currency() { - WC()->session->set( WCPay\MultiCurrency\MultiCurrency::CURRENCY_SESSION_KEY, 'US' ); + WC()->session->set( WCPay\MultiCurrency\MultiCurrency::CURRENCY_SESSION_KEY, Country_Code::UNITED_STATES ); add_filter( 'woocommerce_geolocate_ip', function() { - return 'US'; + return Country_Code::UNITED_STATES; } ); @@ -572,7 +573,7 @@ public function test_display_geolocation_currency_update_notice_does_not_display add_filter( 'woocommerce_geolocate_ip', function() { - return 'US'; + return Country_Code::UNITED_STATES; } ); diff --git a/tests/unit/reports/test-class-wc-rest-payments-reports-authorizations-controller.php b/tests/unit/reports/test-class-wc-rest-payments-reports-authorizations-controller.php index 58f7bc1acaf..302ec1efadd 100644 --- a/tests/unit/reports/test-class-wc-rest-payments-reports-authorizations-controller.php +++ b/tests/unit/reports/test-class-wc-rest-payments-reports-authorizations-controller.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Exceptions\Connection_Exception; use WCPay\Core\Server\Request\List_Authorizations; @@ -196,7 +197,7 @@ private function get_authorizations_list_from_server() { 'source_identifier' => '4242', 'customer_name' => 'Test One', 'customer_email' => 'test1@woo.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'fees' => 312, 'currency' => 'eur', 'risk_level' => 0, @@ -221,7 +222,7 @@ private function get_authorizations_list_from_server() { 'source_identifier' => '4242', 'customer_name' => 'Test Two', 'customer_email' => 'test2@woo.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'fees' => 98, 'currency' => 'eur', 'risk_level' => 0, @@ -246,7 +247,7 @@ private function get_authorizations_list_from_server() { 'source_identifier' => '4242', 'customer_name' => 'Test One', 'customer_email' => 'test1@woo.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'fees' => 312, 'currency' => 'eur', 'risk_level' => 0, @@ -277,7 +278,7 @@ private function get_authorizations_list() { 'customer' => [ 'name' => 'Test One', 'email' => 'test1@woo.com', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'net_amount' => 6988, 'order_id' => 123, @@ -298,7 +299,7 @@ private function get_authorizations_list() { 'customer' => [ 'name' => 'Test Two', 'email' => 'test2@woo.com', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'net_amount' => 1702, 'order_id' => 456, @@ -319,7 +320,7 @@ private function get_authorizations_list() { 'customer' => [ 'name' => 'Test One', 'email' => 'test1@woo.com', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'net_amount' => 6988, 'order_id' => 789, diff --git a/tests/unit/reports/test-class-wc-rest-payments-reports-transactions-controller.php b/tests/unit/reports/test-class-wc-rest-payments-reports-transactions-controller.php index aefee308132..46c2b21452c 100644 --- a/tests/unit/reports/test-class-wc-rest-payments-reports-transactions-controller.php +++ b/tests/unit/reports/test-class-wc-rest-payments-reports-transactions-controller.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Exceptions\Connection_Exception; use WCPay\Core\Server\Request\List_Transactions; @@ -200,7 +201,7 @@ private function get_transactions_list_from_server() { 'source_identifier' => '3184', 'customer_name' => 'Test Customer1', 'customer_email' => 'test1@woo.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'amount' => 2583, 'net' => 2426, 'fees' => 157, @@ -233,7 +234,7 @@ private function get_transactions_list_from_server() { 'source_identifier' => '3184', 'customer_name' => 'Test Customer2', 'customer_email' => 'test2@woo.com', - 'customer_country' => 'US', + 'customer_country' => Country_Code::UNITED_STATES, 'amount' => 2583, 'net' => 2452, 'fees' => 131, @@ -282,7 +283,7 @@ private function get_transactions_list() { 'customer' => [ 'name' => 'Test Customer1', 'email' => 'test1@woo.com', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'net_amount' => 2426, 'order_id' => 123, @@ -308,7 +309,7 @@ private function get_transactions_list() { 'customer' => [ 'name' => 'Test Customer2', 'email' => 'test2@woo.com', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'net_amount' => 2452, 'order_id' => 275, diff --git a/tests/unit/src/Internal/Service/Level3ServiceTest.php b/tests/unit/src/Internal/Service/Level3ServiceTest.php index 553c54f862c..5911201c99b 100644 --- a/tests/unit/src/Internal/Service/Level3ServiceTest.php +++ b/tests/unit/src/Internal/Service/Level3ServiceTest.php @@ -12,6 +12,7 @@ use WC_Order; use WC_Order_Item_Product; use WC_Order_Item_Fee; +use WCPay\Constants\Country_Code; use WCPAY_UnitTestCase; use WC_Payments_Account; use WCPay\Internal\Service\Level3Service; @@ -235,7 +236,7 @@ public function test_full_level3_data() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', false, false, 1, 1, 30, true ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -266,7 +267,7 @@ public function test_full_level3_data_with_product_id_longer_than_12_characters( ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', false, false, 1, 1, 123456789123456 ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -305,7 +306,7 @@ public function test_full_level3_data_with_fee() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', true ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -344,7 +345,7 @@ public function test_full_level3_data_with_negative_price_product() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', false, true, 1, 1 ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -353,7 +354,7 @@ public function test_full_level3_data_with_negative_price_product() { public function test_us_store_level_3_data() { // Use a non-us customer postcode to ensure it's not included in the level3 data. - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '9000' ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -384,7 +385,7 @@ public function test_us_customer_level_3_data() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '9000' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012' ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -394,7 +395,7 @@ public function test_us_customer_level_3_data() { public function test_non_us_customer_level_3_data() { $expected_data = []; - $this->mock_account->method( 'get_account_country' )->willReturn( 'CA' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::CANADA ); $this->mock_level_3_order( 'K0A' ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -425,7 +426,7 @@ public function test_full_level3_data_with_float_quantity() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', false, false, 3.7 ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -456,7 +457,7 @@ public function test_full_level3_data_with_float_quantity_zero() { ->with( 'get_option', 'woocommerce_store_postcode' ) ->willReturn( '94110' ); - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', false, false, 0.4 ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); @@ -505,7 +506,7 @@ public function test_level3_data_bundle() { } public function test_level3_data_bundle_for_orders_with_more_than_200_items() { - $this->mock_account->method( 'get_account_country' )->willReturn( 'US' ); + $this->mock_account->method( 'get_account_country' )->willReturn( Country_Code::UNITED_STATES ); $this->mock_level_3_order( '98012', true, false, 1, 500 ); $level_3_data = $this->sut->get_data_from_order( $this->order_id ); diff --git a/tests/unit/test-class-wc-payments-customer-service.php b/tests/unit/test-class-wc-payments-customer-service.php index 4260bf25d40..5d7c14fc34b 100644 --- a/tests/unit/test-class-wc-payments-customer-service.php +++ b/tests/unit/test-class-wc-payments-customer-service.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Database_Cache; use WCPay\Exceptions\API_Exception; @@ -485,7 +486,7 @@ public function test_update_payment_method_with_billing_details_from_order() { 'billing_details' => [ 'address' => [ 'city' => 'WooCity', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'line1' => 'WooAddress', 'postal_code' => '12345', 'state' => 'NY', @@ -589,7 +590,7 @@ private function get_mock_wc_object_for_customer_data( $object_class, $mock_retu 'get_billing_postcode' => '09876', 'get_billing_city' => 'City', 'get_billing_state' => 'State', - 'get_billing_country' => 'US', + 'get_billing_country' => Country_Code::UNITED_STATES, 'get_shipping_first_name' => 'Shipping', 'get_shipping_last_name' => 'Ship', 'get_shipping_address_1' => '2 Street St', @@ -597,7 +598,7 @@ private function get_mock_wc_object_for_customer_data( $object_class, $mock_retu 'get_shipping_postcode' => '76543', 'get_shipping_city' => 'City2', 'get_shipping_state' => 'State2', - 'get_shipping_country' => 'US', + 'get_shipping_country' => Country_Code::UNITED_STATES, ], $mock_return_overrides ); @@ -622,7 +623,7 @@ private function get_mock_customer_data( $overrides = [] ) { 'postal_code' => '09876', 'city' => 'City', 'state' => 'State', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], 'shipping' => [ 'name' => 'Shipping Ship', @@ -632,7 +633,7 @@ private function get_mock_customer_data( $overrides = [] ) { 'postal_code' => '76543', 'city' => 'City2', 'state' => 'State2', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], ], ], @@ -670,7 +671,7 @@ public function test_get_customer_id_for_order() { 'postal_code' => '12345', 'city' => 'WooCity', 'state' => 'NY', - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ], ]; diff --git a/tests/unit/test-class-wc-payments-incentives-service.php b/tests/unit/test-class-wc-payments-incentives-service.php index 0cbaa3b4ae8..4884198caaa 100644 --- a/tests/unit/test-class-wc-payments-incentives-service.php +++ b/tests/unit/test-class-wc-payments-incentives-service.php @@ -261,7 +261,7 @@ function() use ( $response ) { 'tc_url' => 'incentive_tc_url', ], // This is the hash of the test store context: - // 'country' => 'US', + // 'country' => Country_Code::UNITED_STATES, // 'locale' => 'en_US', // 'has_orders' => false, // 'has_payments' => false, diff --git a/tests/unit/test-class-wc-payments-localization-service.php b/tests/unit/test-class-wc-payments-localization-service.php index c002d6cc8a4..32be4fc17fd 100644 --- a/tests/unit/test-class-wc-payments-localization-service.php +++ b/tests/unit/test-class-wc-payments-localization-service.php @@ -5,6 +5,8 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; + /** * WC_Payments_Localization_Service_Test unit tests. */ @@ -156,7 +158,7 @@ public function test_get_country_locale_data() { ], ], ], - $this->localization_service->get_country_locale_data( 'BR' ) + $this->localization_service->get_country_locale_data( Country_Code::BRAZIL ) ); } diff --git a/tests/unit/test-class-wc-payments-onboarding-service.php b/tests/unit/test-class-wc-payments-onboarding-service.php index 8cb3f11ac99..982a363cb92 100644 --- a/tests/unit/test-class-wc-payments-onboarding-service.php +++ b/tests/unit/test-class-wc-payments-onboarding-service.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Constants\Country_Code; use WCPay\Database_Cache; /** @@ -40,7 +41,7 @@ class WC_Payments_Onboarding_Service_Test extends WCPAY_UnitTestCase { */ private $mock_business_types = [ [ - 'key' => 'US', + 'key' => Country_Code::UNITED_STATES, 'name' => 'United States (US)', 'types' => [ [ @@ -146,12 +147,12 @@ public function test_get_required_verification_information() { $this->mock_api_client ->expects( $this->once() ) ->method( 'get_onboarding_required_verification_information' ) - ->with( 'US', 'company', 'sole_propietorship' ) + ->with( Country_Code::UNITED_STATES, 'company', 'sole_propietorship' ) ->willReturn( $mock_requirements ); $this->assertEquals( $mock_requirements, - $this->onboarding_service->get_required_verification_information( 'US', 'company', 'sole_propietorship' ) + $this->onboarding_service->get_required_verification_information( Country_Code::UNITED_STATES, 'company', 'sole_propietorship' ) ); } diff --git a/tests/unit/test-class-wc-payments-payment-request-button-handler.php b/tests/unit/test-class-wc-payments-payment-request-button-handler.php index f4c05dd5a13..c774cf5573f 100644 --- a/tests/unit/test-class-wc-payments-payment-request-button-handler.php +++ b/tests/unit/test-class-wc-payments-payment-request-button-handler.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\Duplicate_Payment_Prevention_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -14,7 +15,7 @@ */ class WC_Payments_Payment_Request_Button_Handler_Test extends WCPAY_UnitTestCase { const SHIPPING_ADDRESS = [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'state' => 'CA', 'postcode' => '94110', 'city' => 'San Francisco', diff --git a/tests/unit/wc-payment-api/models/test-class-wc-payments-api-charge.php b/tests/unit/wc-payment-api/models/test-class-wc-payments-api-charge.php index 5471fbfc5b8..1f06e1dd7bb 100644 --- a/tests/unit/wc-payment-api/models/test-class-wc-payments-api-charge.php +++ b/tests/unit/wc-payment-api/models/test-class-wc-payments-api-charge.php @@ -5,6 +5,8 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; + /** * WC_Payments_API_Charge unit tests. */ @@ -24,7 +26,7 @@ public function test_payments_api_charge_model_serializes_correctly() { 'address_postal_code_check' => null, 'cvc_check' => null, ], - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'exp_month' => 1, 'exp_year' => 2022, 'fingerprint' => 'mock', diff --git a/tests/unit/wc-payment-api/test-class-wc-payments-api-client.php b/tests/unit/wc-payment-api/test-class-wc-payments-api-client.php index b7e9231f5ad..b9b8e5b79ee 100644 --- a/tests/unit/wc-payment-api/test-class-wc-payments-api-client.php +++ b/tests/unit/wc-payment-api/test-class-wc-payments-api-client.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\Constants\Intent_Status; use WCPay\Exceptions\API_Exception; use WCPay\Internal\Logger; @@ -518,7 +519,7 @@ public function test_create_terminal_location_validation_values() { $this->payments_api_client->create_terminal_location( 'Example', [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, ] ); } @@ -527,7 +528,7 @@ public function test_create_terminal_location_success() { $location = [ 'display_name' => 'Example', 'address' => [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'line1' => 'Some Str. 2', ], 'metadata' => [], @@ -917,7 +918,7 @@ public function test_get_onboarding_po_eligible() { $po_eligible = $this->payments_api_client->get_onboarding_po_eligible( [ - 'country' => 'US', + 'country' => Country_Code::UNITED_STATES, 'type' => 'company', 'mcc' => 'most_popular__software_services', ], diff --git a/tests/unit/woopay/class-woopay-scheduler-test.php b/tests/unit/woopay/class-woopay-scheduler-test.php index 05d689527e3..0fa6db45784 100644 --- a/tests/unit/woopay/class-woopay-scheduler-test.php +++ b/tests/unit/woopay/class-woopay-scheduler-test.php @@ -5,6 +5,7 @@ * @package WooCommerce\Payments\Tests */ +use WCPay\Constants\Country_Code; use WCPay\WooPay\WooPay_Scheduler; use WCPay\WooPay\WooPay_Utilities; @@ -198,7 +199,7 @@ public function test_update_adapted_extensions_and_available_countries_list() { 'test-extension', 'test-extension-2', ]; - $available_countries = [ 'US', 'BR' ]; + $available_countries = [ Country_Code::UNITED_STATES, Country_Code::BRAZIL ]; $this->mock_api_response( [], $adapted_extensions, $available_countries );