mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Add unsupported currency admin notice
This commit is contained in:
parent
af5d33dc78
commit
d3249b140a
3 changed files with 95 additions and 0 deletions
|
@ -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,11 @@ 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');
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
return new UnsupportedCurrencyAdminNotice($state, $settings);
|
||||
},
|
||||
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
|
||||
return new GatewayWithoutPayPalAdminNotice(
|
||||
CreditCardGateway::ID,
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* Registers the admin message to "connect your account" if necessary.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Notice
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
|
||||
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class ConnectAdminNotice
|
||||
*/
|
||||
class UnsupportedCurrencyAdminNotice {
|
||||
|
||||
/**
|
||||
* The state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* ConnectAdminNotice constructor.
|
||||
*
|
||||
* @param State $state The state.
|
||||
* @param ContainerInterface $settings The settings.
|
||||
*/
|
||||
public function __construct( State $state, ContainerInterface $settings ) {
|
||||
$this->state = $state;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the message.
|
||||
*
|
||||
* @return Message|null
|
||||
*/
|
||||
public function unsupported_currency_message() {
|
||||
if ( ! $this->should_display() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
/* translators: %1$s the gateway name. */
|
||||
__(
|
||||
'Attention: Your current WooCommerce store currency is not supported by PayPal. Please update your store currency to one that is supported by PayPal to ensure smooth transactions. Visit the <a href="%1$s">PayPal currency support page</a> for more information on supported currencies.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
"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();
|
||||
}
|
||||
|
||||
private function currency_supported()
|
||||
{
|
||||
//TODO - get the currency from the settings
|
||||
}
|
||||
}
|
|
@ -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' ),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue