diff --git a/changelog/fix-affirm-domestic-transactions b/changelog/fix-affirm-domestic-transactions new file mode 100644 index 00000000000..52c2a7ca373 --- /dev/null +++ b/changelog/fix-affirm-domestic-transactions @@ -0,0 +1,4 @@ +Significance: patch +Type: update + +update: payment method definition to determine eligible countries diff --git a/includes/payment-methods/Configs/Definitions/AffirmDefinition.php b/includes/payment-methods/Configs/Definitions/AffirmDefinition.php index 64c2ebb45b3..0517dee0e88 100644 --- a/includes/payment-methods/Configs/Definitions/AffirmDefinition.php +++ b/includes/payment-methods/Configs/Definitions/AffirmDefinition.php @@ -90,15 +90,26 @@ public static function get_supported_currencies(): array { } /** - * Get the list of supported countries + * Get the list of supported countries. * + * Affirm only supports domestic transactions, so when account_country is provided, + * only that country is returned if it's in the supported list. + * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { - return [ + public static function get_supported_countries( ?string $account_country = null ): array { + $supported_countries = [ Country_Code::UNITED_STATES, Country_Code::CANADA, ]; + + // Affirm only supports domestic transactions. + if ( null !== $account_country && in_array( strtoupper( $account_country ), $supported_countries, true ) ) { + return [ strtoupper( $account_country ) ]; + } + + return $supported_countries; } /** @@ -188,7 +199,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/AlipayDefinition.php b/includes/payment-methods/Configs/Definitions/AlipayDefinition.php index 6d20d5aa65b..e6356843309 100644 --- a/includes/payment-methods/Configs/Definitions/AlipayDefinition.php +++ b/includes/payment-methods/Configs/Definitions/AlipayDefinition.php @@ -165,9 +165,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return []; } @@ -244,7 +245,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/ApplePayDefinition.php b/includes/payment-methods/Configs/Definitions/ApplePayDefinition.php index 6a70d410c63..9d652561040 100644 --- a/includes/payment-methods/Configs/Definitions/ApplePayDefinition.php +++ b/includes/payment-methods/Configs/Definitions/ApplePayDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return []; } @@ -170,7 +171,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ) ) { + if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ) ) { return false; } diff --git a/includes/payment-methods/Configs/Definitions/BancontactDefinition.php b/includes/payment-methods/Configs/Definitions/BancontactDefinition.php index 09c185ee6fa..63c228a7a5a 100644 --- a/includes/payment-methods/Configs/Definitions/BancontactDefinition.php +++ b/includes/payment-methods/Configs/Definitions/BancontactDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::BELGIUM ]; } @@ -167,7 +168,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/EpsDefinition.php b/includes/payment-methods/Configs/Definitions/EpsDefinition.php index 3e8bedfe5f8..7b43dd34a89 100644 --- a/includes/payment-methods/Configs/Definitions/EpsDefinition.php +++ b/includes/payment-methods/Configs/Definitions/EpsDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::AUSTRIA ]; } @@ -167,7 +168,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/GiropayDefinition.php b/includes/payment-methods/Configs/Definitions/GiropayDefinition.php index e7d7fde56e3..a74786f4b0a 100644 --- a/includes/payment-methods/Configs/Definitions/GiropayDefinition.php +++ b/includes/payment-methods/Configs/Definitions/GiropayDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::GERMANY ]; } @@ -168,7 +169,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/GooglePayDefinition.php b/includes/payment-methods/Configs/Definitions/GooglePayDefinition.php index f90c3fa8eb2..8415f28fca1 100644 --- a/includes/payment-methods/Configs/Definitions/GooglePayDefinition.php +++ b/includes/payment-methods/Configs/Definitions/GooglePayDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return []; } @@ -170,7 +171,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ) ) { + if ( ! PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ) ) { return false; } diff --git a/includes/payment-methods/Configs/Definitions/IdealDefinition.php b/includes/payment-methods/Configs/Definitions/IdealDefinition.php index 2ea60db1473..1b73f1b50eb 100644 --- a/includes/payment-methods/Configs/Definitions/IdealDefinition.php +++ b/includes/payment-methods/Configs/Definitions/IdealDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::NETHERLANDS ]; } @@ -168,7 +169,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/P24Definition.php b/includes/payment-methods/Configs/Definitions/P24Definition.php index bb6ca4b4a44..81ed4dd2c90 100644 --- a/includes/payment-methods/Configs/Definitions/P24Definition.php +++ b/includes/payment-methods/Configs/Definitions/P24Definition.php @@ -92,9 +92,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::POLAND ]; } @@ -170,7 +171,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/SofortDefinition.php b/includes/payment-methods/Configs/Definitions/SofortDefinition.php index b600fc53928..9e9c2005b5e 100644 --- a/includes/payment-methods/Configs/Definitions/SofortDefinition.php +++ b/includes/payment-methods/Configs/Definitions/SofortDefinition.php @@ -89,9 +89,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::AUSTRIA, Country_Code::BELGIUM, @@ -173,7 +174,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Definitions/WechatPayDefinition.php b/includes/payment-methods/Configs/Definitions/WechatPayDefinition.php index 1410499075d..d9ff74b286b 100644 --- a/includes/payment-methods/Configs/Definitions/WechatPayDefinition.php +++ b/includes/payment-methods/Configs/Definitions/WechatPayDefinition.php @@ -157,9 +157,10 @@ public static function get_supported_currencies(): array { /** * Get the list of supported countries * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ Country_Code::UNITED_STATES, Country_Code::AUSTRALIA, @@ -259,7 +260,7 @@ public static function get_limits_per_currency(): array { * @return bool */ public static function is_available_for( string $currency, string $account_country ): bool { - return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries(), $currency, $account_country ); + return PaymentMethodUtils::is_available_for( self::get_supported_currencies(), self::get_supported_countries( $account_country ), $currency, $account_country ); } /** diff --git a/includes/payment-methods/Configs/Interfaces/PaymentMethodDefinitionInterface.php b/includes/payment-methods/Configs/Interfaces/PaymentMethodDefinitionInterface.php index abb2424d222..14ef4700437 100644 --- a/includes/payment-methods/Configs/Interfaces/PaymentMethodDefinitionInterface.php +++ b/includes/payment-methods/Configs/Interfaces/PaymentMethodDefinitionInterface.php @@ -69,9 +69,14 @@ public static function get_supported_currencies(): array; * Get the list of supported countries * Empty array means all countries are supported * + * When account_country is provided, payment methods with domestic transaction + * restrictions should return only that country (if supported), enabling + * proper filtering at checkout. + * + * @param string|null $account_country Optional. The merchant's account country. * @return string[] Array of country codes */ - public static function get_supported_countries(): array; + public static function get_supported_countries( ?string $account_country = null ): array; /** * Get the payment method capabilities diff --git a/includes/payment-methods/class-upe-payment-method.php b/includes/payment-methods/class-upe-payment-method.php index 28722c1318a..afd7cbb85f6 100644 --- a/includes/payment-methods/class-upe-payment-method.php +++ b/includes/payment-methods/class-upe-payment-method.php @@ -385,6 +385,10 @@ public function get_countries() { $account = \WC_Payments::get_account_service()->get_cached_account_data(); $account_country = isset( $account['country'] ) ? strtoupper( $account['country'] ) : ''; + if ( ! empty( $this->definition ) ) { + return $this->definition::get_supported_countries( $account_country ); + } + return $this->has_domestic_transactions_restrictions() ? [ $account_country ] : $this->countries; } diff --git a/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition-two.php b/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition-two.php index af1cea55d7b..3dccd0a9ac5 100644 --- a/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition-two.php +++ b/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition-two.php @@ -42,7 +42,7 @@ public static function get_description( ?string $account_country = null ): strin return 'Second mock payment method for testing'; } - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ 'US' ]; } @@ -72,7 +72,7 @@ public static function get_testing_instructions( string $account_country ): stri public static function is_available_for( string $currency, string $account_country ): bool { return in_array( $currency, self::get_supported_currencies(), true ) && - in_array( $account_country, self::get_supported_countries(), true ); + in_array( $account_country, self::get_supported_countries( $account_country ), true ); } public static function get_limits_per_currency(): array { diff --git a/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition.php b/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition.php index 5c490b11aee..c8f7677e22b 100644 --- a/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition.php +++ b/tests/unit/payment-methods/Configs/mocks/class-mock-payment-method-definition.php @@ -46,7 +46,7 @@ public static function get_supported_currencies(): array { return [ 'USD', 'CAD' ]; } - public static function get_supported_countries(): array { + public static function get_supported_countries( ?string $account_country = null ): array { return [ 'US', 'CA' ]; } @@ -72,7 +72,7 @@ public static function get_testing_instructions( string $account_country ): stri public static function is_available_for( string $currency, string $account_country ): bool { return in_array( $currency, self::get_supported_currencies(), true ) && - in_array( $account_country, self::get_supported_countries(), true ); + in_array( $account_country, self::get_supported_countries( $account_country ), true ); } public static function get_limits_per_currency(): array {