Merge pull request #2919 from woocommerce/PCP-4033-remove-currency-requirement-for-vault-v-3

Remove currency requirement for Vault v3
This commit is contained in:
Emili Castells 2025-01-23 10:52:21 +01:00 committed by GitHub
commit 0409719e75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 85 deletions

View file

@ -20,75 +20,56 @@ return array(
$save_payment_methods_applies = $container->get( 'save-payment-methods.helpers.save-payment-methods-applies' );
assert( $save_payment_methods_applies instanceof SavePaymentMethodsApplies );
return $save_payment_methods_applies->for_country_currency();
return $save_payment_methods_applies->for_country();
},
'save-payment-methods.helpers.save-payment-methods-applies' => static function ( ContainerInterface $container ) : SavePaymentMethodsApplies {
return new SavePaymentMethodsApplies(
$container->get( 'save-payment-methods.supported-country-currency-matrix' ),
$container->get( 'api.shop.currency.getter' ),
$container->get( 'save-payment-methods.supported-countries' ),
$container->get( 'api.shop.country' )
);
},
'save-payment-methods.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
$default_currencies = array(
'AUD',
'BRL',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'HUF',
'ILS',
'JPY',
'MXN',
'NOK',
'NZD',
'PHP',
'PLN',
'SEK',
'THB',
'TWD',
'USD',
);
'save-payment-methods.supported-countries' => static function ( ContainerInterface $container ) : array {
if ( has_filter( 'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix' ) ) {
_deprecated_hook( 'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix', '3.0.0', 'woocommerce_paypal_payments_save_payment_methods_supported_countries', esc_attr__( 'Please use the new Hook to filter countries for saved payments in PayPal Payments.', 'woocommerce-paypal-payments' ) );
}
return apply_filters(
'woocommerce_paypal_payments_save_payment_methods_supported_country_currency_matrix',
'woocommerce_paypal_payments_save_payment_methods_supported_countries',
array(
'AU' => $default_currencies,
'AT' => $default_currencies,
'BE' => $default_currencies,
'BG' => $default_currencies,
'CA' => $default_currencies,
'CN' => $default_currencies,
'CY' => $default_currencies,
'CZ' => $default_currencies,
'DK' => $default_currencies,
'EE' => $default_currencies,
'FI' => $default_currencies,
'FR' => $default_currencies,
'DE' => $default_currencies,
'GR' => $default_currencies,
'HU' => $default_currencies,
'IE' => $default_currencies,
'IT' => $default_currencies,
'LV' => $default_currencies,
'LI' => $default_currencies,
'LT' => $default_currencies,
'LU' => $default_currencies,
'MT' => $default_currencies,
'NO' => $default_currencies,
'NL' => $default_currencies,
'PL' => $default_currencies,
'PT' => $default_currencies,
'RO' => $default_currencies,
'SK' => $default_currencies,
'SI' => $default_currencies,
'ES' => $default_currencies,
'SE' => $default_currencies,
'GB' => $default_currencies,
'US' => $default_currencies,
'AU',
'AT',
'BE',
'BG',
'CA',
'CN',
'CY',
'CZ',
'DK',
'EE',
'FI',
'FR',
'DE',
'HK',
'HU',
'IE',
'IT',
'LV',
'LI',
'LT',
'LU',
'MT',
'NO',
'NL',
'PL',
'PT',
'RO',
'SG',
'SK',
'SI',
'ES',
'SE',
'GB',
'US',
)
);
},

View file

@ -9,49 +9,37 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\SavePaymentMethods\Helper;
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
/**
* Class SavePaymentMethodsApplies
*/
class SavePaymentMethodsApplies {
/**
* The matrix which countries and currency combinations can be used for Save Payment Methods.
* The countries can be used for Save Payment Methods.
*
* @var array
*/
private $allowed_country_currency_matrix;
/**
* The getter of the 3-letter currency code of the shop.
*
* @var CurrencyGetter
*/
private CurrencyGetter $currency;
private array $allowed_countries;
/**
* 2-letter country code of the shop.
*
* @var string
*/
private $country;
private string $country;
/**
* SavePaymentMethodsApplies constructor.
*
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for Save Payment Methods.
* @param CurrencyGetter $currency The getter of the 3-letter currency code of the shop.
* @param string $country 2-letter country code of the shop.
* @param array $allowed_countries The matrix which countries and currency combinations can be used for Save Payment Methods.
* @param string $country 2-letter country code of the shop.
*/
public function __construct(
array $allowed_country_currency_matrix,
CurrencyGetter $currency,
array $allowed_countries,
string $country
) {
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
$this->currency = $currency;
$this->country = $country;
$this->allowed_countries = $allowed_countries;
$this->country = $country;
}
/**
@ -59,10 +47,8 @@ class SavePaymentMethodsApplies {
*
* @return bool
*/
public function for_country_currency(): bool {
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
return false;
}
return in_array( $this->currency->get(), $this->allowed_country_currency_matrix[ $this->country ], true );
public function for_country(): bool {
return in_array( $this->country, $this->allowed_countries, true );
}
}