mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Merge branch 'trunk' into PCP-4110-incorrect-subscription-cancellation-handling-with-pay-pal-subscriptions
This commit is contained in:
commit
65e1ca4eb0
259 changed files with 9482 additions and 3476 deletions
|
@ -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();
|
||||
|
@ -1910,6 +1854,13 @@ return array(
|
|||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
if ( apply_filters(
|
||||
'woocommerce.feature-flags.woocommerce_paypal_payments.settings_enabled',
|
||||
getenv( 'PCP_SETTINGS_ENABLED' ) === '1'
|
||||
) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $settings->has( 'fraudnet_enabled' ) && $settings->get( 'fraudnet_enabled' );
|
||||
},
|
||||
'wcgateway.fraudnet-assets' => function( ContainerInterface $container ) : FraudNetAssets {
|
||||
|
@ -1917,7 +1868,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -120,7 +120,10 @@ class Settings implements ContainerInterface {
|
|||
* @return bool
|
||||
*/
|
||||
public function has( string $id ) {
|
||||
if ( $this->settings_map_helper->has_mapped_key( $id ) ) {
|
||||
if (
|
||||
$this->settings_map_helper->has_mapped_key( $id )
|
||||
&& ! is_null( $this->settings_map_helper->mapped_value( $id ) )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -156,7 +159,7 @@ class Settings implements ContainerInterface {
|
|||
if ( $this->settings ) {
|
||||
return false;
|
||||
}
|
||||
$this->settings = get_option( self::KEY, array() );
|
||||
$this->settings = (array) get_option( self::KEY, array() );
|
||||
|
||||
$defaults = array(
|
||||
'title' => __( 'PayPal', 'woocommerce-paypal-payments' ),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -648,7 +642,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul
|
|||
$methods[] = $container->get( 'wcgateway.credit-card-gateway' );
|
||||
}
|
||||
|
||||
if ( $paypal_gateway_enabled && $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) {
|
||||
if ( $paypal_gateway_enabled && apply_filters( 'woocommerce_paypal_payments_card_button_gateway_should_register_gateway', $container->get( 'wcgateway.settings.allow_card_button_gateway' ) ) ) {
|
||||
$methods[] = $container->get( 'wcgateway.card-button-gateway' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue