Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ENUM class for country codes #7925

Merged
merged 24 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
301ed58
Added AF country code
zmaglica Dec 14, 2023
27be666
Replaced more countries
zmaglica Dec 15, 2023
42bdc2a
Replaced countrie that starts with C
zmaglica Dec 15, 2023
0965c78
Replaced countrie that starts with D
zmaglica Dec 15, 2023
fd6c5e8
Replaced countrie that starts with E and F
zmaglica Dec 15, 2023
2ec4363
Replaced countrie that starts with G and H
zmaglica Dec 15, 2023
0e58736
Replaced countrie that starts with I and J
zmaglica Dec 15, 2023
652d515
Replaced countrie that starts with K and L
zmaglica Dec 15, 2023
3185a6f
Replaced countrie that starts with M and N
zmaglica Dec 15, 2023
141083f
Replaced countrie that starts with O and P
zmaglica Dec 15, 2023
f73024a
Replaced countrie that starts with Q, R and S
zmaglica Dec 15, 2023
e8f9bbb
Replaced countrie that starts with T and U
zmaglica Dec 15, 2023
ec1c7ad
Replaced countrie that starts with V and Z
zmaglica Dec 15, 2023
397607d
Added other countries and linting code
zmaglica Dec 15, 2023
e4f34b5
Added changelog
zmaglica Dec 15, 2023
b9ea6ea
Used country codes contants in tests
zmaglica Dec 15, 2023
d3ce810
Refactored name from Country_Codes to Country_Code
zmaglica Jan 8, 2024
69058e8
Merged with latest dev
zmaglica Jan 8, 2024
0942465
Added tests
zmaglica Jan 8, 2024
71264d5
Added HK to tests
zmaglica Jan 8, 2024
b2a392e
Merge branch 'develop' into dev/7886-add-country-codes-enum
zmaglica Jan 9, 2024
9f19f53
Merge branch 'develop' into dev/7886-add-country-codes-enum
naman03malhotra Jan 9, 2024
611d212
Added tests only for stripe supported countries
zmaglica Jan 9, 2024
a8e9f93
Merged with latest dev
zmaglica Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/dev-7886-add-country-codes-enum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Added enum class for country codes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @package WooCommerce\Payments\Admin
*/

use WCPay\Constants\Country_Codes;
use WCPay\Fraud_Prevention\Fraud_Risk_Tools;
use WCPay\Constants\Track_Events;

Expand Down Expand Up @@ -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_Codes::JAPAN === $this->account->get_account_country() ) {
if ( '+81' !== substr( $value, 0, 3 ) ) {
return new WP_Error(
'rest_invalid_pattern',
Expand Down
3 changes: 2 additions & 1 deletion includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
exit; // Exit if accessed directly.
}

use WCPay\Constants\Country_Codes;
use WCPay\Constants\Fraud_Meta_Box_Type;
use WCPay\Constants\Order_Status;
use WCPay\Constants\Payment_Capture_Type;
Expand Down Expand Up @@ -2456,7 +2457,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_Codes::UNITED_STATES ): string {
try {
if ( $this->is_connected() ) {
return $this->account->get_account_country() ?? $default_value;
Expand Down
5 changes: 3 additions & 2 deletions includes/class-wc-payments-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Automattic\WooCommerce\Admin\Notes\DataStore;
use Automattic\WooCommerce\Admin\Notes\Note;
use WCPay\Constants\Country_Codes;
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;
Expand Down Expand Up @@ -277,7 +278,7 @@ public function get_account_status_data() {

return [
'email' => $account['email'] ?? '',
'country' => $account['country'] ?? 'US',
'country' => $account['country'] ?? Country_Codes::UNITED_STATES,
'status' => $account['status'],
'created' => $account['created'] ?? '',
'paymentsEnabled' => $account['payments_enabled'],
Expand Down Expand Up @@ -1786,7 +1787,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_Codes::UNITED_STATES;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package WooCommerce\Payments
*/

use WCPay\Constants\Country_Codes;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down Expand Up @@ -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_Codes::UNITED_STATES === $store_base_location['country'];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
exit;
}

use WCPay\Constants\Country_Codes;
use WCPay\Exceptions\Invalid_Price_Exception;
use WCPay\Fraud_Prevention\Fraud_Prevention_Service;
use WCPay\Logger;
Expand Down Expand Up @@ -444,7 +445,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_Codes::UNITED_KINGDOM === $country ) {
// Replaces a redacted string with something like LN10***.
return str_pad( preg_replace( '/\s+/', '', $postcode ), 7, '*' );
}
Expand Down
77 changes: 39 additions & 38 deletions includes/class-wc-payments-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}

use WCPay\Exceptions\{ Amount_Too_Small_Exception, API_Exception, Connection_Exception };
use WCPay\Constants\Country_Codes;

/**
* WC Payments Utils class
Expand Down Expand Up @@ -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_Codes::UNITED_ARAB_EMIRATES => __( 'United Arab Emirates', 'woocommerce-payments' ),
Country_Codes::AUSTRIA => __( 'Austria', 'woocommerce-payments' ),
Country_Codes::AUSTRALIA => __( 'Australia', 'woocommerce-payments' ),
Country_Codes::BELGIUM => __( 'Belgium', 'woocommerce-payments' ),
Country_Codes::BULGARIA => __( 'Bulgaria', 'woocommerce-payments' ),
Country_Codes::CANADA => __( 'Canada', 'woocommerce-payments' ),
Country_Codes::SWITZERLAND => __( 'Switzerland', 'woocommerce-payments' ),
Country_Codes::CYPRUS => __( 'Cyprus', 'woocommerce-payments' ),
Country_Codes::CZECHIA => __( 'Czech Republic', 'woocommerce-payments' ),
Country_Codes::GERMANY => __( 'Germany', 'woocommerce-payments' ),
Country_Codes::DENMARK => __( 'Denmark', 'woocommerce-payments' ),
Country_Codes::ESTONIA => __( 'Estonia', 'woocommerce-payments' ),
Country_Codes::FINLAND => __( 'Finland', 'woocommerce-payments' ),
Country_Codes::SPAIN => __( 'Spain', 'woocommerce-payments' ),
Country_Codes::FRANCE => __( 'France', 'woocommerce-payments' ),
Country_Codes::CROATIA => __( 'Croatia', 'woocommerce-payments' ),
Country_Codes::JAPAN => __( 'Japan', 'woocommerce-payments' ),
Country_Codes::LUXEMBOURG => __( 'Luxembourg', 'woocommerce-payments' ),
Country_Codes::UNITED_KINGDOM => __( 'United Kingdom (UK)', 'woocommerce-payments' ),
Country_Codes::GREECE => __( 'Greece', 'woocommerce-payments' ),
'HK' => __( 'Hong Kong', 'woocommerce-payments' ),
Country_Codes::HUNGARY => __( 'Hungary', 'woocommerce-payments' ),
Country_Codes::IRELAND => __( 'Ireland', 'woocommerce-payments' ),
Country_Codes::ITALY => __( 'Italy', 'woocommerce-payments' ),
Country_Codes::LITHUANIA => __( 'Lithuania', 'woocommerce-payments' ),
Country_Codes::LATVIA => __( 'Latvia', 'woocommerce-payments' ),
Country_Codes::MALTA => __( 'Malta', 'woocommerce-payments' ),
Country_Codes::NETHERLANDS => __( 'Netherlands', 'woocommerce-payments' ),
Country_Codes::NORWAY => __( 'Norway', 'woocommerce-payments' ),
Country_Codes::NEW_ZEALAND => __( 'New Zealand', 'woocommerce-payments' ),
Country_Codes::POLAND => __( 'Poland', 'woocommerce-payments' ),
Country_Codes::PORTUGAL => __( 'Portugal', 'woocommerce-payments' ),
Country_Codes::ROMANIA => __( 'Romania', 'woocommerce-payments' ),
Country_Codes::SWEDEN => __( 'Sweden', 'woocommerce-payments' ),
Country_Codes::SLOVENIA => __( 'Slovenia', 'woocommerce-payments' ),
Country_Codes::SLOVAKIA => __( 'Slovakia', 'woocommerce-payments' ),
Country_Codes::SINGAPORE => __( 'Singapore', 'woocommerce-payments' ),
Country_Codes::UNITED_STATES => __( 'United States (US)', 'woocommerce-payments' ),
];
}

Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,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-codes.php';
include_once __DIR__ . '/constants/class-fraud-meta-box-type.php';
include_once __DIR__ . '/constants/class-order-status.php';
include_once __DIR__ . '/constants/class-payment-type.php';
Expand Down
Loading
Loading