Skip to content

Commit

Permalink
only use counties for saved payments and updated the list
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuesken committed Dec 16, 2024
1 parent 0b76a35 commit eb2298f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 85 deletions.
101 changes: 41 additions & 60 deletions modules/ppcp-save-payment-methods/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,75 +20,56 @@
$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 filer 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',
)
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,46 @@

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_country_currencies;

/**
* 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_country_currencies 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_country_currencies,
string $country
) {
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
$this->currency = $currency;
$this->country = $country;
$this->allowed_country_currencies = $allowed_country_currencies;
$this->country = $country;
}

/**
* Returns whether Save Payment Methods can be used in the current country and the current currency used.
*
* @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_country_currencies, true );
}
}

0 comments on commit eb2298f

Please sign in to comment.