mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 17:51:41 +08:00
✨ Show Fastlane warning when DCC is disabled
This commit is contained in:
parent
8535601810
commit
dc2dbaed92
3 changed files with 60 additions and 1 deletions
|
@ -119,6 +119,7 @@ return array(
|
||||||
'html' => implode(
|
'html' => implode(
|
||||||
'',
|
'',
|
||||||
array(
|
array(
|
||||||
|
$container->get( 'axo.settings-conflict-notice' ),
|
||||||
$container->get( 'axo.shipping-config-notice' ),
|
$container->get( 'axo.shipping-config-notice' ),
|
||||||
$container->get( 'axo.checkout-config-notice' ),
|
$container->get( 'axo.checkout-config-notice' ),
|
||||||
$container->get( 'axo.incompatible-plugins-notice' ),
|
$container->get( 'axo.incompatible-plugins-notice' ),
|
||||||
|
|
|
@ -16,7 +16,6 @@ use WooCommerce\PayPalCommerce\Axo\Helper\SettingsNoticeGenerator;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -164,6 +163,16 @@ return array(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'axo.settings-conflict-notice' => static function ( ContainerInterface $container ) : string {
|
||||||
|
$settings_notice_generator = $container->get( 'axo.helpers.settings-notice-generator' );
|
||||||
|
assert( $settings_notice_generator instanceof SettingsNoticeGenerator );
|
||||||
|
|
||||||
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
|
assert( $settings instanceof Settings );
|
||||||
|
|
||||||
|
return $settings_notice_generator->generate_settings_conflict_notice( $settings );
|
||||||
|
},
|
||||||
|
|
||||||
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
|
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
|
||||||
$settings_notice_generator = $container->get( 'axo.helpers.settings-notice-generator' );
|
$settings_notice_generator = $container->get( 'axo.helpers.settings-notice-generator' );
|
||||||
assert( $settings_notice_generator instanceof SettingsNoticeGenerator );
|
assert( $settings_notice_generator instanceof SettingsNoticeGenerator );
|
||||||
|
|
|
@ -11,11 +11,32 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\Axo\Helper;
|
namespace WooCommerce\PayPalCommerce\Axo\Helper;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SettingsNoticeGenerator
|
* Class SettingsNoticeGenerator
|
||||||
*/
|
*/
|
||||||
class SettingsNoticeGenerator {
|
class SettingsNoticeGenerator {
|
||||||
|
/**
|
||||||
|
* Generates the full HTML of the notification.
|
||||||
|
*
|
||||||
|
* @param string $message HTML of the inner message contents.
|
||||||
|
* @param bool $is_error Whether the provided message is an error. Affects the notice color.
|
||||||
|
*
|
||||||
|
* @return string The full HTML code of the notification, or an empty string.
|
||||||
|
*/
|
||||||
|
private function render_notice( string $message, bool $is_error = false ) : string {
|
||||||
|
if ( ! $message ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'<div class="ppcp-notice %1$s"><p>%2$s</p></div>',
|
||||||
|
$is_error ? 'ppcp-notice-error' : '',
|
||||||
|
$message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the checkout notice.
|
* Generates the checkout notice.
|
||||||
|
@ -127,4 +148,32 @@ class SettingsNoticeGenerator {
|
||||||
|
|
||||||
return '<div class="ppcp-notice"><p>' . $notice_content . '</p></div>';
|
return '<div class="ppcp-notice"><p>' . $notice_content . '</p></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a warning notice with instructions on conflicting plugin-internal settings.
|
||||||
|
*
|
||||||
|
* @param Settings $settings The plugin settings container, which is checked for conflicting
|
||||||
|
* values.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function generate_settings_conflict_notice( Settings $settings ) : string {
|
||||||
|
$notice_content = '';
|
||||||
|
$is_dcc_enabled = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' );
|
||||||
|
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||||
|
} catch ( NotFoundException $ignored ) {
|
||||||
|
// Never happens.
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! $is_dcc_enabled ) {
|
||||||
|
$notice_content = __(
|
||||||
|
'<span class="highlight">Warning:</span> To enable Fastlane and accelerate payments, the <strong>Advanced Card Processing</strong> payment method must also be enabled.',
|
||||||
|
'woocommerce-paypal-payments'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render_notice( $notice_content, true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue