Allow to override the list of Pay Later supported countries

This commit is contained in:
Alex P. 2024-08-31 14:03:04 +03:00
parent 796ded031e
commit 381041138c
No known key found for this signature in database
GPG key ID: 54487A734A204D71
3 changed files with 24 additions and 14 deletions

View file

@ -1642,6 +1642,21 @@ return array(
'SE', 'SE',
); );
}, },
'api.paylater-countries' => static function ( ContainerInterface $container ) : array {
return apply_filters(
'woocommerce_paypal_payments_supported_paylater_countries',
array(
'US',
'DE',
'GB',
'FR',
'AU',
'IT',
'ES',
)
);
},
'api.order-helper' => static function( ContainerInterface $container ): OrderHelper { 'api.order-helper' => static function( ContainerInterface $container ): OrderHelper {
return new OrderHelper(); return new OrderHelper();
}, },

View file

@ -320,6 +320,7 @@ return array(
}, },
'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply { 'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
return new MessagesApply( return new MessagesApply(
$container->get( 'api.paylater-countries' ),
$container->get( 'api.shop.country' ) $container->get( 'api.shop.country' )
); );
}, },

View file

@ -18,17 +18,9 @@ class MessagesApply {
/** /**
* In which countries credit messaging is available. * In which countries credit messaging is available.
* *
* @var array * @var string[]
*/ */
private $countries = array( private $allowed_countries;
'US',
'DE',
'GB',
'FR',
'AU',
'IT',
'ES',
);
/** /**
* 2-letter country code of the shop. * 2-letter country code of the shop.
@ -40,10 +32,12 @@ class MessagesApply {
/** /**
* MessagesApply constructor. * MessagesApply constructor.
* *
* @param string $country 2-letter country code of the shop. * @param string[] $allowed_countries In which countries credit messaging is available.
* @param string $country 2-letter country code of the shop.
*/ */
public function __construct( string $country ) { public function __construct( array $allowed_countries, string $country ) {
$this->country = $country; $this->allowed_countries = $allowed_countries;
$this->country = $country;
} }
/** /**
@ -52,6 +46,6 @@ class MessagesApply {
* @return bool * @return bool
*/ */
public function for_country(): bool { public function for_country(): bool {
return in_array( $this->country, $this->countries, true ); return in_array( $this->country, $this->allowed_countries, true );
} }
} }