mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Merge branch 'refs/heads/trunk' into PCP-4110-incorrect-subscription-cancellation-handling-with-pay-pal-subscriptions
This commit is contained in:
commit
35d6c7e913
47 changed files with 1112 additions and 842 deletions
|
@ -17,7 +17,7 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CardPaymentsConfiguration;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
|
||||
|
||||
return array(
|
||||
|
@ -39,7 +39,10 @@ return array(
|
|||
},
|
||||
|
||||
'axo.helpers.compatibility-checker' => static function ( ContainerInterface $container ) : CompatibilityChecker {
|
||||
return new CompatibilityChecker( $container->get( 'axo.fastlane-incompatible-plugin-names' ) );
|
||||
return new CompatibilityChecker(
|
||||
$container->get( 'axo.fastlane-incompatible-plugin-names' ),
|
||||
$container->get( 'wcgateway.configuration.card-configuration' )
|
||||
);
|
||||
},
|
||||
|
||||
// If AXO is configured and onboarded.
|
||||
|
@ -80,7 +83,7 @@ return array(
|
|||
return new AxoGateway(
|
||||
$container->get( 'wcgateway.settings.render' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.configuration.dcc' ),
|
||||
$container->get( 'wcgateway.configuration.card-configuration' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wcgateway.order-processor' ),
|
||||
|
@ -193,10 +196,7 @@ return array(
|
|||
$compatibility_checker = $container->get( 'axo.helpers.compatibility-checker' );
|
||||
assert( $compatibility_checker instanceof CompatibilityChecker );
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
return $compatibility_checker->generate_settings_conflict_notice( $settings );
|
||||
return $compatibility_checker->generate_settings_conflict_notice();
|
||||
},
|
||||
|
||||
'axo.checkout-config-notice' => static function ( ContainerInterface $container ) : string {
|
||||
|
@ -221,16 +221,15 @@ return array(
|
|||
},
|
||||
|
||||
'axo.incompatible-plugins-notice.raw' => static function ( ContainerInterface $container ) : string {
|
||||
$settings_notice_generator = new CompatibilityChecker(
|
||||
$container->get( 'axo.fastlane-incompatible-plugin-names' )
|
||||
);
|
||||
$settings_notice_generator = $container->get( 'axo.helpers.compatibility-checker' );
|
||||
assert( $settings_notice_generator instanceof CompatibilityChecker );
|
||||
|
||||
return $settings_notice_generator->generate_incompatible_plugins_notice( true );
|
||||
},
|
||||
|
||||
'axo.smart-button-location-notice' => static function ( ContainerInterface $container ) : string {
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
if ( $dcc_configuration->use_fastlane() ) {
|
||||
$fastlane_settings_url = admin_url(
|
||||
|
|
|
@ -30,7 +30,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
use WC_Payment_Gateways;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CardPaymentsConfiguration;
|
||||
|
||||
/**
|
||||
* Class AxoModule
|
||||
|
@ -98,8 +98,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
return $methods;
|
||||
}
|
||||
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
if ( ! $dcc_configuration->is_enabled() ) {
|
||||
return $methods;
|
||||
|
@ -164,8 +164,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
$listener = $c->get( 'wcgateway.settings.listener' );
|
||||
assert( $listener instanceof SettingsListener );
|
||||
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
$listener->filter_settings(
|
||||
$dcc_configuration->use_fastlane(),
|
||||
|
@ -247,8 +247,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
add_filter(
|
||||
'woocommerce_paypal_payments_sdk_components_hook',
|
||||
function( $components ) use ( $c ) {
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
if ( ! $dcc_configuration->use_fastlane() ) {
|
||||
return $components;
|
||||
|
@ -262,8 +262,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
'wp_head',
|
||||
function () use ( $c ) {
|
||||
// Add meta tag to allow feature-detection of the site's AXO payment state.
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
if ( $dcc_configuration->use_fastlane() ) {
|
||||
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript
|
||||
|
@ -403,8 +403,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
* @return bool
|
||||
*/
|
||||
private function should_render_fastlane( ContainerInterface $c ): bool {
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.dcc' );
|
||||
assert( $dcc_configuration instanceof DCCGatewayConfiguration );
|
||||
$dcc_configuration = $c->get( 'wcgateway.configuration.card-configuration' );
|
||||
assert( $dcc_configuration instanceof CardPaymentsConfiguration );
|
||||
|
||||
$subscription_helper = $c->get( 'wc-subscriptions.helper' );
|
||||
assert( $subscription_helper instanceof SubscriptionHelper );
|
||||
|
|
|
@ -29,7 +29,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\ProcessPaymentTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\GatewayGenericException;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CardPaymentsConfiguration;
|
||||
|
||||
/**
|
||||
* Class AXOGateway.
|
||||
|
@ -56,9 +56,9 @@ class AxoGateway extends WC_Payment_Gateway {
|
|||
/**
|
||||
* Gateway configuration object, providing relevant settings.
|
||||
*
|
||||
* @var DCCGatewayConfiguration
|
||||
* @var CardPaymentsConfiguration
|
||||
*/
|
||||
protected DCCGatewayConfiguration $dcc_configuration;
|
||||
protected CardPaymentsConfiguration $dcc_configuration;
|
||||
|
||||
/**
|
||||
* The WcGateway module URL.
|
||||
|
@ -133,24 +133,24 @@ class AxoGateway extends WC_Payment_Gateway {
|
|||
/**
|
||||
* AXOGateway constructor.
|
||||
*
|
||||
* @param SettingsRenderer $settings_renderer The settings renderer.
|
||||
* @param ContainerInterface $ppcp_settings The settings.
|
||||
* @param DCCGatewayConfiguration $dcc_configuration The DCC Gateway configuration.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param OrderProcessor $order_processor The Order processor.
|
||||
* @param array $card_icons The card icons.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param SettingsRenderer $settings_renderer The settings renderer.
|
||||
* @param ContainerInterface $ppcp_settings The settings.
|
||||
* @param CardPaymentsConfiguration $dcc_configuration The DCC Gateway configuration.
|
||||
* @param string $wcgateway_module_url The WcGateway module URL.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param OrderProcessor $order_processor The Order processor.
|
||||
* @param array $card_icons The card icons.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param PurchaseUnitFactory $purchase_unit_factory The purchase unit factory.
|
||||
* @param ShippingPreferenceFactory $shipping_preference_factory The shipping preference factory.
|
||||
* @param TransactionUrlProvider $transaction_url_provider The transaction url provider.
|
||||
* @param Environment $environment The environment.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param TransactionUrlProvider $transaction_url_provider The transaction url provider.
|
||||
* @param Environment $environment The environment.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
*/
|
||||
public function __construct(
|
||||
SettingsRenderer $settings_renderer,
|
||||
ContainerInterface $ppcp_settings,
|
||||
DCCGatewayConfiguration $dcc_configuration,
|
||||
CardPaymentsConfiguration $dcc_configuration,
|
||||
string $wcgateway_module_url,
|
||||
SessionHandler $session_handler,
|
||||
OrderProcessor $order_processor,
|
||||
|
|
|
@ -6,16 +6,19 @@
|
|||
* @package WooCommerce\PayPalCommerce\Axo\Helper
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Axo\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CartCheckoutDetector;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CardPaymentsConfiguration;
|
||||
|
||||
/**
|
||||
* Class CompatibilityChecker
|
||||
*
|
||||
* DI service: 'axo.helpers.compatibility-checker'
|
||||
*/
|
||||
class CompatibilityChecker {
|
||||
/**
|
||||
|
@ -33,20 +36,24 @@ class CompatibilityChecker {
|
|||
protected array $checkout_compatibility;
|
||||
|
||||
/**
|
||||
* Stores whether DCC is enabled.
|
||||
* Provides details about the DCC configuration.
|
||||
*
|
||||
* @var bool|null
|
||||
* @var CardPaymentsConfiguration
|
||||
*/
|
||||
protected ?bool $is_dcc_enabled = null;
|
||||
private CardPaymentsConfiguration $dcc_configuration;
|
||||
|
||||
/**
|
||||
* CompatibilityChecker constructor.
|
||||
*
|
||||
* @param string[] $incompatible_plugin_names The list of Fastlane incompatible plugin names.
|
||||
* @param string[] $incompatible_plugin_names The list of Fastlane incompatible
|
||||
* plugin names.
|
||||
* @param CardPaymentsConfiguration $dcc_configuration DCC gateway configuration.
|
||||
*/
|
||||
public function __construct( array $incompatible_plugin_names ) {
|
||||
public function __construct( array $incompatible_plugin_names, CardPaymentsConfiguration $dcc_configuration ) {
|
||||
$this->incompatible_plugin_names = $incompatible_plugin_names;
|
||||
$this->checkout_compatibility = array(
|
||||
$this->dcc_configuration = $dcc_configuration;
|
||||
|
||||
$this->checkout_compatibility = array(
|
||||
'has_elementor_checkout' => null,
|
||||
'has_classic_checkout' => null,
|
||||
'has_block_checkout' => null,
|
||||
|
@ -58,7 +65,7 @@ class CompatibilityChecker {
|
|||
*
|
||||
* @return bool Whether the checkout uses Elementor.
|
||||
*/
|
||||
protected function has_elementor_checkout(): bool {
|
||||
protected function has_elementor_checkout() : bool {
|
||||
if ( $this->checkout_compatibility['has_elementor_checkout'] === null ) {
|
||||
$this->checkout_compatibility['has_elementor_checkout'] = CartCheckoutDetector::has_elementor_checkout();
|
||||
}
|
||||
|
@ -71,7 +78,7 @@ class CompatibilityChecker {
|
|||
*
|
||||
* @return bool Whether the checkout uses classic checkout.
|
||||
*/
|
||||
protected function has_classic_checkout(): bool {
|
||||
protected function has_classic_checkout() : bool {
|
||||
if ( $this->checkout_compatibility['has_classic_checkout'] === null ) {
|
||||
$this->checkout_compatibility['has_classic_checkout'] = CartCheckoutDetector::has_classic_checkout();
|
||||
}
|
||||
|
@ -84,7 +91,7 @@ class CompatibilityChecker {
|
|||
*
|
||||
* @return bool Whether the checkout uses block checkout.
|
||||
*/
|
||||
protected function has_block_checkout(): bool {
|
||||
protected function has_block_checkout() : bool {
|
||||
if ( $this->checkout_compatibility['has_block_checkout'] === null ) {
|
||||
$this->checkout_compatibility['has_block_checkout'] = CartCheckoutDetector::has_block_checkout();
|
||||
}
|
||||
|
@ -92,29 +99,12 @@ class CompatibilityChecker {
|
|||
return $this->checkout_compatibility['has_block_checkout'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if DCC is enabled.
|
||||
*
|
||||
* @param Settings $settings The plugin settings container.
|
||||
* @return bool Whether DCC is enabled.
|
||||
*/
|
||||
protected function is_dcc_enabled( Settings $settings ): bool {
|
||||
if ( $this->is_dcc_enabled === null ) {
|
||||
try {
|
||||
$this->is_dcc_enabled = $settings->has( 'dcc_enabled' ) && $settings->get( 'dcc_enabled' );
|
||||
} catch ( NotFoundException $ignored ) {
|
||||
$this->is_dcc_enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->is_dcc_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param string $message HTML of the inner message contents.
|
||||
* @param bool $is_error Whether the provided message is an error. Affects the notice
|
||||
* color.
|
||||
* @param bool $raw_message Whether to return raw message without HTML wrappers.
|
||||
*
|
||||
* @return string The full HTML code of the notification, or an empty string, or raw message.
|
||||
|
@ -136,11 +126,12 @@ class CompatibilityChecker {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if there aren't any incompatibilities that would prevent Fastlane from working properly.
|
||||
* Check if there aren't any incompatibilities that would prevent Fastlane from working
|
||||
* properly.
|
||||
*
|
||||
* @return bool Whether the setup is compatible.
|
||||
*/
|
||||
public function is_fastlane_compatible(): bool {
|
||||
public function is_fastlane_compatible() : bool {
|
||||
// Check for incompatible plugins.
|
||||
if ( ! empty( $this->incompatible_plugin_names ) ) {
|
||||
return false;
|
||||
|
@ -165,7 +156,7 @@ class CompatibilityChecker {
|
|||
* @param bool $raw_message Whether to return raw message without HTML wrappers.
|
||||
* @return string
|
||||
*/
|
||||
public function generate_checkout_notice( bool $raw_message = false ): string {
|
||||
public function generate_checkout_notice( bool $raw_message = false ) : string {
|
||||
$notice_content = '';
|
||||
|
||||
// Check for checkout incompatibilities.
|
||||
|
@ -213,7 +204,7 @@ class CompatibilityChecker {
|
|||
* @param bool $raw_message Whether to return raw message without HTML wrappers.
|
||||
* @return string
|
||||
*/
|
||||
public function generate_incompatible_plugins_notice( bool $raw_message = false ): string {
|
||||
public function generate_incompatible_plugins_notice( bool $raw_message = false ) : string {
|
||||
if ( empty( $this->incompatible_plugin_names ) ) {
|
||||
return '';
|
||||
}
|
||||
|
@ -235,12 +226,11 @@ class CompatibilityChecker {
|
|||
/**
|
||||
* Generates a warning notice with instructions on conflicting plugin-internal settings.
|
||||
*
|
||||
* @param Settings $settings The plugin settings container, which is checked for conflicting values.
|
||||
* @param bool $raw_message Whether to return raw message without HTML wrappers.
|
||||
* @param bool $raw_message Whether to return raw message without HTML wrappers.
|
||||
* @return string
|
||||
*/
|
||||
public function generate_settings_conflict_notice( Settings $settings, bool $raw_message = false ) : string {
|
||||
if ( $this->is_dcc_enabled( $settings ) ) {
|
||||
public function generate_settings_conflict_notice( bool $raw_message = false ) : string {
|
||||
if ( $this->dcc_configuration->is_enabled() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue