mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🔀 Merge branch 'trunk'
This commit is contained in:
commit
cdcc523956
54 changed files with 523 additions and 401 deletions
|
@ -80,12 +80,11 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\ConnectBearer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\EnvironmentConfig;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
|
||||
return array(
|
||||
'api.host' => static function( ContainerInterface $container ) : string {
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
if ( $environment->is_sandbox() ) {
|
||||
|
|
|
@ -42,7 +42,7 @@ return array(
|
|||
assert( $display_manager instanceof DisplayManager );
|
||||
|
||||
// Domain registration.
|
||||
$env = $container->get( 'onboarding.environment' );
|
||||
$env = $container->get( 'settings.environment' );
|
||||
assert( $env instanceof Environment );
|
||||
|
||||
$domain_registration_url = 'https://www.paypal.com/uccservicing/apm/applepay';
|
||||
|
|
|
@ -20,7 +20,6 @@ use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
|
|||
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
|
@ -260,15 +259,15 @@ return array(
|
|||
},
|
||||
|
||||
'applepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$product_status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $product_status instanceof AppleProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$enabled = $product_status->is_active();
|
||||
|
|
|
@ -368,7 +368,7 @@ class ApplepayModule implements ServiceModule, ExtendingModule, ExecutableModule
|
|||
if ( ! $button->is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
$env = $c->get( 'onboarding.environment' );
|
||||
$env = $c->get( 'settings.environment' );
|
||||
assert( $env instanceof Environment );
|
||||
$is_sandobx = $env->current_environment_is( Environment::SANDBOX );
|
||||
$this->load_domain_association_file( $is_sandobx );
|
||||
|
|
|
@ -89,6 +89,7 @@ class AppleProductStatus extends ProductStatus {
|
|||
}
|
||||
}
|
||||
|
||||
// Settings used as a cache; `settings->set` is compatible with new UI.
|
||||
if ( $has_capability ) {
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
} else {
|
||||
|
|
|
@ -36,7 +36,7 @@ return array(
|
|||
fn(): SmartButtonInterface => $container->get( 'button.smart-button' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.configuration.dcc' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'axo.payment_method_selected_map' ),
|
||||
$container->get( 'axo.supported-country-card-type-matrix' )
|
||||
|
|
|
@ -10,7 +10,6 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Axo;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Axo\Helper\NoticeRenderer;
|
||||
use WooCommerce\PayPalCommerce\Axo\Helper\PropertiesDictionary;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DisplayManager;
|
||||
|
|
|
@ -66,7 +66,7 @@ return array(
|
|||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'axo.insights' ),
|
||||
$container->get( 'wcgateway.settings.status' ),
|
||||
$container->get( 'api.shop.currency.getter' ),
|
||||
|
@ -89,7 +89,7 @@ return array(
|
|||
$container->get( 'api.factory.purchase-unit' ),
|
||||
$container->get( 'api.factory.shipping-preference' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
|
|
|
@ -36,7 +36,6 @@ use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
|
|||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
||||
|
@ -49,7 +48,7 @@ return array(
|
|||
return $client_id;
|
||||
}
|
||||
|
||||
$env = $container->get( 'onboarding.environment' );
|
||||
$env = $container->get( 'settings.environment' );
|
||||
/**
|
||||
* The environment.
|
||||
*
|
||||
|
@ -125,8 +124,8 @@ return array(
|
|||
}
|
||||
}
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() !== State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return new DisabledSmartButton();
|
||||
}
|
||||
|
||||
|
@ -142,7 +141,7 @@ return array(
|
|||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
|
||||
$messages_apply = $container->get( 'button.helper.messages-apply' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
$payment_token_repository = $container->get( 'vaulting.repository.payment-token' );
|
||||
return new SmartButton(
|
||||
$container->get( 'button.url' ),
|
||||
|
@ -241,11 +240,11 @@ return array(
|
|||
);
|
||||
},
|
||||
'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
return new EarlyOrderHandler( $state, $order_processor, $session_handler );
|
||||
return new EarlyOrderHandler(
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.order-processor' ),
|
||||
$container->get( 'session.handler' )
|
||||
);
|
||||
},
|
||||
'button.endpoint.approve-order' => static function ( ContainerInterface $container ): ApproveOrderEndpoint {
|
||||
$request_data = $container->get( 'button.request-data' );
|
||||
|
|
|
@ -272,8 +272,9 @@ class ApproveOrderEndpoint implements EndpointInterface {
|
|||
* @return void
|
||||
*/
|
||||
protected function toggle_final_review_enabled_setting(): void {
|
||||
// TODO new-ux: This flag must also be updated in the new settings.
|
||||
$final_review_enabled_setting = $this->settings->has( 'blocks_final_review_enabled' ) && $this->settings->get( 'blocks_final_review_enabled' );
|
||||
$final_review_enabled_setting ? $this->settings->set( 'blocks_final_review_enabled', false ) : $this->settings->set( 'blocks_final_review_enabled', true );
|
||||
$this->settings->set( 'blocks_final_review_enabled', ! $final_review_enabled_setting );
|
||||
$this->settings->persist();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@ namespace WooCommerce\PayPalCommerce\Button\Helper;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderTransient;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
||||
|
@ -23,11 +21,11 @@ use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor;
|
|||
class EarlyOrderHandler {
|
||||
|
||||
/**
|
||||
* The State.
|
||||
* Whether the merchant is connected to PayPal (onboarding completed).
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The Order Processor.
|
||||
|
@ -46,17 +44,17 @@ class EarlyOrderHandler {
|
|||
/**
|
||||
* EarlyOrderHandler constructor.
|
||||
*
|
||||
* @param State $state The State.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param OrderProcessor $order_processor The Order Processor.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
*/
|
||||
public function __construct(
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
OrderProcessor $order_processor,
|
||||
SessionHandler $session_handler
|
||||
) {
|
||||
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->order_processor = $order_processor;
|
||||
$this->session_handler = $session_handler;
|
||||
}
|
||||
|
@ -67,7 +65,7 @@ class EarlyOrderHandler {
|
|||
* @return bool
|
||||
*/
|
||||
public function should_create_early_order(): bool {
|
||||
return $this->state->current_state() === State::STATE_ONBOARDED;
|
||||
return $this->is_connected;
|
||||
}
|
||||
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
|
|
|
@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmApplies;
|
|||
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
|
||||
use WooCommerce\PayPalCommerce\Googlepay\Helper\AvailabilityNotice;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
|
@ -174,7 +173,7 @@ return array(
|
|||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wc-subscriptions.helper' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'wcgateway.settings.status' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
|
@ -221,15 +220,15 @@ return array(
|
|||
},
|
||||
|
||||
'googlepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$product_status = $container->get( 'googlepay.helpers.apm-product-status' );
|
||||
assert( $product_status instanceof ApmProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$enabled = $product_status->is_active();
|
||||
|
|
|
@ -89,6 +89,7 @@ class ApmProductStatus extends ProductStatus {
|
|||
}
|
||||
}
|
||||
|
||||
// Settings used as a cache; `settings->set` is compatible with new UI.
|
||||
if ( $has_capability ) {
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
|||
|
||||
use WC_Order;
|
||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
|
@ -56,8 +55,9 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
|
|||
if ( ! self::should_add_local_apm_gateways( $c ) ) {
|
||||
return $methods;
|
||||
}
|
||||
$onboarding_state = $c->get( 'onboarding.state' );
|
||||
if ( $onboarding_state->current_state() === State::STATE_START ) {
|
||||
|
||||
$is_connected = $c->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ class LocalApmProductStatus extends ProductStatus {
|
|||
}
|
||||
}
|
||||
|
||||
// Settings used as a cache; `settings->set` is compatible with new UI.
|
||||
if ( $has_capability ) {
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
} else {
|
||||
|
|
|
@ -18,10 +18,11 @@ use WooCommerce\PayPalCommerce\Onboarding\Endpoint\UpdateSignupLinksEndpoint;
|
|||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingSendOnlyNoticeRenderer;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
||||
return array(
|
||||
'api.paypal-host' => function( ContainerInterface $container ) : string {
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
/**
|
||||
* The current environment.
|
||||
*
|
||||
|
@ -34,7 +35,7 @@ return array(
|
|||
|
||||
},
|
||||
'api.paypal-website-url' => function( ContainerInterface $container ) : string {
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
if ( $environment->current_environment_is( Environment::SANDBOX ) ) {
|
||||
return $container->get( 'api.paypal-website-url-sandbox' );
|
||||
|
@ -56,9 +57,16 @@ return array(
|
|||
|
||||
return $state->current_state() >= State::STATE_ONBOARDED;
|
||||
},
|
||||
'onboarding.environment' => function( ContainerInterface $container ) : Environment {
|
||||
'settings.flag.is-sandbox' => static function ( ContainerInterface $container ) : bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new Environment( $settings );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
return $settings->has( 'sandbox_on' ) && $settings->get( 'sandbox_on' );
|
||||
},
|
||||
'settings.environment' => function ( ContainerInterface $container ) : Environment {
|
||||
return new Environment(
|
||||
$container->get( 'settings.flag.is-sandbox' )
|
||||
);
|
||||
},
|
||||
|
||||
'onboarding.assets' => function( ContainerInterface $container ) : OnboardingAssets {
|
||||
|
@ -68,7 +76,7 @@ return array(
|
|||
$container->get( 'onboarding.url' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$state,
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$login_seller_endpoint,
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' )
|
||||
);
|
||||
|
|
|
@ -133,9 +133,11 @@ class OnboardingRESTController {
|
|||
* @return array
|
||||
*/
|
||||
public function get_status( $request ) {
|
||||
$environment = $this->container->get( 'onboarding.environment' );
|
||||
$environment = $this->container->get( 'settings.environment' );
|
||||
$state = $this->container->get( 'onboarding.state' );
|
||||
|
||||
// Legacy onboarding module; using `State::STATE_ONBOARDED` checks is valid here.
|
||||
|
||||
return array(
|
||||
'environment' => $environment->current_environment(),
|
||||
'onboarded' => ( $state->current_state() >= State::STATE_ONBOARDED ),
|
||||
|
|
|
@ -95,6 +95,7 @@ class SaveConfig {
|
|||
* @param array $config The configurator config.
|
||||
*/
|
||||
public function save_config( array $config ): void {
|
||||
// TODO new-ux: We should convert this to a new AbstractDataModel class in the settings folder!
|
||||
$this->settings->set( 'pay_later_enable_styling_per_messaging_location', true );
|
||||
$this->settings->set( 'pay_later_messaging_enabled', true );
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
|
|||
function( $subscription ) use ( $c ) {
|
||||
$subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||
if ( $subscription_id ) {
|
||||
$environment = $c->get( 'onboarding.environment' );
|
||||
$environment = $c->get( 'settings.environment' );
|
||||
$host = $environment->current_environment_is( Environment::SANDBOX ) ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
|
||||
?>
|
||||
<tr>
|
||||
|
@ -476,7 +476,7 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
|
|||
return;
|
||||
}
|
||||
|
||||
$environment = $c->get( 'onboarding.environment' );
|
||||
$environment = $c->get( 'settings.environment' );
|
||||
echo '<div class="options_group subscription_pricing show_if_subscription hidden">';
|
||||
$this->render_paypal_subscription_fields( $product, $environment );
|
||||
echo '</div>';
|
||||
|
@ -507,7 +507,7 @@ class PayPalSubscriptionsModule implements ServiceModule, ExtendingModule, Execu
|
|||
return;
|
||||
}
|
||||
|
||||
$environment = $c->get( 'onboarding.environment' );
|
||||
$environment = $c->get( 'settings.environment' );
|
||||
$this->render_paypal_subscription_fields( $product, $environment );
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import { ToggleControl } from '@wordpress/components';
|
||||
import { Action, Description } from '../Elements';
|
||||
|
||||
const ControlToggleButton = ( { label, description, value, onChange } ) => (
|
||||
const ControlToggleButton = ( {
|
||||
label,
|
||||
description,
|
||||
value,
|
||||
onChange,
|
||||
disabled = false,
|
||||
} ) => (
|
||||
<Action>
|
||||
<ToggleControl
|
||||
className="ppcp--control-toggle"
|
||||
|
@ -12,6 +18,7 @@ const ControlToggleButton = ( { label, description, value, onChange } ) => (
|
|||
help={
|
||||
description ? <Description>{ description }</Description> : null
|
||||
}
|
||||
disabled={ disabled }
|
||||
/>
|
||||
</Action>
|
||||
);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { __ } from '@wordpress/i18n';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { ControlToggleButton } from '../../../../../ReusableComponents/Controls';
|
||||
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
|
||||
|
@ -12,6 +13,12 @@ const OrderIntent = () => {
|
|||
setCaptureVirtualOnlyOrders,
|
||||
} = SettingsHooks.useSettings();
|
||||
|
||||
useEffect( () => {
|
||||
if ( ! authorizeOnly && captureVirtualOnlyOrders ) {
|
||||
setCaptureVirtualOnlyOrders( false );
|
||||
}
|
||||
}, [ authorizeOnly ] );
|
||||
|
||||
return (
|
||||
<SettingsBlock
|
||||
title={ __( 'Order Intent', 'woocommerce-paypal-payments' ) }
|
||||
|
@ -34,6 +41,7 @@ const OrderIntent = () => {
|
|||
) }
|
||||
onChange={ setCaptureVirtualOnlyOrders }
|
||||
value={ captureVirtualOnlyOrders }
|
||||
disabled={ ! authorizeOnly }
|
||||
/>
|
||||
</SettingsBlock>
|
||||
);
|
||||
|
|
|
@ -20,13 +20,11 @@ use WooCommerce\PayPalCommerce\Settings\Data\TodosModel;
|
|||
use WooCommerce\PayPalCommerce\Settings\Data\Definition\TodosDefinition;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\CompleteOnClickEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\PayLaterMessagingEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\ResetDismissedTodosEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\SettingsRestEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\StylingRestEndpoint;
|
||||
|
@ -43,6 +41,8 @@ use WooCommerce\PayPalCommerce\Settings\Data\Definition\PaymentMethodsDefinition
|
|||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
|
||||
|
||||
return array(
|
||||
'settings.url' => static function ( ContainerInterface $container ) : string {
|
||||
|
@ -116,13 +116,51 @@ return array(
|
|||
);
|
||||
},
|
||||
/**
|
||||
* Checks if valid merchant connection details are stored in the DB.
|
||||
* Merchant connection details, which includes the connection status
|
||||
* (onboarding/connected) and connection-aware environment checks.
|
||||
* This is the preferred solution to check environment and connection state.
|
||||
*/
|
||||
'settings.flag.is-connected' => static function ( ContainerInterface $container ) : bool {
|
||||
'settings.connection-state' => static function ( ContainerInterface $container ) : ConnectionState {
|
||||
$data = $container->get( 'settings.data.general' );
|
||||
assert( $data instanceof GeneralSettings );
|
||||
|
||||
return $data->is_merchant_connected();
|
||||
$is_connected = $data->is_merchant_connected();
|
||||
$environment = new Environment( $data->is_sandbox_merchant() );
|
||||
|
||||
return new ConnectionState( $is_connected, $environment );
|
||||
},
|
||||
'settings.environment' => static function ( ContainerInterface $container ) : Environment {
|
||||
// We should remove this service in favor of directly using `settings.connection-state`.
|
||||
$state = $container->get( 'settings.connection-state' );
|
||||
assert( $state instanceof ConnectionState );
|
||||
|
||||
return $state->get_environment();
|
||||
},
|
||||
/**
|
||||
* Checks if valid merchant connection details are stored in the DB.
|
||||
*/
|
||||
'settings.flag.is-connected' => static function ( ContainerInterface $container ) : bool {
|
||||
/*
|
||||
* This service only resolves the connection status once per request.
|
||||
* We should remove this service in favor of directly using `settings.connection-state`.
|
||||
*/
|
||||
$state = $container->get( 'settings.connection-state' );
|
||||
assert( $state instanceof ConnectionState );
|
||||
|
||||
return $state->is_connected();
|
||||
},
|
||||
/**
|
||||
* Checks if the merchant is connected to a sandbox environment.
|
||||
*/
|
||||
'settings.flag.is-sandbox' => static function ( ContainerInterface $container ) : bool {
|
||||
/*
|
||||
* This service only resolves the sandbox flag once per request.
|
||||
* We should remove this service in favor of directly using `settings.connection-state`.
|
||||
*/
|
||||
$state = $container->get( 'settings.connection-state' );
|
||||
assert( $state instanceof ConnectionState );
|
||||
|
||||
return $state->is_sandbox();
|
||||
},
|
||||
'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint {
|
||||
return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) );
|
||||
|
@ -268,6 +306,7 @@ return array(
|
|||
$container->get( 'api.env.paypal-host' ),
|
||||
$container->get( 'api.env.endpoint.login-seller' ),
|
||||
$container->get( 'api.repository.partner-referrals-data' ),
|
||||
$container->get( 'settings.connection-state' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -24,6 +24,7 @@ use WooCommerce\WooCommerce\Logging\Logger\NullLogger;
|
|||
use WooCommerce\PayPalCommerce\Settings\DTO\MerchantConnectionDTO;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||
use WooCommerce\PayPalCommerce\Settings\Enum\SellerTypeEnum;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\ConnectionState;
|
||||
|
||||
/**
|
||||
* Class that manages the connection to PayPal.
|
||||
|
@ -64,27 +65,37 @@ class AuthenticationManager {
|
|||
*/
|
||||
private PartnerReferralsData $referrals_data;
|
||||
|
||||
/**
|
||||
* The connection state manager.
|
||||
*
|
||||
* @var ConnectionState
|
||||
*/
|
||||
private ConnectionState $connection_state;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param GeneralSettings $common_settings Data model that stores the connection details.
|
||||
* @param EnvironmentConfig $connection_host API host for direct authentication.
|
||||
* @param EnvironmentConfig $login_endpoint API handler to fetch merchant credentials.
|
||||
* @param PartnerReferralsData $referrals_data Partner referrals data.
|
||||
* @param ?LoggerInterface $logger Logging instance.
|
||||
* @param GeneralSettings $common_settings Data model that stores the connection details.
|
||||
* @param EnvironmentConfig $connection_host API host for direct authentication.
|
||||
* @param EnvironmentConfig $login_endpoint API handler to fetch merchant credentials.
|
||||
* @param PartnerReferralsData $referrals_data Partner referrals data.
|
||||
* @param ConnectionState $connection_state Connection state manager.
|
||||
* @param ?LoggerInterface $logger Logging instance.
|
||||
*/
|
||||
public function __construct(
|
||||
GeneralSettings $common_settings,
|
||||
EnvironmentConfig $connection_host,
|
||||
EnvironmentConfig $login_endpoint,
|
||||
PartnerReferralsData $referrals_data,
|
||||
ConnectionState $connection_state,
|
||||
?LoggerInterface $logger = null
|
||||
) {
|
||||
$this->common_settings = $common_settings;
|
||||
$this->connection_host = $connection_host;
|
||||
$this->login_endpoint = $login_endpoint;
|
||||
$this->referrals_data = $referrals_data;
|
||||
$this->logger = $logger ?: new NullLogger();
|
||||
$this->common_settings = $common_settings;
|
||||
$this->connection_host = $connection_host;
|
||||
$this->login_endpoint = $login_endpoint;
|
||||
$this->referrals_data = $referrals_data;
|
||||
$this->connection_state = $connection_state;
|
||||
$this->logger = $logger ?: new NullLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +123,9 @@ class AuthenticationManager {
|
|||
$this->common_settings->reset_merchant_data();
|
||||
$this->common_settings->save();
|
||||
|
||||
// Update the connection status and clear the environment flags.
|
||||
$this->connection_state->disconnect();
|
||||
|
||||
/**
|
||||
* Broadcast, that the plugin disconnected from PayPal. This allows other
|
||||
* modules to clean up merchant-related details, such as eligibility flags.
|
||||
|
@ -420,6 +434,9 @@ class AuthenticationManager {
|
|||
if ( $this->common_settings->is_merchant_connected() ) {
|
||||
$this->logger->info( 'Merchant successfully connected to PayPal' );
|
||||
|
||||
// Update the connection status and set the environment flags.
|
||||
$this->connection_state->connect( $connection->is_sandbox );
|
||||
|
||||
/**
|
||||
* Request to flush caches before authenticating the merchant, to
|
||||
* ensure the new merchant does not use stale data from previous
|
||||
|
|
|
@ -21,7 +21,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Compat\PPEC\PPECHelper;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\WebhookEventStorage;
|
||||
|
||||
/**
|
||||
|
@ -58,8 +57,8 @@ class StatusReportModule implements ServiceModule, ExtendingModule, ExecutableMo
|
|||
|
||||
$subscriptions_mode_settings = $c->get( 'wcgateway.settings.fields.subscriptions_mode' ) ?: array();
|
||||
|
||||
/* @var State $state The state. */
|
||||
$state = $c->get( 'onboarding.state' );
|
||||
/* @var bool $is_connected Whether onboarding is complete. */
|
||||
$is_connected = $c->get( 'settings.flag.is-connected' );
|
||||
|
||||
/* @var Bearer $bearer The bearer. */
|
||||
$bearer = $c->get( 'api.bearer' );
|
||||
|
@ -92,7 +91,7 @@ class StatusReportModule implements ServiceModule, ExtendingModule, ExecutableMo
|
|||
'exported_label' => 'Onboarded',
|
||||
'description' => esc_html__( 'Whether PayPal account is correctly configured or not.', 'woocommerce-paypal-payments' ),
|
||||
'value' => $this->bool_to_html(
|
||||
$this->onboarded( $bearer, $state )
|
||||
$this->onboarded( $bearer, $is_connected )
|
||||
),
|
||||
),
|
||||
array(
|
||||
|
@ -230,19 +229,18 @@ class StatusReportModule implements ServiceModule, ExtendingModule, ExecutableMo
|
|||
/**
|
||||
* It returns the current onboarding status.
|
||||
*
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param State $state The state.
|
||||
* @param Bearer $bearer The bearer.
|
||||
* @param bool $is_connected Whether onboarding is complete.
|
||||
* @return bool
|
||||
*/
|
||||
private function onboarded( Bearer $bearer, State $state ): bool {
|
||||
private function onboarded( Bearer $bearer, bool $is_connected ): bool {
|
||||
try {
|
||||
$token = $bearer->bearer();
|
||||
} catch ( RuntimeException $exception ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current_state = $state->current_state();
|
||||
return $token->is_valid() && $current_state === $state::STATE_ONBOARDED;
|
||||
return $is_connected && $token->is_valid();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ return array(
|
|||
$container->get( 'api.factory.payer' ),
|
||||
$container->get( 'api.factory.shipping-preference' ),
|
||||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'wcgateway.processor.authorized-payments' ),
|
||||
$container->get( 'wcgateway.settings' )
|
||||
);
|
||||
|
|
|
@ -26,7 +26,7 @@ return array(
|
|||
return $settings->has( 'merchant_id' ) ? (string) $settings->get( 'merchant_id' ) : '';
|
||||
},
|
||||
'api.partner_merchant_id' => static function ( string $previous, ContainerInterface $container ): string {
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
|
||||
/**
|
||||
* The environment.
|
||||
|
|
|
@ -87,35 +87,21 @@ use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
|||
|
||||
return array(
|
||||
'wcgateway.paypal-gateway' => static function ( ContainerInterface $container ): PayPalGateway {
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$settings_renderer = $container->get( 'wcgateway.settings.render' );
|
||||
$funding_source_renderer = $container->get( 'wcgateway.funding-source.renderer' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$refund_processor = $container->get( 'wcgateway.processor.refunds' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$transaction_url_provider = $container->get( 'wcgateway.transaction-url-provider' );
|
||||
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
|
||||
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
|
||||
$payment_token_repository = $container->get( 'vaulting.repository.payment-token' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$api_shop_country = $container->get( 'api.shop.country' );
|
||||
return new PayPalGateway(
|
||||
$settings_renderer,
|
||||
$funding_source_renderer,
|
||||
$order_processor,
|
||||
$settings,
|
||||
$session_handler,
|
||||
$refund_processor,
|
||||
$state,
|
||||
$transaction_url_provider,
|
||||
$subscription_helper,
|
||||
$page_id,
|
||||
$environment,
|
||||
$payment_token_repository,
|
||||
$logger,
|
||||
$api_shop_country,
|
||||
$container->get( 'wcgateway.settings.render' ),
|
||||
$container->get( 'wcgateway.funding-source.renderer' ),
|
||||
$container->get( 'wcgateway.order-processor' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'wc-subscriptions.helper' ),
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'vaulting.repository.payment-token' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'api.shop.country' ),
|
||||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'api.factory.paypal-checkout-url' ),
|
||||
$container->get( 'wcgateway.place-order-button-text' ),
|
||||
|
@ -127,42 +113,26 @@ return array(
|
|||
);
|
||||
},
|
||||
'wcgateway.credit-card-gateway' => static function ( ContainerInterface $container ): CreditCardGateway {
|
||||
$order_processor = $container->get( 'wcgateway.order-processor' );
|
||||
$settings_renderer = $container->get( 'wcgateway.settings.render' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$dcc_configuration = $container->get( 'wcgateway.configuration.dcc' );
|
||||
$module_url = $container->get( 'wcgateway.url' );
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$refund_processor = $container->get( 'wcgateway.processor.refunds' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$transaction_url_provider = $container->get( 'wcgateway.transaction-url-provider' );
|
||||
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
|
||||
$payments_endpoint = $container->get( 'api.endpoint.payments' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$vaulted_credit_card_handler = $container->get( 'vaulting.credit-card-handler' );
|
||||
$icons = $container->get( 'wcgateway.credit-card-icons' );
|
||||
|
||||
return new CreditCardGateway(
|
||||
$settings_renderer,
|
||||
$order_processor,
|
||||
$settings,
|
||||
$dcc_configuration,
|
||||
$icons,
|
||||
$module_url,
|
||||
$session_handler,
|
||||
$refund_processor,
|
||||
$state,
|
||||
$transaction_url_provider,
|
||||
$subscription_helper,
|
||||
$payments_endpoint,
|
||||
$vaulted_credit_card_handler,
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'wcgateway.settings.render' ),
|
||||
$container->get( 'wcgateway.order-processor' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.configuration.dcc' ),
|
||||
$container->get( 'wcgateway.credit-card-icons' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'wc-subscriptions.helper' ),
|
||||
$container->get( 'api.endpoint.payments' ),
|
||||
$container->get( 'vaulting.credit-card-handler' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'api.endpoint.order' ),
|
||||
$container->get( 'wcgateway.endpoint.capture-card-payment' ),
|
||||
$container->get( 'api.prefix' ),
|
||||
$container->get( 'api.endpoint.payment-tokens' ),
|
||||
$container->get( 'vaulting.wc-payment-tokens' ),
|
||||
$logger
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
'wcgateway.credit-card-labels' => static function ( ContainerInterface $container ) : array {
|
||||
|
@ -234,11 +204,11 @@ return array(
|
|||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'session.handler' ),
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'wc-subscriptions.helper' ),
|
||||
$container->get( 'wcgateway.settings.allow_card_button_gateway.default' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'vaulting.repository.payment-token' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'api.factory.paypal-checkout-url' ),
|
||||
|
@ -321,10 +291,9 @@ return array(
|
|||
$section = isset( $_GET['section'] ) ? sanitize_text_field( wp_unslash( $_GET['section'] ) ) : '';
|
||||
$ppcp_tab = isset( $_GET[ SectionsRenderer::KEY ] ) ? sanitize_text_field( wp_unslash( $_GET[ SectionsRenderer::KEY ] ) ) : '';
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
assert( $state instanceof State );
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
|
||||
if ( ! $ppcp_tab && PayPalGateway::ID === $section && $state->current_state() !== State::STATE_ONBOARDED ) {
|
||||
if ( ! $ppcp_tab && PayPalGateway::ID === $section && ! $is_connected ) {
|
||||
return Settings::CONNECTION_TAB_ID;
|
||||
}
|
||||
|
||||
|
@ -343,29 +312,25 @@ return array(
|
|||
}
|
||||
),
|
||||
'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$is_current_country_send_only = $container->get( 'wcgateway.is-send-only-country' );
|
||||
return new ConnectAdminNotice( $state, $settings, $is_current_country_send_only );
|
||||
return new ConnectAdminNotice(
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.is-send-only-country' )
|
||||
);
|
||||
},
|
||||
'wcgateway.notice.currency-unsupported' => static function ( ContainerInterface $container ): UnsupportedCurrencyAdminNotice {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$shop_currency = $container->get( 'api.shop.currency.getter' );
|
||||
$supported_currencies = $container->get( 'api.supported-currencies' );
|
||||
$is_wc_gateways_list_page = $container->get( 'wcgateway.is-wc-gateways-list-page' );
|
||||
$is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
|
||||
return new UnsupportedCurrencyAdminNotice(
|
||||
$state,
|
||||
$shop_currency,
|
||||
$supported_currencies,
|
||||
$is_wc_gateways_list_page,
|
||||
$is_ppcp_settings_page
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'api.shop.currency.getter' ),
|
||||
$container->get( 'api.supported-currencies' ),
|
||||
$container->get( 'wcgateway.is-wc-gateways-list-page' ),
|
||||
$container->get( 'wcgateway.is-ppcp-settings-page' )
|
||||
);
|
||||
},
|
||||
'wcgateway.notice.dcc-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
|
||||
return new GatewayWithoutPayPalAdminNotice(
|
||||
CreditCardGateway::ID,
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.is-wc-payments-page' ),
|
||||
$container->get( 'wcgateway.is-ppcp-settings-page' )
|
||||
|
@ -374,7 +339,7 @@ return array(
|
|||
'wcgateway.notice.card-button-without-paypal' => static function ( ContainerInterface $container ): GatewayWithoutPayPalAdminNotice {
|
||||
return new GatewayWithoutPayPalAdminNotice(
|
||||
CardButtonGateway::ID,
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.is-wc-payments-page' ),
|
||||
$container->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
|
@ -477,14 +442,12 @@ return array(
|
|||
return in_array( $store_country, $send_only_countries, true );
|
||||
},
|
||||
'wcgateway.notice.send-only-country' => static function ( ContainerInterface $container ) {
|
||||
$onboarding_state = $container->get( 'onboarding.state' );
|
||||
assert( $onboarding_state instanceof State );
|
||||
return new SendOnlyCountryNotice(
|
||||
$container->get( 'wcgateway.send-only-message' ),
|
||||
$container->get( 'wcgateway.is-send-only-country' ),
|
||||
$container->get( 'wcgateway.is-ppcp-settings-page' ),
|
||||
$container->get( 'wcgateway.is-wc-gateways-list-page' ),
|
||||
$onboarding_state->current_state()
|
||||
$container->get( 'settings.flag.is-connected' )
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -527,7 +490,7 @@ return array(
|
|||
'wcgateway.settings.sections-renderer' => static function ( ContainerInterface $container ): SectionsRenderer {
|
||||
return new SectionsRenderer(
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.helper.dcc-product-status' ),
|
||||
$container->get( 'api.helpers.dccapplies' ),
|
||||
$container->get( 'button.helper.messages-apply' ),
|
||||
|
@ -545,57 +508,36 @@ return array(
|
|||
return new SettingsStatus( $settings );
|
||||
},
|
||||
'wcgateway.settings.render' => static function ( ContainerInterface $container ): SettingsRenderer {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
$dcc_applies = $container->get( 'api.helpers.dccapplies' );
|
||||
$messages_apply = $container->get( 'button.helper.messages-apply' );
|
||||
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
|
||||
$settings_status = $container->get( 'wcgateway.settings.status' );
|
||||
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
|
||||
$api_shop_country = $container->get( 'api.shop.country' );
|
||||
return new SettingsRenderer(
|
||||
$settings,
|
||||
$state,
|
||||
$fields,
|
||||
$dcc_applies,
|
||||
$messages_apply,
|
||||
$dcc_product_status,
|
||||
$settings_status,
|
||||
$page_id,
|
||||
$api_shop_country
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'onboarding.state' ), // Correct.
|
||||
$container->get( 'wcgateway.settings.fields' ),
|
||||
$container->get( 'api.helpers.dccapplies' ),
|
||||
$container->get( 'button.helper.messages-apply' ),
|
||||
$container->get( 'wcgateway.helper.dcc-product-status' ),
|
||||
$container->get( 'wcgateway.settings.status' ),
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'api.shop.country' )
|
||||
);
|
||||
},
|
||||
'wcgateway.settings.listener' => static function ( ContainerInterface $container ): SettingsListener {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$fields = $container->get( 'wcgateway.settings.fields' );
|
||||
$webhook_registrar = $container->get( 'webhook.registrar' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
$cache = $container->get( 'api.paypal-bearer-cache' );
|
||||
$bearer = $container->get( 'api.bearer' );
|
||||
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
|
||||
$signup_link_cache = $container->get( 'onboarding.signup-link-cache' );
|
||||
$signup_link_ids = $container->get( 'onboarding.signup-link-ids' );
|
||||
$pui_status_cache = $container->get( 'pui.status-cache' );
|
||||
$dcc_status_cache = $container->get( 'dcc.status-cache' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
return new SettingsListener(
|
||||
$settings,
|
||||
$fields,
|
||||
$webhook_registrar,
|
||||
$cache,
|
||||
$state,
|
||||
$bearer,
|
||||
$page_id,
|
||||
$signup_link_cache,
|
||||
$signup_link_ids,
|
||||
$pui_status_cache,
|
||||
$dcc_status_cache,
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.settings.fields' ),
|
||||
$container->get( 'webhook.registrar' ),
|
||||
$container->get( 'api.paypal-bearer-cache' ),
|
||||
$container->get( 'onboarding.state' ), // Correct.
|
||||
$container->get( 'api.bearer' ),
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'onboarding.signup-link-cache' ),
|
||||
$container->get( 'onboarding.signup-link-ids' ),
|
||||
$container->get( 'pui.status-cache' ),
|
||||
$container->get( 'dcc.status-cache' ),
|
||||
$container->get( 'http.redirector' ),
|
||||
$container->get( 'api.partner_merchant_id-production' ),
|
||||
$container->get( 'api.partner_merchant_id-sandbox' ),
|
||||
$container->get( 'api.endpoint.billing-agreements' ),
|
||||
$logger,
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
new Cache( 'ppcp-client-credentials-cache' )
|
||||
);
|
||||
},
|
||||
|
@ -607,7 +549,7 @@ return array(
|
|||
$threed_secure = $container->get( 'button.helper.three-d-secure' );
|
||||
$authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||
$subscription_helper = $container->get( 'wc-subscriptions.helper' );
|
||||
$order_helper = $container->get( 'api.order-helper' );
|
||||
|
@ -728,6 +670,8 @@ return array(
|
|||
return array();
|
||||
}
|
||||
|
||||
// Legacy settings service, correct use of `State` class.
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
assert( $state instanceof State );
|
||||
|
||||
|
@ -1485,12 +1429,12 @@ return array(
|
|||
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
|
||||
$container->get( 'api.factory.purchase-unit' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-payment-source-factory' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||
$container->get( 'wcgateway.checkout-helper' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.processor.refunds' ),
|
||||
$container->get( 'wcgateway.url' )
|
||||
);
|
||||
|
@ -1524,7 +1468,7 @@ return array(
|
|||
$container->get( 'wcgateway.pay-upon-invoice-order-endpoint' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'onboarding.state' ),
|
||||
$container->get( 'settings.flag.is-connected' ),
|
||||
$container->get( 'wcgateway.current-ppcp-settings-page-id' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-product-status' ),
|
||||
$container->get( 'wcgateway.pay-upon-invoice-helper' ),
|
||||
|
@ -1549,7 +1493,7 @@ return array(
|
|||
$container->get( 'api.factory.shipping-preference' ),
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.transaction-url-provider' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' )
|
||||
);
|
||||
},
|
||||
|
@ -1717,15 +1661,15 @@ return array(
|
|||
return 'https://www.paypal.com/bizsignup/entry?product=ADVANCED_VAULTING';
|
||||
},
|
||||
'wcgateway.settings.connection.dcc-status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$dcc_product_status = $container->get( 'wcgateway.helper.dcc-product-status' );
|
||||
assert( $dcc_product_status instanceof DCCProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$dcc_enabled = $dcc_product_status->is_active();
|
||||
|
@ -1755,7 +1699,7 @@ return array(
|
|||
);
|
||||
},
|
||||
'wcgateway.settings.connection.reference-transactions-status-text' => static function ( ContainerInterface $container ): string {
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$billing_agreements_endpoint = $container->get( 'api.endpoint.billing-agreements' );
|
||||
|
@ -1788,15 +1732,15 @@ return array(
|
|||
);
|
||||
},
|
||||
'wcgateway.settings.connection.pui-status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
if ( ! $is_connected ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pui_product_status = $container->get( 'wcgateway.pay-upon-invoice-product-status' );
|
||||
assert( $pui_product_status instanceof PayUponInvoiceProductStatus );
|
||||
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
assert( $environment instanceof Environment );
|
||||
|
||||
$pui_enabled = $pui_product_status->is_active();
|
||||
|
@ -1917,7 +1861,7 @@ return array(
|
|||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'wcgateway.fraudnet' ),
|
||||
$container->get( 'onboarding.environment' ),
|
||||
$container->get( 'settings.environment' ),
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'wcgateway.gateway-repository' ),
|
||||
$container->get( 'session.handler' ),
|
||||
|
|
|
@ -62,6 +62,7 @@ class SettingsCommand {
|
|||
$value = false;
|
||||
}
|
||||
|
||||
// TODO new-ux: The setting must also be updated in the new settings.
|
||||
$this->settings->set( $key, $value );
|
||||
$this->settings->persist();
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ use Psr\Log\LoggerInterface;
|
|||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\FreeTrialHandlerTrait;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||
|
@ -70,13 +69,6 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
private $refund_processor;
|
||||
|
||||
/**
|
||||
* The state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Service able to provide transaction url for an order.
|
||||
*
|
||||
|
@ -141,7 +133,7 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
* @param ContainerInterface $config The settings.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||
* @param State $state The state.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param bool $default_enabled Whether the gateway should be enabled by default.
|
||||
|
@ -157,7 +149,7 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
ContainerInterface $config,
|
||||
SessionHandler $session_handler,
|
||||
RefundProcessor $refund_processor,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
TransactionUrlProvider $transaction_url_provider,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
bool $default_enabled,
|
||||
|
@ -173,12 +165,11 @@ class CardButtonGateway extends \WC_Payment_Gateway {
|
|||
$this->config = $config;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->refund_processor = $refund_processor;
|
||||
$this->state = $state;
|
||||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->default_enabled = $default_enabled;
|
||||
$this->environment = $environment;
|
||||
$this->onboarded = $state->current_state() === State::STATE_ONBOARDED;
|
||||
$this->onboarded = $is_connected;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->logger = $logger;
|
||||
$this->paypal_checkout_url_factory = $paypal_checkout_url_factory;
|
||||
|
|
|
@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentTokensEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\PaymentTokenRepository;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\VaultedCreditCardHandler;
|
||||
|
@ -109,13 +108,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
*/
|
||||
private $refund_processor;
|
||||
|
||||
/**
|
||||
* The state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Service to get transaction url for an order.
|
||||
*
|
||||
|
@ -204,7 +196,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
* @param string $module_url The URL to the module.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param RefundProcessor $refund_processor The refund processor.
|
||||
* @param State $state The state.
|
||||
* @param TransactionUrlProvider $transaction_url_provider Service able to provide view transaction url base.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param PaymentsEndpoint $payments_endpoint The payments endpoint.
|
||||
|
@ -226,7 +217,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
string $module_url,
|
||||
SessionHandler $session_handler,
|
||||
RefundProcessor $refund_processor,
|
||||
State $state,
|
||||
TransactionUrlProvider $transaction_url_provider,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
PaymentsEndpoint $payments_endpoint,
|
||||
|
@ -247,7 +237,6 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
|
|||
$this->module_url = $module_url;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->refund_processor = $refund_processor;
|
||||
$this->state = $state;
|
||||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->payments_endpoint = $payments_endpoint;
|
||||
|
|
|
@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Session\SessionHandler;
|
||||
use WooCommerce\PayPalCommerce\Vaulting\WooCommercePaymentTokens;
|
||||
use WooCommerce\PayPalCommerce\WcSubscriptions\FreeTrialHandlerTrait;
|
||||
|
@ -104,13 +103,6 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*/
|
||||
private $refund_processor;
|
||||
|
||||
/**
|
||||
* The state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Service able to provide transaction url for an order.
|
||||
*
|
||||
|
@ -137,7 +129,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $onboarded;
|
||||
private bool $onboarded;
|
||||
|
||||
/**
|
||||
* ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
|
@ -225,7 +217,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
* @param ContainerInterface $config The settings.
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param RefundProcessor $refund_processor The Refund Processor.
|
||||
* @param State $state The state.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param TransactionUrlProvider $transaction_url_provider Service providing transaction view URL based on order.
|
||||
* @param SubscriptionHelper $subscription_helper The subscription helper.
|
||||
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
|
@ -249,7 +241,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
ContainerInterface $config,
|
||||
SessionHandler $session_handler,
|
||||
RefundProcessor $refund_processor,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
TransactionUrlProvider $transaction_url_provider,
|
||||
SubscriptionHelper $subscription_helper,
|
||||
string $page_id,
|
||||
|
@ -273,12 +265,11 @@ class PayPalGateway extends \WC_Payment_Gateway {
|
|||
$this->config = $config;
|
||||
$this->session_handler = $session_handler;
|
||||
$this->refund_processor = $refund_processor;
|
||||
$this->state = $state;
|
||||
$this->transaction_url_provider = $transaction_url_provider;
|
||||
$this->subscription_helper = $subscription_helper;
|
||||
$this->page_id = $page_id;
|
||||
$this->environment = $environment;
|
||||
$this->onboarded = $state->current_state() === State::STATE_ONBOARDED;
|
||||
$this->onboarded = $is_connected;
|
||||
$this->payment_token_repository = $payment_token_repository;
|
||||
$this->logger = $logger;
|
||||
$this->api_shop_country = $api_shop_country;
|
||||
|
|
|
@ -19,7 +19,6 @@ use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceProductStatus;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Processor\TransactionIdHandlingTrait;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
|
@ -62,11 +61,11 @@ class PayUponInvoice {
|
|||
protected $pui_helper;
|
||||
|
||||
/**
|
||||
* The onboarding state.
|
||||
* Whether onboarding was completed and the merchant is connected to PayPal.
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
protected $state;
|
||||
protected bool $is_connected;
|
||||
|
||||
/**
|
||||
* Current PayPal settings page id.
|
||||
|
@ -102,7 +101,7 @@ class PayUponInvoice {
|
|||
* @param PayUponInvoiceOrderEndpoint $pui_order_endpoint The PUI order endpoint.
|
||||
* @param LoggerInterface $logger The logger.
|
||||
* @param Settings $settings The settings.
|
||||
* @param State $state The onboarding state.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param string $current_ppcp_settings_page_id Current PayPal settings page id.
|
||||
* @param PayUponInvoiceProductStatus $pui_product_status The PUI product status.
|
||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||
|
@ -113,7 +112,7 @@ class PayUponInvoice {
|
|||
PayUponInvoiceOrderEndpoint $pui_order_endpoint,
|
||||
LoggerInterface $logger,
|
||||
Settings $settings,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
string $current_ppcp_settings_page_id,
|
||||
PayUponInvoiceProductStatus $pui_product_status,
|
||||
PayUponInvoiceHelper $pui_helper,
|
||||
|
@ -123,7 +122,7 @@ class PayUponInvoice {
|
|||
$this->pui_order_endpoint = $pui_order_endpoint;
|
||||
$this->logger = $logger;
|
||||
$this->settings = $settings;
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->current_ppcp_settings_page_id = $current_ppcp_settings_page_id;
|
||||
$this->pui_product_status = $pui_product_status;
|
||||
$this->pui_helper = $pui_helper;
|
||||
|
@ -138,6 +137,10 @@ class PayUponInvoice {
|
|||
*/
|
||||
public function init(): void {
|
||||
if ( $this->pui_helper->is_pui_gateway_enabled() ) {
|
||||
/*
|
||||
* TODO new-ux: Check if we still support this setting, or if it's always enabled.
|
||||
* If fraudnet is not configurable in new UI, we can ignore this.
|
||||
*/
|
||||
$this->settings->set( 'fraudnet_enabled', true );
|
||||
$this->settings->persist();
|
||||
}
|
||||
|
@ -437,7 +440,7 @@ class PayUponInvoice {
|
|||
function ( $methods ) {
|
||||
if (
|
||||
! is_array( $methods )
|
||||
|| State::STATE_ONBOARDED !== $this->state->current_state()
|
||||
|| ! $this->is_connected
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|| ! ( is_checkout() || isset( $_GET['pay_for_order'] ) && $_GET['pay_for_order'] === 'true' )
|
||||
) {
|
||||
|
|
|
@ -17,7 +17,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\Environment;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\TransactionUrlProvider;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\CheckoutHelper;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
|
||||
|
@ -89,13 +88,6 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
*/
|
||||
protected $checkout_helper;
|
||||
|
||||
/**
|
||||
* The onboarding state.
|
||||
*
|
||||
* @var State
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The refund processor.
|
||||
*
|
||||
|
@ -121,7 +113,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
* @param LoggerInterface $logger The logger.
|
||||
* @param PayUponInvoiceHelper $pui_helper The PUI helper.
|
||||
* @param CheckoutHelper $checkout_helper The checkout helper.
|
||||
* @param State $state The onboarding state.
|
||||
* @param bool $is_connected Whether the onboarding was completed.
|
||||
* @param RefundProcessor $refund_processor The refund processor.
|
||||
* @param string $module_url The module URL.
|
||||
*/
|
||||
|
@ -134,7 +126,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
LoggerInterface $logger,
|
||||
PayUponInvoiceHelper $pui_helper,
|
||||
CheckoutHelper $checkout_helper,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
RefundProcessor $refund_processor,
|
||||
string $module_url
|
||||
) {
|
||||
|
@ -169,8 +161,7 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
|||
$this->module_url = $module_url;
|
||||
$this->icon = apply_filters( 'woocommerce_paypal_payments_pay_upon_invoice_gateway_icon', esc_url( $this->module_url ) . 'assets/images/ratepay.svg' );
|
||||
|
||||
$this->state = $state;
|
||||
if ( $state->current_state() === State::STATE_ONBOARDED ) {
|
||||
if ( $is_connected ) {
|
||||
$this->supports = array( 'refunds' );
|
||||
}
|
||||
$this->refund_processor = $refund_processor;
|
||||
|
|
135
modules/ppcp-wc-gateway/src/Helper/ConnectionState.php
Normal file
135
modules/ppcp-wc-gateway/src/Helper/ConnectionState.php
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
/**
|
||||
* Describes the current API connection state (connected vs onboarding).
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
|
||||
*/
|
||||
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
|
||||
|
||||
/**
|
||||
* Class ConnectionState
|
||||
*
|
||||
* Manages the merchants' connection status details and provides inspection
|
||||
* methods to describe the current state.
|
||||
*/
|
||||
class ConnectionState {
|
||||
/**
|
||||
* The connection status.
|
||||
*
|
||||
* A merchant can be either "connected" (true) or "onboarding" (false).
|
||||
* During the "onboarding" phase, the environment is undefined.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The environment instance, which is managed by this class because it's
|
||||
* hierarchically coupled to the connection status: Only connected merchants
|
||||
* have a defined environment.
|
||||
*
|
||||
* @var Environment
|
||||
*/
|
||||
private Environment $environment;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param bool $is_connected Initial connection status.
|
||||
* @param Environment $environment The environment instance.
|
||||
*/
|
||||
public function __construct( bool $is_connected, Environment $environment ) {
|
||||
$this->is_connected = $is_connected;
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection status to "connected to PayPal" (end onboarding).
|
||||
*
|
||||
* @param bool $is_sandbox Whether to connect to a sandbox environment.
|
||||
*/
|
||||
public function connect( bool $is_sandbox = false ) : void {
|
||||
if ( ! $this->is_connected ) {
|
||||
/**
|
||||
* Action that fires before the connection status changes from
|
||||
* disconnected to connected.
|
||||
*/
|
||||
do_action( 'woocommerce_paypal_payments_merchant_connection_change', true );
|
||||
}
|
||||
|
||||
$this->is_connected = true;
|
||||
$this->environment->set_environment( $is_sandbox );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection status to "not connected to PayPal" (start onboarding).
|
||||
*/
|
||||
public function disconnect() : void {
|
||||
if ( $this->is_connected ) {
|
||||
/**
|
||||
* Action that fires before the connection status changes from
|
||||
* connected to disconnected.
|
||||
*/
|
||||
do_action( 'woocommerce_paypal_payments_merchant_connection_change', false );
|
||||
}
|
||||
|
||||
$this->is_connected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the managed environment instance.
|
||||
*
|
||||
* @return Environment The environment instance.
|
||||
*/
|
||||
public function get_environment() : Environment {
|
||||
return $this->environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the merchant connected to a PayPal account?
|
||||
*
|
||||
* @return bool True, if onboarding was completed and connection details are present.
|
||||
*/
|
||||
public function is_connected() : bool {
|
||||
return $this->is_connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the merchant currently in the "onboarding phase"?
|
||||
*
|
||||
* @return bool True, if we don't know merchant connection details.
|
||||
*/
|
||||
public function is_onboarding() : bool {
|
||||
return ! $this->is_connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the merchant connected to a sandbox environment?
|
||||
*
|
||||
* @return bool True, if connected to a sandbox environment.
|
||||
*/
|
||||
public function is_sandbox() : bool {
|
||||
return $this->is_connected && $this->environment->is_sandbox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the merchant connected to a production environment and can receive payments?
|
||||
*
|
||||
* @return bool True, if connected to a production environment.
|
||||
*/
|
||||
public function is_production() : bool {
|
||||
return $this->is_connected && $this->environment->is_production();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current environment's name.
|
||||
*
|
||||
* @return string Name of the currently connected environment; empty string if not connected.
|
||||
*/
|
||||
public function current_environment() : string {
|
||||
return $this->is_connected ? $this->environment->current_environment() : '';
|
||||
}
|
||||
}
|
|
@ -103,6 +103,7 @@ class DCCProductStatus extends ProductStatus {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Settings used as a cache; `settings->set` is compatible with new UI.
|
||||
if ( in_array( 'CUSTOM_CARD_PROCESSING', $product->capabilities(), true ) ) {
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
|
|
@ -9,8 +9,6 @@ declare( strict_types = 1 );
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class Environment
|
||||
*/
|
||||
|
@ -27,36 +25,73 @@ class Environment {
|
|||
public const SANDBOX = 'sandbox';
|
||||
|
||||
/**
|
||||
* The Settings.
|
||||
* Name of the current environment.
|
||||
*
|
||||
* @var ContainerInterface
|
||||
* @var string
|
||||
*/
|
||||
private ContainerInterface $settings;
|
||||
private string $environment_name;
|
||||
|
||||
/**
|
||||
* Environment constructor.
|
||||
*
|
||||
* @param ContainerInterface $settings The settings.
|
||||
* @param bool $is_sandbox Whether this instance represents a sandbox environment.
|
||||
*/
|
||||
public function __construct( ContainerInterface $settings ) {
|
||||
$this->settings = $settings;
|
||||
public function __construct( bool $is_sandbox = false ) {
|
||||
$this->environment_name = $this->prepare_environment_name( $is_sandbox );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current environment.
|
||||
* Returns a valid environment name based on the provided argument.
|
||||
*
|
||||
* @param bool $is_sandbox Whether this instance represents a sandbox environment.
|
||||
* @return string The environment name.
|
||||
*/
|
||||
private function prepare_environment_name( bool $is_sandbox ) : string {
|
||||
if ( $is_sandbox ) {
|
||||
return self::SANDBOX;
|
||||
}
|
||||
|
||||
return self::PRODUCTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current environment.
|
||||
*
|
||||
* @param bool $is_sandbox Whether this instance represents a sandbox environment.
|
||||
*/
|
||||
public function set_environment( bool $is_sandbox ) : void {
|
||||
$new_environment = $this->prepare_environment_name( $is_sandbox );
|
||||
|
||||
if ( $new_environment !== $this->environment_name ) {
|
||||
/**
|
||||
* Action that fires before the environment status changes.
|
||||
*
|
||||
* @param string $new_environment The new environment name.
|
||||
* @param string $old_environment The previous environment name.
|
||||
*/
|
||||
do_action(
|
||||
'woocommerce_paypal_payments_merchant_environment_change',
|
||||
$new_environment,
|
||||
$this->environment_name
|
||||
);
|
||||
}
|
||||
|
||||
$this->environment_name = $new_environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current environment's name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function current_environment() : string {
|
||||
return (
|
||||
$this->settings->has( 'sandbox_on' ) && $this->settings->get( 'sandbox_on' )
|
||||
) ? self::SANDBOX : self::PRODUCTION;
|
||||
return $this->environment_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether the current environment equals $environment
|
||||
*
|
||||
* @deprecated Use the is_sandbox() and is_production() methods instead.
|
||||
* @deprecated 3.0.0 - Use the is_sandbox() and is_production() methods instead.
|
||||
* These methods provide better encapsulation, are less error-prone,
|
||||
* and improve code readability by removing the need to pass environment constants.
|
||||
* @param string $environment The value to check against.
|
||||
|
|
|
@ -96,6 +96,7 @@ class PayUponInvoiceProductStatus extends ProductStatus {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Settings used as a cache; `settings->set` is compatible with new UI.
|
||||
if ( in_array( 'PAY_UPON_INVOICE', $product->capabilities(), true ) ) {
|
||||
$this->settings->set( self::SETTINGS_KEY, self::SETTINGS_VALUE_ENABLED );
|
||||
$this->settings->persist();
|
||||
|
|
|
@ -10,7 +10,6 @@ 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;
|
||||
|
||||
|
@ -20,11 +19,11 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|||
class ConnectAdminNotice {
|
||||
|
||||
/**
|
||||
* The state.
|
||||
* Whether the merchant completed the onboarding and is connected to PayPal.
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
|
@ -43,12 +42,16 @@ class ConnectAdminNotice {
|
|||
/**
|
||||
* ConnectAdminNotice constructor.
|
||||
*
|
||||
* @param State $state The state.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
* @param ContainerInterface $settings The settings.
|
||||
* @param bool $is_current_country_send_only Whether the current store's country is classified as a send-only country.
|
||||
*/
|
||||
public function __construct( State $state, ContainerInterface $settings, bool $is_current_country_send_only ) {
|
||||
$this->state = $state;
|
||||
public function __construct(
|
||||
bool $is_connected,
|
||||
ContainerInterface $settings,
|
||||
bool $is_current_country_send_only
|
||||
) {
|
||||
$this->is_connected = $is_connected;
|
||||
$this->settings = $settings;
|
||||
$this->is_current_country_send_only = $is_current_country_send_only;
|
||||
}
|
||||
|
@ -77,9 +80,13 @@ class ConnectAdminNotice {
|
|||
/**
|
||||
* Whether the message should display.
|
||||
*
|
||||
* Only display the "almost ready" message for merchants that did not complete
|
||||
* the onboarding wizard. Also, ensure their store country is eligible for
|
||||
* collecting PayPal payments.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function should_display(): bool {
|
||||
return $this->state->current_state() !== State::STATE_ONBOARDED && $this->is_current_country_send_only === false;
|
||||
return ! $this->is_connected && ! $this->is_current_country_send_only;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
|
|||
|
||||
use WC_Payment_Gateway;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
||||
|
||||
|
@ -32,11 +31,11 @@ class GatewayWithoutPayPalAdminNotice {
|
|||
private $id;
|
||||
|
||||
/**
|
||||
* The state.
|
||||
* Whether the merchant completed onboarding.
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The settings.
|
||||
|
@ -70,7 +69,7 @@ class GatewayWithoutPayPalAdminNotice {
|
|||
* ConnectAdminNotice constructor.
|
||||
*
|
||||
* @param string $id The gateway ID.
|
||||
* @param State $state The state.
|
||||
* @param bool $is_connected Whether onboading was completed.
|
||||
* @param ContainerInterface $settings The settings.
|
||||
* @param bool $is_payments_page Whether the current page is the WC payment page.
|
||||
* @param bool $is_ppcp_settings_page Whether the current page is the PPCP settings page.
|
||||
|
@ -78,14 +77,14 @@ class GatewayWithoutPayPalAdminNotice {
|
|||
*/
|
||||
public function __construct(
|
||||
string $id,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
ContainerInterface $settings,
|
||||
bool $is_payments_page,
|
||||
bool $is_ppcp_settings_page,
|
||||
?SettingsStatus $settings_status = null
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->settings = $settings;
|
||||
$this->is_payments_page = $is_payments_page;
|
||||
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
|
||||
|
@ -161,7 +160,7 @@ class GatewayWithoutPayPalAdminNotice {
|
|||
* @return string One of the NOTICE_* constants.
|
||||
*/
|
||||
protected function check(): string {
|
||||
if ( State::STATE_ONBOARDED !== $this->state->current_state() ||
|
||||
if ( ! $this->is_connected ||
|
||||
( ! $this->is_payments_page && ! $this->is_ppcp_settings_page ) ) {
|
||||
return self::NOTICE_OK;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
|
||||
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
|
||||
/**
|
||||
* Creates an admin message that notifies user about send only country.
|
||||
|
@ -47,9 +46,9 @@ class SendOnlyCountryNotice {
|
|||
/**
|
||||
* Onboarding state
|
||||
*
|
||||
* @var int
|
||||
* @var bool
|
||||
*/
|
||||
private int $onboarding_state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* AdminNotice constructor.
|
||||
|
@ -58,20 +57,20 @@ class SendOnlyCountryNotice {
|
|||
* @param bool $is_send_only_country Determines if current WC country is a send only country.
|
||||
* @param bool $is_ppcp_settings_page Determines if current page is ppcp settings page.
|
||||
* @param bool $is_wc_gateways_list_page Determines if current page is ppcp gateway list page.
|
||||
* @param int $onboarding_state Determines current onboarding state.
|
||||
* @param bool $is_connected Whether onboarding was completed.
|
||||
*/
|
||||
public function __construct(
|
||||
string $message_text,
|
||||
bool $is_send_only_country,
|
||||
bool $is_ppcp_settings_page,
|
||||
bool $is_wc_gateways_list_page,
|
||||
int $onboarding_state
|
||||
bool $is_connected
|
||||
) {
|
||||
$this->message_text = $message_text;
|
||||
$this->is_send_only_country = $is_send_only_country;
|
||||
$this->is_ppcp_settings_page = $is_ppcp_settings_page;
|
||||
$this->is_wc_gateways_list_page = $is_wc_gateways_list_page;
|
||||
$this->onboarding_state = $onboarding_state;
|
||||
$this->is_connected = $is_connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,10 +79,9 @@ class SendOnlyCountryNotice {
|
|||
* @return Message|null
|
||||
*/
|
||||
public function message(): ?Message {
|
||||
|
||||
if ( ! $this->is_send_only_country ||
|
||||
! $this->is_ppcp_page() ||
|
||||
$this->onboarding_state === State::STATE_START
|
||||
! $this->is_connected ||
|
||||
! $this->is_ppcp_page()
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Notice;
|
|||
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\CurrencyGetter;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Class UnsupportedCurrencyAdminNotice
|
||||
|
@ -21,11 +18,11 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
|||
class UnsupportedCurrencyAdminNotice {
|
||||
|
||||
/**
|
||||
* The state.
|
||||
* Whether the merchant completed onboarding.
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The supported currencies.
|
||||
|
@ -58,20 +55,20 @@ class UnsupportedCurrencyAdminNotice {
|
|||
/**
|
||||
* UnsupportedCurrencyAdminNotice constructor.
|
||||
*
|
||||
* @param State $state The state.
|
||||
* @param bool $is_connected Whether the merchant completed onboarding.
|
||||
* @param CurrencyGetter $shop_currency The shop currency.
|
||||
* @param array $supported_currencies The supported currencies.
|
||||
* @param bool $is_wc_gateways_list_page Indicates if we're on the WooCommerce gateways list page.
|
||||
* @param bool $is_ppcp_settings_page Indicates if we're on a PPCP Settings page.
|
||||
*/
|
||||
public function __construct(
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
CurrencyGetter $shop_currency,
|
||||
array $supported_currencies,
|
||||
bool $is_wc_gateways_list_page,
|
||||
bool $is_ppcp_settings_page
|
||||
) {
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->shop_currency = $shop_currency;
|
||||
$this->supported_currencies = $supported_currencies;
|
||||
$this->is_wc_gateways_list_page = $is_wc_gateways_list_page;
|
||||
|
@ -110,7 +107,7 @@ class UnsupportedCurrencyAdminNotice {
|
|||
* @return bool
|
||||
*/
|
||||
protected function should_display(): bool {
|
||||
return $this->state->current_state() === State::STATE_ONBOARDED
|
||||
return $this->is_connected
|
||||
&& ! $this->currency_supported()
|
||||
&& ( $this->is_wc_gateways_list_page || $this->is_ppcp_settings_page );
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
// Legacy settings module, use of `State` class is correct.
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
assert( $state instanceof State );
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
|||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\OXXO\OXXOGateway;
|
||||
|
@ -35,11 +34,11 @@ class SectionsRenderer {
|
|||
protected $page_id;
|
||||
|
||||
/**
|
||||
* The onboarding state.
|
||||
* Whether onboarding was completed and the merchant is connected to PayPal.
|
||||
*
|
||||
* @var State
|
||||
* @var bool
|
||||
*/
|
||||
private $state;
|
||||
private bool $is_connected;
|
||||
|
||||
/**
|
||||
* The DCC product status
|
||||
|
@ -69,18 +68,11 @@ class SectionsRenderer {
|
|||
*/
|
||||
private $pui_product_status;
|
||||
|
||||
/**
|
||||
* SectionsRenderer constructor.
|
||||
*
|
||||
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
* @param State $state The onboarding state.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SectionsRenderer constructor.
|
||||
*
|
||||
* @param string $page_id ID of the current PPCP gateway settings page, or empty if it is not such page.
|
||||
* @param State $state The onboarding state.
|
||||
* @param bool $is_connected Whether the merchant completed onboarding.
|
||||
* @param DCCProductStatus $dcc_product_status The DCC product status.
|
||||
* @param DccApplies $dcc_applies The DCC applies.
|
||||
* @param MessagesApply $messages_apply The Messages apply.
|
||||
|
@ -88,14 +80,14 @@ class SectionsRenderer {
|
|||
*/
|
||||
public function __construct(
|
||||
string $page_id,
|
||||
State $state,
|
||||
bool $is_connected,
|
||||
DCCProductStatus $dcc_product_status,
|
||||
DccApplies $dcc_applies,
|
||||
MessagesApply $messages_apply,
|
||||
PayUponInvoiceProductStatus $pui_product_status
|
||||
) {
|
||||
$this->page_id = $page_id;
|
||||
$this->state = $state;
|
||||
$this->is_connected = $is_connected;
|
||||
$this->dcc_product_status = $dcc_product_status;
|
||||
$this->dcc_applies = $dcc_applies;
|
||||
$this->messages_apply = $messages_apply;
|
||||
|
@ -108,9 +100,7 @@ class SectionsRenderer {
|
|||
* @return bool
|
||||
*/
|
||||
public function should_render() : bool {
|
||||
return ! empty( $this->page_id ) &&
|
||||
( $this->state->production_state() === State::STATE_ONBOARDED ||
|
||||
$this->state->sandbox_state() === State::STATE_ONBOARDED );
|
||||
return $this->page_id && $this->is_connected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -214,6 +214,8 @@ class SettingsListener {
|
|||
Cache $client_credentials_cache
|
||||
) {
|
||||
|
||||
// This is a legacy settings class, it's correctly relying on the `Status` class.
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->setting_fields = $setting_fields;
|
||||
$this->webhook_registrar = $webhook_registrar;
|
||||
|
@ -261,6 +263,8 @@ class SettingsListener {
|
|||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
// This method is only used for legacy UI, `settings->set` is valid here.
|
||||
|
||||
$this->settings->set( 'merchant_id', $merchant_id );
|
||||
$this->settings->set( 'merchant_email', $merchant_email );
|
||||
|
||||
|
@ -363,6 +367,8 @@ class SettingsListener {
|
|||
return;
|
||||
}
|
||||
|
||||
// This method is only used for legacy UI, `settings->set` is valid here.
|
||||
|
||||
try {
|
||||
$token = $this->bearer->bearer();
|
||||
if ( ! $token->vaulting_available() ) {
|
||||
|
@ -472,6 +478,10 @@ class SettingsListener {
|
|||
&& 1 === absint( $_POST['woocommerce_ppcp-gateway_enabled'] );
|
||||
}
|
||||
|
||||
// This method initializes a feature cache. This initialization is not
|
||||
// required by the new UI; we can ignore the `settings->set` usage.
|
||||
// TODO new-ux: Test, if this method is called or some non-settings parts must be converted.
|
||||
|
||||
// phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
// phpcs:enable phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
if ( $credentials_change_status ) {
|
||||
|
@ -720,6 +730,8 @@ class SettingsListener {
|
|||
/**
|
||||
* Prevent enabling tracking if it is not enabled for merchant account.
|
||||
*
|
||||
* This method is not used anywhere. Not relevant for new-ux.
|
||||
*
|
||||
* @throws RuntimeException When API request fails.
|
||||
*/
|
||||
public function listen_for_tracking_enabled(): void {
|
||||
|
@ -765,6 +777,8 @@ class SettingsListener {
|
|||
return;
|
||||
}
|
||||
|
||||
// This method is only used for legacy UI, `settings->set` is valid here.
|
||||
|
||||
$existing_setting_value = $this->settings->has( $setting_slug ) ? $this->settings->get( $setting_slug ) : null;
|
||||
|
||||
if ( $condition ) {
|
||||
|
|
|
@ -114,6 +114,8 @@ class SettingsRenderer {
|
|||
string $api_shop_country
|
||||
) {
|
||||
|
||||
// This is a legacy settings class, it's correctly relying on the `Status` class.
|
||||
|
||||
$this->settings = $settings;
|
||||
$this->state = $state;
|
||||
$this->fields = $fields;
|
||||
|
|
|
@ -14,8 +14,6 @@ use Psr\Log\LoggerInterface;
|
|||
use Throwable;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
|
@ -33,7 +31,6 @@ use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\FeesRenderer;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
|
||||
|
@ -59,7 +56,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\SectionsRenderer;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsListener;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\SettingsRenderer;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrarInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\DCCGatewayConfiguration;
|
||||
|
@ -209,7 +205,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$c->get( 'button.client_id_for_admin' ),
|
||||
$c->get( 'api.shop.currency.getter' ),
|
||||
$c->get( 'api.shop.country' ),
|
||||
$c->get( 'onboarding.environment' ),
|
||||
$c->get( 'settings.environment' ),
|
||||
$settings_status->is_pay_later_button_enabled(),
|
||||
$settings->has( 'disable_funding' ) ? $settings->get( 'disable_funding' ) : array(),
|
||||
$c->get( 'wcgateway.settings.funding-sources' ),
|
||||
|
@ -607,16 +603,14 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
|
||||
$methods[] = $paypal_gateway;
|
||||
|
||||
$onboarding_state = $container->get( 'onboarding.state' );
|
||||
assert( $onboarding_state instanceof State );
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof ContainerInterface );
|
||||
|
||||
$is_our_page = $container->get( 'wcgateway.is-ppcp-settings-page' );
|
||||
$is_gateways_list_page = $container->get( 'wcgateway.is-wc-gateways-list-page' );
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
|
||||
if ( $onboarding_state->current_state() !== State::STATE_ONBOARDED ) {
|
||||
if ( ! $is_connected ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ return array(
|
|||
$endpoint = $container->get( 'api.endpoint.order' );
|
||||
$purchase_unit_factory = $container->get( 'api.factory.purchase-unit' );
|
||||
$payer_factory = $container->get( 'api.factory.payer' );
|
||||
$environment = $container->get( 'onboarding.environment' );
|
||||
$environment = $container->get( 'settings.environment' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
$authorized_payments_processor = $container->get( 'wcgateway.processor.authorized-payments' );
|
||||
$funding_source_renderer = $container->get( 'wcgateway.funding-source.renderer' );
|
||||
|
|
|
@ -10,7 +10,6 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\Webhooks;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
|
@ -18,8 +17,9 @@ return array(
|
|||
$endpoint = $container->get( 'api.endpoint.webhook' );
|
||||
assert( $endpoint instanceof WebhookEndpoint );
|
||||
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() >= State::STATE_ONBOARDED ) {
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
|
||||
if ( $is_connected ) {
|
||||
return $endpoint->list();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,8 @@ namespace WooCommerce\PayPalCommerce\Webhooks;
|
|||
|
||||
use Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\WebhookEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Webhook;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulateEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulationStateEndpoint;
|
||||
|
@ -183,7 +181,7 @@ return array(
|
|||
return new WebhooksStatusPageAssets(
|
||||
$container->get( 'webhook.module-url' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'onboarding.environment' )
|
||||
$container->get( 'settings.environment' )
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Webhooks;
|
||||
|
||||
use WC_Order;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use Exception;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExecutableModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ExtendingModule;
|
||||
|
@ -18,7 +16,6 @@ use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\FactoryModule;
|
|||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ModuleClassNameIdTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Module\ServiceModule;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\ResubscribeEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\Endpoint\SimulateEndpoint;
|
||||
|
@ -142,9 +139,10 @@ class WebhookModule implements ServiceModule, FactoryModule, ExtendingModule, Ex
|
|||
);
|
||||
|
||||
try {
|
||||
$webhooks = $container->get( 'webhook.status.registered-webhooks' );
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( empty( $webhooks ) && $state->current_state() >= State::STATE_ONBOARDED ) {
|
||||
$webhooks = $container->get( 'webhook.status.registered-webhooks' );
|
||||
$is_connected = $container->get( 'settings.flag.is-connected' );
|
||||
|
||||
if ( empty( $webhooks ) && $is_connected ) {
|
||||
$registrar = $container->get( 'webhook.registrar' );
|
||||
assert( $registrar instanceof WebhookRegistrar );
|
||||
$registrar->register();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue