diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 901c1f94a..de4b6ee63 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -57,6 +57,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; use WooCommerce\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice; use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice; use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice; +use WooCommerce\PayPalCommerce\WcGateway\Notice\UnsupportedCurrencyAdminNotice; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; @@ -208,6 +209,12 @@ return array( $settings = $container->get( 'wcgateway.settings' ); return new ConnectAdminNotice( $state, $settings ); }, + 'wcgateway.notice.currency-unsupported' => static function ( ContainerInterface $container ): UnsupportedCurrencyAdminNotice { + $state = $container->get( 'onboarding.state' ); + $shop_currency = $container->get( 'api.shop.currency' ); + $supported_currencies = $container->get( 'api.supported-currencies' ); + return new UnsupportedCurrencyAdminNotice( $state, $shop_currency, $supported_currencies ); + }, 'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice { return new GatewayWithoutPayPalAdminNotice( CreditCardGateway::ID, diff --git a/modules/ppcp-wc-gateway/src/Notice/UnsupportedCurrencyAdminNotice.php b/modules/ppcp-wc-gateway/src/Notice/UnsupportedCurrencyAdminNotice.php new file mode 100644 index 000000000..27ef14f79 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Notice/UnsupportedCurrencyAdminNotice.php @@ -0,0 +1,97 @@ +state = $state; + $this->shop_currency = $shop_currency; + $this->supported_currencies = $supported_currencies; + } + + /** + * Returns the message. + * + * @return Message|null + */ + public function unsupported_currency_message() { + if ( ! $this->should_display() ) { + return null; + } + + $message = sprintf( + /* translators: %1$s the shop currency, 2$s the gateway name. */ + __( + 'Attention: Your current WooCommerce store currency (%1$s) is not supported by PayPal. Please update your store currency to one that is supported by PayPal to ensure smooth transactions. Visit the PayPal currency support page for more information on supported currencies.', + 'woocommerce-paypal-payments' + ), + $this->shop_currency, + 'https://developer.paypal.com/api/rest/reference/currency-codes/' + ); + return new Message( $message, 'warning' ); + } + + /** + * Whether the message should display. + * + * @return bool + */ + protected function should_display(): bool { + return $this->state->current_state() === State::STATE_ONBOARDED && ! $this->currency_supported(); + } + + /** + * Whether the currency is supported by PayPal. + * + * @return bool + */ + private function currency_supported(): bool { + $currency = $this->shop_currency; + $supported_currencies = $this->supported_currencies; + return in_array( $currency, $supported_currencies, true ); + } +} diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index f49fb8f08..9f3282b58 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -39,6 +39,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus; use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus; use WooCommerce\PayPalCommerce\WcGateway\Notice\ConnectAdminNotice; use WooCommerce\PayPalCommerce\WcGateway\Notice\GatewayWithoutPayPalAdminNotice; +use WooCommerce\PayPalCommerce\WcGateway\Notice\UnsupportedCurrencyAdminNotice; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; use WooCommerce\PayPalCommerce\WcGateway\Settings\HeaderRenderer; use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer; @@ -197,6 +198,13 @@ class WCGatewayModule implements ModuleInterface { $notices[] = $connect_message; } + $notice = $c->get( 'wcgateway.notice.currency-unsupported' ); + assert( $notice instanceof UnsupportedCurrencyAdminNotice ); + $unsupported_currency_message = $notice->unsupported_currency_message(); + if ( $unsupported_currency_message ) { + $notices[] = $unsupported_currency_message; + } + foreach ( array( $c->get( 'wcgateway.notice.dcc-without-paypal' ), $c->get( 'wcgateway.notice.card-button-without-paypal' ),