From 31e46a8e1739c0fc810d476a5b6380bbd17fa113 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 17:45:54 +0400 Subject: [PATCH 01/19] Add mapping for the `stay_updated` setting --- modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index a4504e76b..fe326a422 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -55,6 +55,7 @@ class SettingsTabMapHelper { 'logging_enabled' => 'enable_logging', 'vault_enabled' => 'save_paypal_and_venmo', '3d_secure_contingency' => 'three_d_secure', + 'stay_updated' => 'stay_updated', ); } From 1a4697a31b003672c685d7f34f674e2fbca37714 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 17:49:02 +0400 Subject: [PATCH 02/19] Add the task inside 'Things To Do Next' Woo section --- modules/ppcp-wc-gateway/services.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index ebc29f60f..76a324b1e 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2068,10 +2068,29 @@ return array( return array(); }, + 'wcgateway.settings.wc-tasks.working-capital-config' => static function( ContainerInterface $container ): array { + $settings = $container->get( 'wcgateway.settings' ); + $stay_updated = $settings->has( 'stay_updated' ) ? $settings->get( 'stay_updated' ) : false; + + if ( $container->get( 'api.shop.country' ) !== 'US' || ! $stay_updated ) { + return array(); + } + + return array( + array( + 'id' => 'ppcp-working-capital-task', + 'title' => __( 'Start you PayPal Working Capital application', 'woocommerce-paypal-payments' ), + 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), + 'redirect_url' => 'http://example.com/', + ), + ); + }, + 'wcgateway.settings.wc-tasks.task-config-services' => static function(): array { return array( 'wcgateway.settings.wc-tasks.pay-later-task-config', 'wcgateway.settings.wc-tasks.connect-task-config', + 'wcgateway.settings.wc-tasks.working-capital-config', ); }, From 80b49695556be13d71036ad107b2b38e8bfad529 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 17:49:23 +0400 Subject: [PATCH 03/19] Create the type for inbox note --- .../src/Settings/WcInboxNotes/InboxNote.php | 61 +++++++++++++++++++ .../WcInboxNotes/InboxNoteInterface.php | 20 ++++++ 2 files changed, 81 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNote.php create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteInterface.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNote.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNote.php new file mode 100644 index 000000000..8d5ed408b --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNote.php @@ -0,0 +1,61 @@ +title = $title; + $this->content = $content; + $this->type = $type; + $this->name = $name; + $this->status = $status; + $this->action = $action; + } + + public function title(): string { + return $this->title; + } + + public function content(): string { + return $this->content; + } + + public function type(): string { + return $this->type; + } + + public function name(): string { + return $this->name; + } + + public function status(): string { + return $this->status; + } + + public function action(): InboxNoteActionInterface { + return $this->action; + } +} diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteInterface.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteInterface.php new file mode 100644 index 000000000..f354f3a38 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteInterface.php @@ -0,0 +1,20 @@ + Date: Mon, 4 Aug 2025 17:49:33 +0400 Subject: [PATCH 04/19] Create the type for inbox note action --- .../Settings/WcInboxNotes/InboxNoteAction.php | 49 +++++++++++++++++++ .../WcInboxNotes/InboxNoteActionInterface.php | 19 +++++++ 2 files changed, 68 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteAction.php create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteActionInterface.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteAction.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteAction.php new file mode 100644 index 000000000..3fac66f45 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteAction.php @@ -0,0 +1,49 @@ +name = $name; + $this->label = $label; + $this->url = $url; + $this->status = $status; + $this->is_primary = $is_primary; + } + + public function name(): string { + return $this->name; + } + + public function label(): string { + return $this->label; + } + + public function url(): string { + return $this->url; + } + + public function status(): string { + return $this->status; + } + + public function is_primary(): bool { + return $this->is_primary; + } +} diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteActionInterface.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteActionInterface.php new file mode 100644 index 000000000..3424be152 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteActionInterface.php @@ -0,0 +1,19 @@ + Date: Mon, 4 Aug 2025 17:49:48 +0400 Subject: [PATCH 05/19] Create a factory for inbox notes --- .../WcInboxNotes/InboxNoteFactory.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteFactory.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteFactory.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteFactory.php new file mode 100644 index 000000000..cebe19724 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteFactory.php @@ -0,0 +1,25 @@ + Date: Mon, 4 Aug 2025 17:49:56 +0400 Subject: [PATCH 06/19] Create a registrar for inbox notes --- .../WcInboxNotes/InboxNoteRegistrar.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php new file mode 100644 index 000000000..417a257f3 --- /dev/null +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php @@ -0,0 +1,56 @@ +inbox_notes = $inbox_notes; + } + + public function register(): void { + foreach ( $this->inbox_notes as $inbox_note ) { + $inbox_note_name = $inbox_note->name(); + + if ( Notes::get_note_by_name( $inbox_note_name ) ) { + continue; + } + + $note = new Note(); + $note->set_title( $inbox_note->title() ); + $note->set_content( $inbox_note->content() ); + $note->set_type( $inbox_note->type() ); + $note->set_name( $inbox_note_name ); + $note->set_source( 'your-plugin-name' ); + $note->set_status( $inbox_note->status() ); + + $inbox_note_action = $inbox_note->action(); + + $note->add_action( + $inbox_note_action->name(), + $inbox_note_action->label(), + $inbox_note_action->url(), + $inbox_note_action->status(), + $inbox_note_action->is_primary() + ); + + $note->save(); + } + } +} From 0108779972d470811faabdc9b12163571e1068ca Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 17:50:08 +0400 Subject: [PATCH 07/19] Add appropriate services --- modules/ppcp-wc-gateway/services.php | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 76a324b1e..1da2abcbe 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway; +use Automattic\WooCommerce\Admin\Notes\Note; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\ExperienceContext; use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; @@ -82,6 +83,10 @@ 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\WcGateway\Settings\WcInboxNotes\InboxNoteAction; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcInboxNotes\InboxNoteFactory; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcInboxNotes\InboxNoteInterface; +use WooCommerce\PayPalCommerce\WcGateway\Settings\WcInboxNotes\InboxNoteRegistrar; use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Factory\SimpleRedirectTaskFactory; use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Factory\SimpleRedirectTaskFactoryInterface; use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrar; @@ -2141,6 +2146,41 @@ return array( return $simple_redirect_tasks; }, + 'wcgateway.settings.inbox-note-factory' => static function(): InboxNoteFactory { + return new InboxNoteFactory(); + }, + + 'wcgateway.settings.inbox-note-registrar' => static function( ContainerInterface $container ): InboxNoteRegistrar { + return new InboxNoteRegistrar( $container->get( 'wcgateway.settings.inbox-notes' ) ); + }, + + /** + * Retrieves the list of inbox note instances. + * + * @returns InboxNoteInterface[] + */ + 'wcgateway.settings.inbox-notes' => static function( ContainerInterface $container ): array { + $inbox_note_factory = $container->get( 'wcgateway.settings.inbox-note-factory' ); + assert( $inbox_note_factory instanceof InboxNoteFactory ); + + return array( + $inbox_note_factory->create_note( + __( 'PayPal Working Capital', 'woocommerce-paypal-payments' ), + __( 'Fast funds with payments that flex with your PayPal sales The PayPal Working Capital business loan is primarily based on your PayPal account history. Apply for $1,000-$200,000 (and up to $300,000 for repeat borrowers) with no credit check.† If approved, loans are funded in minutes.', 'woocommerce-paypal-payments' ), + Note::E_WC_ADMIN_NOTE_INFORMATIONAL, + 'ppcp-working-capital-inbox-note', + Note::E_WC_ADMIN_NOTE_UNACTIONED, + new InboxNoteAction( + 'apply_now', + __( 'Apply now', 'woocommerce-paypal-payments' ), + 'http://example.com/', + Note::E_WC_ADMIN_NOTE_UNACTIONED, + true + ) + ), + ); + }, + 'wcgateway.void-button.assets' => function( ContainerInterface $container ) : VoidButtonAssets { return new VoidButtonAssets( $container->get( 'wcgateway.url' ), From 7e43288f74e1eed1aa5ed67c2c433e8327b6fc42 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 17:50:56 +0400 Subject: [PATCH 08/19] Register the notes in 'Inbox' Woo section --- .../ppcp-wc-gateway/src/WCGatewayModule.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index 08e4b6460..f6d22371f 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -62,6 +62,7 @@ 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\WcGateway\Settings\WcInboxNotes\InboxNoteRegistrar; use WooCommerce\PayPalCommerce\WcGateway\Settings\WcTasks\Registrar\TaskRegistrarInterface; /** @@ -95,6 +96,7 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul $this->register_columns( $c ); $this->register_checkout_paypal_address_preset( $c ); $this->register_wc_tasks( $c ); + $this->register_woo_inbox_notes( $c ); $this->register_void_button( $c ); if ( ! $c->get( 'wcgateway.settings.admin-settings-enabled' ) ) { @@ -957,6 +959,26 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul ); } + /** + * Registers inbox notes in the WooCommerce Admin inbox section. + */ + protected function register_woo_inbox_notes( ContainerInterface $container ): void { + add_action( + 'admin_init', + static function () use ( $container ): void { + $logger = $container->get( 'woocommerce.logger.woocommerce' ); + assert( $logger instanceof LoggerInterface ); + try { + $inbox_note_registrar = $container->get( 'wcgateway.settings.inbox-note-registrar' ); + assert( $inbox_note_registrar instanceof InboxNoteRegistrar ); + $inbox_note_registrar->register(); + } catch ( Exception $exception ) { + $logger->error( 'Failed to add note to the WooCommerce inbox section. ' . $exception->getMessage() ); + } + }, + ); + } + /** * Registers the assets and ajax endpoint for the void button. * From 3587074bab8333bec3aa963cc4bf0cf458555b41 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:11:49 +0400 Subject: [PATCH 09/19] Simplify the code --- modules/ppcp-settings/services.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 0a00db31e..457d096ce 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -522,6 +522,10 @@ $services = array( // TODO: This "merchant_capabilities" service is only used here. Could it be merged to make the code cleaner and less segmented? $capabilities = $container->get( 'settings.service.merchant_capabilities' ); + $settings = $container->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + $stay_updated = $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); + /** * Initializes TodosEligibilityService with eligibility conditions for various PayPal features. * Each parameter determines whether a specific feature should be shown in the Things To Do list. @@ -566,7 +570,8 @@ $services = array( $container->get( 'googlepay.eligible' ) && $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account. $container->get( 'applepay.eligible' ) && $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. $container->get( 'googlepay.eligible' ) && $capabilities['google_pay'] && ! $gateways['google_pay'], - ! $capabilities['installments'] && 'MX' === $container->get( 'settings.data.general' )->get_merchant_country() // Enable Installments for Mexico. + ! $capabilities['installments'] && 'MX' === $container->get( 'settings.data.general' )->get_merchant_country(), // Enable Installments for Mexico. + $container->get( 'api.shop.country' ) === 'US' && $stay_updated // Enable Working Capital. ); }, 'settings.rest.features' => static function ( ContainerInterface $container ) : FeaturesRestEndpoint { From b97da8dda0dffffdbf8c19a7262105c650e796b8 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:12:16 +0400 Subject: [PATCH 10/19] Add TodoDefinition for working capital --- .../src/Data/Definition/TodosDefinition.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index 6d1a3be7a..87e9c9b89 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -227,6 +227,16 @@ class TodosDefinition { ), 'priority' => 13, ), + 'apply_for_working_capital' => array( + 'title' => __( 'Start you PayPal Working Capital application', 'woocommerce-paypal-payments' ), + 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), + 'isEligible' => $eligibility_checks['apply_for_working_capital'], + 'action' => array( + 'type' => 'external', + 'url' => 'http://example.com/', + ), + 'priority' => 14, + ), ); } } From cdf43b50237a9f54c8bb107ca0e39bd849188e09 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:12:36 +0400 Subject: [PATCH 11/19] Add TodoEligibility for working capital --- .../ppcp-settings/src/Service/TodosEligibilityService.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-settings/src/Service/TodosEligibilityService.php b/modules/ppcp-settings/src/Service/TodosEligibilityService.php index 94cc21fb0..61dc2eb07 100644 --- a/modules/ppcp-settings/src/Service/TodosEligibilityService.php +++ b/modules/ppcp-settings/src/Service/TodosEligibilityService.php @@ -129,6 +129,8 @@ class TodosEligibilityService { */ private bool $is_enable_installments_eligible; + private bool $is_working_capital_eligible; + /** * Constructor. * @@ -148,6 +150,7 @@ class TodosEligibilityService { * @param bool $is_enable_apple_pay_eligible Whether enabling Apple Pay is eligible. * @param bool $is_enable_google_pay_eligible Whether enabling Google Pay is eligible. * @param bool $is_enable_installments_eligible Whether enabling Installments is eligible. + * @param bool $is_working_capital_eligible Whether applying for Working Capital is eligible. */ public function __construct( bool $is_fastlane_eligible, @@ -165,7 +168,8 @@ class TodosEligibilityService { bool $is_google_pay_eligible, bool $is_enable_apple_pay_eligible, bool $is_enable_google_pay_eligible, - bool $is_enable_installments_eligible + bool $is_enable_installments_eligible, + bool $is_working_capital_eligible ) { $this->is_fastlane_eligible = $is_fastlane_eligible; $this->is_pay_later_messaging_eligible = $is_pay_later_messaging_eligible; @@ -183,6 +187,7 @@ class TodosEligibilityService { $this->is_enable_apple_pay_eligible = $is_enable_apple_pay_eligible; $this->is_enable_google_pay_eligible = $is_enable_google_pay_eligible; $this->is_enable_installments_eligible = $is_enable_installments_eligible; + $this->is_working_capital_eligible = $is_working_capital_eligible; } /** @@ -208,6 +213,7 @@ class TodosEligibilityService { 'enable_apple_pay' => fn() => $this->is_enable_apple_pay_eligible, 'enable_google_pay' => fn() => $this->is_enable_google_pay_eligible, 'enable_installments' => fn() => $this->is_enable_installments_eligible, + 'apply_for_working_capital' => fn() => $this->is_working_capital_eligible, ); } } From f32c013677a1d1d12f36ae6c8f248389960c2091 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:12:49 +0400 Subject: [PATCH 12/19] Apply services --- modules/ppcp-wc-gateway/services.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1da2abcbe..5348ae643 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2075,7 +2075,8 @@ return array( 'wcgateway.settings.wc-tasks.working-capital-config' => static function( ContainerInterface $container ): array { $settings = $container->get( 'wcgateway.settings' ); - $stay_updated = $settings->has( 'stay_updated' ) ? $settings->get( 'stay_updated' ) : false; + assert( $settings instanceof Settings ); + $stay_updated = $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); if ( $container->get( 'api.shop.country' ) !== 'US' || ! $stay_updated ) { return array(); From d7a45138ffe116f094a1666551ad39b0fe1b0dba Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:47:11 +0400 Subject: [PATCH 13/19] Add method to get and set the `stay_updated` setting --- .../ppcp-settings/src/Data/SettingsModel.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/ppcp-settings/src/Data/SettingsModel.php b/modules/ppcp-settings/src/Data/SettingsModel.php index 1ce1d162e..28761a3ae 100644 --- a/modules/ppcp-settings/src/Data/SettingsModel.php +++ b/modules/ppcp-settings/src/Data/SettingsModel.php @@ -406,4 +406,22 @@ class SettingsModel extends AbstractDataModel { $cards ); } + + /** + * Gets the Stay Updated setting. + * + * @return bool True if Stay Updated is enabled, false otherwise. + */ + public function get_stay_updated() : bool { + return $this->data['stay_updated']; + } + + /** + * Sets the Stay Updated setting. + * + * @param bool $save Whether to save the Stay Updated. + */ + public function set_stay_updated( bool $save ) : void { + $this->data['stay_updated'] = $this->sanitizer->sanitize_bool( $save ); + } } From 05e24ea0a913192e6786406751409cdf1abba33b Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:48:04 +0400 Subject: [PATCH 14/19] Add feature-flag for the working capital. Is turned off by default --- modules/ppcp-wc-gateway/src/WCGatewayModule.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/ppcp-wc-gateway/src/WCGatewayModule.php b/modules/ppcp-wc-gateway/src/WCGatewayModule.php index f6d22371f..c39bedbbf 100644 --- a/modules/ppcp-wc-gateway/src/WCGatewayModule.php +++ b/modules/ppcp-wc-gateway/src/WCGatewayModule.php @@ -966,6 +966,21 @@ class WCGatewayModule implements ServiceModule, ExtendingModule, ExecutableModul add_action( 'admin_init', static function () use ( $container ): void { + $settings = $container->get( 'wcgateway.settings' ); + assert( $settings instanceof Settings ); + + $is_working_capital_feature_flag_enabled = apply_filters( + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention + 'woocommerce.feature-flags.woocommerce_paypal_payments.working_capital_enabled', + getenv( 'PCP_WORKING_CAPITAL_ENABLED' ) === '1' + ); + + $is_working_capital_eligible = $container->get( 'api.shop.country' ) === 'US' && $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); + + if ( ! $is_working_capital_feature_flag_enabled || ! $is_working_capital_eligible ) { + return; + } + $logger = $container->get( 'woocommerce.logger.woocommerce' ); assert( $logger instanceof LoggerInterface ); try { From 1fdff2c44ea49d3199746810b19dfe75088f3736 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:48:12 +0400 Subject: [PATCH 15/19] Add feature-flag for the working capital. Is turned off by default --- modules/ppcp-wc-gateway/services.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 5348ae643..114f7be81 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2074,11 +2074,18 @@ return array( }, 'wcgateway.settings.wc-tasks.working-capital-config' => static function( ContainerInterface $container ): array { - $settings = $container->get( 'wcgateway.settings' ); + $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $stay_updated = $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); - if ( $container->get( 'api.shop.country' ) !== 'US' || ! $stay_updated ) { + $is_working_capital_feature_flag_enabled = apply_filters( + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention + 'woocommerce.feature-flags.woocommerce_paypal_payments.working_capital_enabled', + getenv( 'PCP_WORKING_CAPITAL_ENABLED' ) === '1' + ); + + $is_working_capital_eligible = $container->get( 'api.shop.country' ) === 'US' && $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); + + if ( ! $is_working_capital_feature_flag_enabled || ! $is_working_capital_eligible ) { return array(); } From d975a552a24622d589b128750205723663373962 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 18:48:15 +0400 Subject: [PATCH 16/19] Add feature-flag for the working capital. Is turned off by default --- modules/ppcp-settings/services.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 457d096ce..03ea71432 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -522,9 +522,16 @@ $services = array( // TODO: This "merchant_capabilities" service is only used here. Could it be merged to make the code cleaner and less segmented? $capabilities = $container->get( 'settings.service.merchant_capabilities' ); - $settings = $container->get( 'wcgateway.settings' ); + $settings = $container->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); - $stay_updated = $settings->has( 'stay_updated' ) && $settings->get( 'stay_updated' ); + + $is_working_capital_feature_flag_enabled = apply_filters( + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- feature flags use this convention + 'woocommerce.feature-flags.woocommerce_paypal_payments.working_capital_enabled', + getenv( 'PCP_WORKING_CAPITAL_ENABLED' ) === '1' + ); + + $is_working_capital_eligible = $container->get( 'settings.data.general' )->get_merchant_country() === 'US' && $container->get( 'settings.data.settings' )->get_stay_updated(); /** * Initializes TodosEligibilityService with eligibility conditions for various PayPal features. @@ -571,7 +578,7 @@ $services = array( $container->get( 'applepay.eligible' ) && $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. $container->get( 'googlepay.eligible' ) && $capabilities['google_pay'] && ! $gateways['google_pay'], ! $capabilities['installments'] && 'MX' === $container->get( 'settings.data.general' )->get_merchant_country(), // Enable Installments for Mexico. - $container->get( 'api.shop.country' ) === 'US' && $stay_updated // Enable Working Capital. + $is_working_capital_feature_flag_enabled && $is_working_capital_eligible // Enable Working Capital. ); }, 'settings.rest.features' => static function ( ContainerInterface $container ) : FeaturesRestEndpoint { From f0e88a65d8f14247610c10e179a554cbd9aaed96 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 19:05:16 +0400 Subject: [PATCH 17/19] Fix the wording --- modules/ppcp-settings/src/Data/Definition/TodosDefinition.php | 2 +- modules/ppcp-wc-gateway/services.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index 87e9c9b89..c97738779 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -228,7 +228,7 @@ class TodosDefinition { 'priority' => 13, ), 'apply_for_working_capital' => array( - 'title' => __( 'Start you PayPal Working Capital application', 'woocommerce-paypal-payments' ), + 'title' => __( 'Start your PayPal Working Capital application', 'woocommerce-paypal-payments' ), 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['apply_for_working_capital'], 'action' => array( diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 114f7be81..dbaf27df6 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2092,7 +2092,7 @@ return array( return array( array( 'id' => 'ppcp-working-capital-task', - 'title' => __( 'Start you PayPal Working Capital application', 'woocommerce-paypal-payments' ), + 'title' => __( 'Start your PayPal Working Capital application', 'woocommerce-paypal-payments' ), 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), 'redirect_url' => 'http://example.com/', ), From 9bf1042a0157c525f303a2b6ba2b334b17bc1d98 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 19:05:49 +0400 Subject: [PATCH 18/19] Fix the wording --- modules/ppcp-settings/src/Data/Definition/TodosDefinition.php | 2 +- modules/ppcp-wc-gateway/services.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index c97738779..aafe1b198 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -229,7 +229,7 @@ class TodosDefinition { ), 'apply_for_working_capital' => array( 'title' => __( 'Start your PayPal Working Capital application', 'woocommerce-paypal-payments' ), - 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), + 'description' => __( 'Hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['apply_for_working_capital'], 'action' => array( 'type' => 'external', diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index dbaf27df6..31abbc5af 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2093,7 +2093,7 @@ return array( array( 'id' => 'ppcp-working-capital-task', 'title' => __( 'Start your PayPal Working Capital application', 'woocommerce-paypal-payments' ), - 'description' => __( 'hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), + 'description' => __( 'Hey, you are eligible for credit. Click here to learn more and sign up', 'woocommerce-paypal-payments' ), 'redirect_url' => 'http://example.com/', ), ); From c48f3e6d2abbb5250b254a4660338e823f438673 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 4 Aug 2025 19:19:53 +0400 Subject: [PATCH 19/19] Add the plugin base name --- modules/ppcp-wc-gateway/services.php | 2 +- .../src/Settings/WcInboxNotes/InboxNoteRegistrar.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 31abbc5af..0a395f3de 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -2159,7 +2159,7 @@ return array( }, 'wcgateway.settings.inbox-note-registrar' => static function( ContainerInterface $container ): InboxNoteRegistrar { - return new InboxNoteRegistrar( $container->get( 'wcgateway.settings.inbox-notes' ) ); + return new InboxNoteRegistrar( $container->get( 'wcgateway.settings.inbox-notes' ), $container->get( 'ppcp.plugin' ) ); }, /** diff --git a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php index 417a257f3..8a0b6509d 100644 --- a/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php +++ b/modules/ppcp-wc-gateway/src/Settings/WcInboxNotes/InboxNoteRegistrar.php @@ -9,6 +9,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings\WcInboxNotes; use Automattic\WooCommerce\Admin\Notes\Note; use Automattic\WooCommerce\Admin\Notes\Notes; +use WpOop\WordPress\Plugin\PluginInterface; /** * Registers inbox notes in the WooCommerce Admin inbox section. @@ -19,9 +20,11 @@ class InboxNoteRegistrar { * @var InboxNoteInterface[] */ protected array $inbox_notes; + protected PluginInterface $plugin; - public function __construct( array $inbox_notes ) { + public function __construct( array $inbox_notes, PluginInterface $plugin ) { $this->inbox_notes = $inbox_notes; + $this->plugin = $plugin; } public function register(): void { @@ -37,7 +40,7 @@ class InboxNoteRegistrar { $note->set_content( $inbox_note->content() ); $note->set_type( $inbox_note->type() ); $note->set_name( $inbox_note_name ); - $note->set_source( 'your-plugin-name' ); + $note->set_source( $this->plugin->getBaseName() ); $note->set_status( $inbox_note->status() ); $inbox_note_action = $inbox_note->action();