Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/fix-affirm-domestic-transactions
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

update: payment method definition to determine eligible countries
19 changes: 15 additions & 4 deletions includes/payment-methods/Configs/Definitions/AffirmDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions includes/payment-methods/class-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
}

Expand All @@ -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 {
Expand Down
Loading