mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Extract shop currency, country to services
This commit is contained in:
parent
cfb10b0cee
commit
ffe32070d0
13 changed files with 197 additions and 109 deletions
|
@ -70,6 +70,7 @@ return array(
|
|||
$environment = $container->get( 'onboarding.environment' );
|
||||
$payment_token_repository = $container->get( 'vaulting.repository.payment-token' );
|
||||
$settings_status = $container->get( 'wcgateway.settings.status' );
|
||||
$currency = $container->get( 'api.shop.currency' );
|
||||
return new SmartButton(
|
||||
$container->get( 'button.url' ),
|
||||
$container->get( 'session.handler' ),
|
||||
|
@ -82,7 +83,8 @@ return array(
|
|||
$messages_apply,
|
||||
$environment,
|
||||
$payment_token_repository,
|
||||
$settings_status
|
||||
$settings_status,
|
||||
$currency
|
||||
);
|
||||
},
|
||||
'button.url' => static function ( ContainerInterface $container ): string {
|
||||
|
@ -171,7 +173,9 @@ return array(
|
|||
return new ThreeDSecure( $logger );
|
||||
},
|
||||
'button.helper.messages-apply' => static function ( ContainerInterface $container ): MessagesApply {
|
||||
return new MessagesApply();
|
||||
return new MessagesApply(
|
||||
$container->get( 'api.shop.country' )
|
||||
);
|
||||
},
|
||||
|
||||
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
||||
|
|
|
@ -114,6 +114,13 @@ class SmartButton implements SmartButtonInterface {
|
|||
*/
|
||||
private $payment_token_repository;
|
||||
|
||||
/**
|
||||
* 3-letter currency code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
/**
|
||||
* SmartButton constructor.
|
||||
*
|
||||
|
@ -129,6 +136,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
* @param Environment $environment The environment object.
|
||||
* @param PaymentTokenRepository $payment_token_repository The payment token repository.
|
||||
* @param SettingsStatus $settings_status The Settings status helper.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
|
@ -142,7 +150,8 @@ class SmartButton implements SmartButtonInterface {
|
|||
MessagesApply $messages_apply,
|
||||
Environment $environment,
|
||||
PaymentTokenRepository $payment_token_repository,
|
||||
SettingsStatus $settings_status
|
||||
SettingsStatus $settings_status,
|
||||
string $currency
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
|
@ -157,6 +166,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
$this->environment = $environment;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->settings_status = $settings_status;
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -749,7 +759,7 @@ class SmartButton implements SmartButtonInterface {
|
|||
|
||||
$params = array(
|
||||
'client-id' => $this->client_id,
|
||||
'currency' => get_woocommerce_currency(),
|
||||
'currency' => $this->currency,
|
||||
'integration-date' => PAYPAL_INTEGRATION_DATE,
|
||||
'components' => implode( ',', $this->components() ),
|
||||
'vault' => $this->can_save_vault_token() ? 'true' : 'false',
|
||||
|
|
|
@ -28,14 +28,28 @@ class MessagesApply {
|
|||
'AU',
|
||||
);
|
||||
|
||||
/**
|
||||
* 2-letter country code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* MessagesApply constructor.
|
||||
*
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct( string $country ) {
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a credit messaging is enabled for the shops location country.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function for_country(): bool {
|
||||
$region = wc_get_base_location();
|
||||
$country = $region['country'];
|
||||
return in_array( $country, $this->countries, true );
|
||||
return in_array( $this->country, $this->countries, true );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,15 +39,28 @@ class MessagesDisclaimers {
|
|||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* 2-letter country code of the shop.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $country;
|
||||
|
||||
/**
|
||||
* MessagesDisclaimers constructor.
|
||||
*
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct( string $country ) {
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a disclaimer link based on country.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function link_for_country(): string {
|
||||
$region = wc_get_base_location();
|
||||
$country = $region['country'];
|
||||
|
||||
return $this->disclaimers[ $country ]['link'] ?? '';
|
||||
return $this->disclaimers[ $this->country ]['link'] ?? '';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue