From e5023b50075b6dc0900b492346683c215fe381b9 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 13:46:04 +0100
Subject: [PATCH 01/13] =?UTF-8?q?=E2=9C=A8=20New=20REST=20endpoint=20to=20?=
=?UTF-8?q?disconnect=20merchant?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Endpoint/AuthenticationRestEndpoint.php | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index 9d72ff88c..a558f6e71 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -123,6 +123,15 @@ class AuthenticationRestEndpoint extends RestEndpoint {
),
)
);
+ register_rest_route(
+ $this->namespace,
+ '/' . $this->rest_base . '/disconnect',
+ array(
+ 'methods' => WP_REST_Server::EDITABLE,
+ 'callback' => array( $this, 'disconnect' ),
+ 'permission_callback' => array( $this, 'check_permission' ),
+ )
+ );
}
/**
@@ -176,4 +185,15 @@ class AuthenticationRestEndpoint extends RestEndpoint {
return $this->return_success( $response );
}
+
+ /**
+ * Disconnect the merchant and clear the authentication details.
+ *
+ * @return WP_REST_Response
+ */
+ public function disconnect() : WP_REST_Response {
+ $this->authentication_manager->disconnect();
+
+ return $this->return_success( 'OK' );
+ }
}
From 4f61251ae7ab8c438a007c15335ad6b3c187698f Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 13:56:41 +0100
Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=92=A1=20Document=20REST=20paths=20?=
=?UTF-8?q?in=20source=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Endpoint/AuthenticationRestEndpoint.php | 20 +++++++++++++++++++
.../src/Endpoint/CommonRestEndpoint.php | 12 +++++++++++
.../src/Endpoint/LoginLinkRestEndpoint.php | 7 +++++++
.../src/Endpoint/OnboardingRestEndpoint.php | 9 +++++++++
.../Endpoint/RefreshFeatureStatusEndpoint.php | 3 +++
.../src/Endpoint/WebhookSettingsEndpoint.php | 8 ++++++++
6 files changed, 59 insertions(+)
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index a558f6e71..5ffd48baa 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -67,6 +67,14 @@ class AuthenticationRestEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() : void {
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/authenticate/direct
+ * {
+ * clientId
+ * clientSecret
+ * useSandbox
+ * }
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/direct',
@@ -97,6 +105,14 @@ class AuthenticationRestEndpoint extends RestEndpoint {
)
);
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/authenticate/isu
+ * {
+ * sharedId
+ * authCode
+ * useSandbox
+ * }
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/isu',
@@ -123,6 +139,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
),
)
);
+
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/authenticate/disconnect
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/disconnect',
diff --git a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
index d99204c80..6da060f28 100644
--- a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
@@ -111,6 +111,9 @@ class CommonRestEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() {
+ /**
+ * GET /wp-json/wc/v3/wc_paypal/common
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
@@ -121,6 +124,12 @@ class CommonRestEndpoint extends RestEndpoint {
)
);
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/common
+ * {
+ * // Fields mentioned in $field_map[]['js_name']
+ * }
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
@@ -131,6 +140,9 @@ class CommonRestEndpoint extends RestEndpoint {
)
);
+ /**
+ * GET /wp-json/wc/v3/wc_paypal/common/merchant
+ */
register_rest_route(
$this->namespace,
"/$this->rest_base/merchant",
diff --git a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
index 7ddee27a5..c2b0e9ff3 100644
--- a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
@@ -52,6 +52,13 @@ class LoginLinkRestEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() : void {
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/login_link
+ * {
+ * useSandbox
+ * products
+ * }
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
diff --git a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
index 018ab2dc2..19cdcd530 100644
--- a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
@@ -97,6 +97,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() {
+ /**
+ * GET /wp-json/wc/v3/wc_paypal/onboarding
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
@@ -107,6 +110,12 @@ class OnboardingRestEndpoint extends RestEndpoint {
)
);
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/onboarding
+ * {
+ * // Fields mentioned in $field_map[]['js_name']
+ * }
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
diff --git a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
index dfbfc3a3a..7e8335e00 100644
--- a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
@@ -83,6 +83,9 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() {
+ /**
+ * POST /wp-json/wc/v3/wc_paypal/refresh-feature-status
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
diff --git a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
index df227264a..603496194 100644
--- a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
@@ -77,6 +77,10 @@ class WebhookSettingsEndpoint extends RestEndpoint {
* Configure REST API routes.
*/
public function register_routes() : void {
+ /**
+ * GET /wp-json/wc/v3/wc_paypal/webhook_settings
+ * POST /wp-json/wc/v3/wc_paypal/webhook_settings
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
@@ -94,6 +98,10 @@ class WebhookSettingsEndpoint extends RestEndpoint {
)
);
+ /**
+ * GET /wp-json/wc/v3/wc_paypal/webhook_simulate
+ * POST /wp-json/wc/v3/wc_paypal/webhook_simulate
+ */
register_rest_route(
$this->namespace,
'/' . $this->rest_simulate_base,
From 1bee5f1c46ae0a1c7ddb579f1f1a7baa9313cf5d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 13:57:42 +0100
Subject: [PATCH 03/13] =?UTF-8?q?=F0=9F=8E=A8=20Minor=20code-style=20chang?=
=?UTF-8?q?es?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php | 2 +-
.../ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php | 2 +-
.../src/Endpoint/RefreshFeatureStatusEndpoint.php | 2 +-
.../ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php | 6 +++++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
index 6da060f28..35af6c093 100644
--- a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
@@ -110,7 +110,7 @@ class CommonRestEndpoint extends RestEndpoint {
/**
* Configure REST API routes.
*/
- public function register_routes() {
+ public function register_routes() : void {
/**
* GET /wp-json/wc/v3/wc_paypal/common
*/
diff --git a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
index 19cdcd530..54aced7ef 100644
--- a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
@@ -96,7 +96,7 @@ class OnboardingRestEndpoint extends RestEndpoint {
/**
* Configure REST API routes.
*/
- public function register_routes() {
+ public function register_routes() : void {
/**
* GET /wp-json/wc/v3/wc_paypal/onboarding
*/
diff --git a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
index 7e8335e00..7f1d4468c 100644
--- a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
@@ -82,7 +82,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
/**
* Configure REST API routes.
*/
- public function register_routes() {
+ public function register_routes() : void {
/**
* POST /wp-json/wc/v3/wc_paypal/refresh-feature-status
*/
diff --git a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
index 603496194..5e56de9e3 100644
--- a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
@@ -67,7 +67,11 @@ class WebhookSettingsEndpoint extends RestEndpoint {
* @param WebhookRegistrar $webhook_registrar A service that allows resubscribing webhooks.
* @param WebhookSimulation $webhook_simulation A service that allows webhook simulations.
*/
- public function __construct( WebhookEndpoint $webhook_endpoint, WebhookRegistrar $webhook_registrar, WebhookSimulation $webhook_simulation ) {
+ public function __construct(
+ WebhookEndpoint $webhook_endpoint,
+ WebhookRegistrar $webhook_registrar,
+ WebhookSimulation $webhook_simulation
+ ) {
$this->webhook_endpoint = $webhook_endpoint;
$this->webhook_registrar = $webhook_registrar;
$this->webhook_simulation = $webhook_simulation;
From 8f38bac810e84155f87c11ab6c73cb38a7b40a0e Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:06:24 +0100
Subject: [PATCH 04/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Consolidate=20REST?=
=?UTF-8?q?=20endpoints:=20Webhooks?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/constants.js | 8 ++++----
.../src/Endpoint/WebhookSettingsEndpoint.php | 19 ++++++-------------
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/constants.js b/modules/ppcp-settings/resources/js/data/common/constants.js
index 49abba6db..40c01b6e3 100644
--- a/modules/ppcp-settings/resources/js/data/common/constants.js
+++ b/modules/ppcp-settings/resources/js/data/common/constants.js
@@ -66,24 +66,24 @@ export const REST_ISU_AUTHENTICATION_PATH = '/wc/v3/wc_paypal/authenticate/isu';
export const REST_CONNECTION_URL_PATH = '/wc/v3/wc_paypal/login_link';
/**
- * REST path to fetch webhooks data or resubscribe webhooks,
+ * REST path to fetch webhooks data or resubscribe webhooks.
*
* Used by: Controls
* See: WebhookSettingsEndpoint.php
*
* @type {string}
*/
-export const REST_WEBHOOKS = '/wc/v3/wc_paypal/webhook_settings';
+export const REST_WEBHOOKS = '/wc/v3/wc_paypal/webhooks';
/**
- * REST path to start webhook simulation and observe the state,
+ * REST path to start webhook simulation and observe the state.
*
* Used by: Controls
* See: WebhookSettingsEndpoint.php
*
* @type {string}
*/
-export const REST_WEBHOOKS_SIMULATE = '/wc/v3/wc_paypal/webhook_simulate';
+export const REST_WEBHOOKS_SIMULATE = '/wc/v3/wc_paypal/webhooks/simulate';
/**
* REST path to refresh the feature status.
diff --git a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
index 5e56de9e3..81e8f4335 100644
--- a/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/WebhookSettingsEndpoint.php
@@ -29,14 +29,7 @@ class WebhookSettingsEndpoint extends RestEndpoint {
*
* @var string
*/
- protected $rest_base = 'webhook_settings';
-
- /**
- * Endpoint base to start webhook simulation and check the state
- *
- * @var string
- */
- protected string $rest_simulate_base = 'webhook_simulate';
+ protected $rest_base = 'webhooks';
/**
* Application webhook endpoint
@@ -82,8 +75,8 @@ class WebhookSettingsEndpoint extends RestEndpoint {
*/
public function register_routes() : void {
/**
- * GET /wp-json/wc/v3/wc_paypal/webhook_settings
- * POST /wp-json/wc/v3/wc_paypal/webhook_settings
+ * GET /wp-json/wc/v3/wc_paypal/webhooks
+ * POST /wp-json/wc/v3/wc_paypal/webhooks
*/
register_rest_route(
$this->namespace,
@@ -103,12 +96,12 @@ class WebhookSettingsEndpoint extends RestEndpoint {
);
/**
- * GET /wp-json/wc/v3/wc_paypal/webhook_simulate
- * POST /wp-json/wc/v3/wc_paypal/webhook_simulate
+ * GET /wp-json/wc/v3/wc_paypal/webhooks/simulate
+ * POST /wp-json/wc/v3/wc_paypal/webhooks/simulate
*/
register_rest_route(
$this->namespace,
- '/' . $this->rest_simulate_base,
+ '/' . $this->rest_base . '/simulate',
array(
array(
'methods' => WP_REST_Server::READABLE,
From 53ce535f4a93a9809463b121957c0c49a77ad41f Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:08:20 +0100
Subject: [PATCH 05/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Shorten=20REST=20end?=
=?UTF-8?q?points:=20Features?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/common/constants.js | 3 +--
.../src/Endpoint/RefreshFeatureStatusEndpoint.php | 4 ++--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/constants.js b/modules/ppcp-settings/resources/js/data/common/constants.js
index 40c01b6e3..6101ed31a 100644
--- a/modules/ppcp-settings/resources/js/data/common/constants.js
+++ b/modules/ppcp-settings/resources/js/data/common/constants.js
@@ -93,5 +93,4 @@ export const REST_WEBHOOKS_SIMULATE = '/wc/v3/wc_paypal/webhooks/simulate';
*
* @type {string}
*/
-export const REST_REFRESH_FEATURES_PATH =
- '/wc/v3/wc_paypal/refresh-feature-status';
+export const REST_REFRESH_FEATURES_PATH = '/wc/v3/wc_paypal/refresh-features';
diff --git a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
index 7f1d4468c..3b17b84ed 100644
--- a/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/RefreshFeatureStatusEndpoint.php
@@ -25,7 +25,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
*
* @var string
*/
- protected $rest_base = 'refresh-feature-status';
+ protected $rest_base = 'refresh-features';
/**
* Cache timeout in seconds.
@@ -84,7 +84,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
*/
public function register_routes() : void {
/**
- * POST /wp-json/wc/v3/wc_paypal/refresh-feature-status
+ * POST /wp-json/wc/v3/wc_paypal/refresh-features
*/
register_rest_route(
$this->namespace,
From ec029dd4c5cfa547f63a954c635b32c51eb56e4c Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:09:04 +0100
Subject: [PATCH 06/13] =?UTF-8?q?=E2=9C=A8=20Flush=20APM=20feature=20cache?=
=?UTF-8?q?=20on=20merchant=20disconnect?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Service/AuthenticationManager.php | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/modules/ppcp-settings/src/Service/AuthenticationManager.php b/modules/ppcp-settings/src/Service/AuthenticationManager.php
index 96d7f3bc1..f722ab297 100644
--- a/modules/ppcp-settings/src/Service/AuthenticationManager.php
+++ b/modules/ppcp-settings/src/Service/AuthenticationManager.php
@@ -122,6 +122,11 @@ class AuthenticationManager {
* is no need for it here, it's good house-keeping practice to clean up.
*/
do_action( 'woocommerce_paypal_payments_flush_api_cache' );
+
+ /**
+ * Clear the APM eligibility flags from the default settings object.
+ */
+ do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
}
/**
@@ -420,6 +425,11 @@ class AuthenticationManager {
*/
do_action( 'woocommerce_paypal_payments_authenticated_merchant' );
+ /**
+ * Clear the APM eligibility flags from the default settings object.
+ */
+ do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
+
/**
* Subscribe the new merchant to relevant PayPal webhooks.
*/
From 30ab1bd51f5e1aadf081b009efcbc3a9cc086cd5 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:11:24 +0100
Subject: [PATCH 07/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Consolidate=20authen?=
=?UTF-8?q?tication=20name:=20OAuth,=20not=20ISU?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/constants.js | 5 +++--
.../resources/js/data/common/controls.js | 4 ++--
.../src/Endpoint/AuthenticationRestEndpoint.php | 12 ++++++------
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/constants.js b/modules/ppcp-settings/resources/js/data/common/constants.js
index 6101ed31a..9faa698e5 100644
--- a/modules/ppcp-settings/resources/js/data/common/constants.js
+++ b/modules/ppcp-settings/resources/js/data/common/constants.js
@@ -46,14 +46,15 @@ export const REST_DIRECT_AUTHENTICATION_PATH =
'/wc/v3/wc_paypal/authenticate/direct';
/**
- * REST path to perform the ISU authentication check, using shared ID and authCode.
+ * REST path to perform the OAuth authentication check, using shared ID and authCode.
*
* Used by: Controls
* See: AuthenticateRestEndpoint.php
*
* @type {string}
*/
-export const REST_ISU_AUTHENTICATION_PATH = '/wc/v3/wc_paypal/authenticate/isu';
+export const REST_OAUTH_AUTHENTICATION_PATH =
+ '/wc/v3/wc_paypal/authenticate/oauth';
/**
* REST path to generate an ISU URL for the PayPal-login.
diff --git a/modules/ppcp-settings/resources/js/data/common/controls.js b/modules/ppcp-settings/resources/js/data/common/controls.js
index 62d4a8f84..dc2f04710 100644
--- a/modules/ppcp-settings/resources/js/data/common/controls.js
+++ b/modules/ppcp-settings/resources/js/data/common/controls.js
@@ -15,7 +15,7 @@ import {
REST_CONNECTION_URL_PATH,
REST_HYDRATE_MERCHANT_PATH,
REST_REFRESH_FEATURES_PATH,
- REST_ISU_AUTHENTICATION_PATH,
+ REST_OAUTH_AUTHENTICATION_PATH,
REST_WEBHOOKS,
REST_WEBHOOKS_SIMULATE,
} from './constants';
@@ -82,7 +82,7 @@ export const controls = {
} ) {
try {
return await apiFetch( {
- path: REST_ISU_AUTHENTICATION_PATH,
+ path: REST_OAUTH_AUTHENTICATION_PATH,
method: 'POST',
data: {
sharedId,
diff --git a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
index 5ffd48baa..7ac964b2d 100644
--- a/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/AuthenticationRestEndpoint.php
@@ -106,7 +106,7 @@ class AuthenticationRestEndpoint extends RestEndpoint {
);
/**
- * POST /wp-json/wc/v3/wc_paypal/authenticate/isu
+ * POST /wp-json/wc/v3/wc_paypal/authenticate/oauth
* {
* sharedId
* authCode
@@ -115,10 +115,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
*/
register_rest_route(
$this->namespace,
- '/' . $this->rest_base . '/isu',
+ '/' . $this->rest_base . '/oauth',
array(
'methods' => WP_REST_Server::EDITABLE,
- 'callback' => array( $this, 'connect_isu' ),
+ 'callback' => array( $this, 'connect_oauth' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
'sharedId' => array(
@@ -181,14 +181,14 @@ class AuthenticationRestEndpoint extends RestEndpoint {
}
/**
- * ISU login: Retrieves clientId and clientSecret using a sharedId and authCode.
+ * OAuth login: Retrieves clientId and clientSecret using a sharedId and authCode.
*
- * This is the final step in the UI-driven login via the ISU popup, which
+ * This is the final step in the UI-driven login via the OAuth popup, which
* is triggered by the LoginLinkRestEndpoint URL.
*
* @param WP_REST_Request $request Full data about the request.
*/
- public function connect_isu( WP_REST_Request $request ) : WP_REST_Response {
+ public function connect_oauth( WP_REST_Request $request ) : WP_REST_Response {
$shared_id = $request->get_param( 'sharedId' );
$auth_code = $request->get_param( 'authCode' );
$use_sandbox = $request->get_param( 'useSandbox' );
From bc08aa74da195446a6f85936a2d7651892212c62 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:12:57 +0100
Subject: [PATCH 08/13] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Shorten=20action=20n?=
=?UTF-8?q?ame?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/common/action-types.js | 3 +--
modules/ppcp-settings/resources/js/data/common/actions.js | 2 +-
modules/ppcp-settings/resources/js/data/common/controls.js | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/action-types.js b/modules/ppcp-settings/resources/js/data/common/action-types.js
index 8ae56b20c..91f350482 100644
--- a/modules/ppcp-settings/resources/js/data/common/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/common/action-types.js
@@ -26,6 +26,5 @@ export default {
DO_REFRESH_FEATURES: 'COMMON:DO_REFRESH_FEATURES',
DO_RESUBSCRIBE_WEBHOOKS: 'COMMON:DO_RESUBSCRIBE_WEBHOOKS',
DO_START_WEBHOOK_SIMULATION: 'COMMON:DO_START_WEBHOOK_SIMULATION',
- DO_CHECK_WEBHOOK_SIMULATION_STATE:
- 'COMMON:DO_CHECK_WEBHOOK_SIMULATION_STATE',
+ DO_CHECK_WEBHOOK_SIMULATION: 'COMMON:DO_CHECK_WEBHOOK_SIMULATION',
};
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index c859fe0be..91652f56e 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -288,5 +288,5 @@ export const startWebhookSimulation = function* () {
* @return {Action} The action.
*/
export const checkWebhookSimulationState = function* () {
- return yield { type: ACTION_TYPES.DO_CHECK_WEBHOOK_SIMULATION_STATE };
+ return yield { type: ACTION_TYPES.DO_CHECK_WEBHOOK_SIMULATION };
};
diff --git a/modules/ppcp-settings/resources/js/data/common/controls.js b/modules/ppcp-settings/resources/js/data/common/controls.js
index dc2f04710..a7e53a8da 100644
--- a/modules/ppcp-settings/resources/js/data/common/controls.js
+++ b/modules/ppcp-settings/resources/js/data/common/controls.js
@@ -138,7 +138,7 @@ export const controls = {
} );
},
- async [ ACTION_TYPES.DO_CHECK_WEBHOOK_SIMULATION_STATE ]() {
+ async [ ACTION_TYPES.DO_CHECK_WEBHOOK_SIMULATION ]() {
return await apiFetch( {
path: REST_WEBHOOKS_SIMULATE,
} );
From 401faf6975bc5d4696b46c86ff0c60c439fc8414 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:16:46 +0100
Subject: [PATCH 09/13] =?UTF-8?q?=E2=9C=A8=20New=20Redux=20action=20to=20d?=
=?UTF-8?q?isconnect=20merchant?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/action-types.js | 1 +
.../ppcp-settings/resources/js/data/common/actions.js | 9 +++++++++
.../resources/js/data/common/constants.js | 11 +++++++++++
.../resources/js/data/common/controls.js | 8 ++++++++
4 files changed, 29 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/data/common/action-types.js b/modules/ppcp-settings/resources/js/data/common/action-types.js
index 91f350482..f33e8a9ee 100644
--- a/modules/ppcp-settings/resources/js/data/common/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/common/action-types.js
@@ -21,6 +21,7 @@ export default {
DO_PERSIST_DATA: 'COMMON:DO_PERSIST_DATA',
DO_DIRECT_API_AUTHENTICATION: 'COMMON:DO_DIRECT_API_AUTHENTICATION',
DO_OAUTH_AUTHENTICATION: 'COMMON:DO_OAUTH_AUTHENTICATION',
+ DO_DISCONNECT_MERCHANT: 'COMMON:DO_DISCONNECT_MERCHANT',
DO_GENERATE_ONBOARDING_URL: 'COMMON:DO_GENERATE_ONBOARDING_URL',
DO_REFRESH_MERCHANT: 'COMMON:DO_REFRESH_MERCHANT',
DO_REFRESH_FEATURES: 'COMMON:DO_REFRESH_FEATURES',
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index 91652f56e..0c4cb4af1 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -212,6 +212,15 @@ export const authenticateWithOAuth = function* (
};
};
+/**
+ * Side effect. Checks webhook simulation.
+ *
+ * @return {Action} The action.
+ */
+export const disconnectMerchant = function () {
+ return { type: ACTION_TYPES.DO_DISCONNECT_MERCHANT };
+};
+
/**
* Side effect. Clears and refreshes the merchant data via a REST request.
*
diff --git a/modules/ppcp-settings/resources/js/data/common/constants.js b/modules/ppcp-settings/resources/js/data/common/constants.js
index 9faa698e5..86bd670db 100644
--- a/modules/ppcp-settings/resources/js/data/common/constants.js
+++ b/modules/ppcp-settings/resources/js/data/common/constants.js
@@ -56,6 +56,17 @@ export const REST_DIRECT_AUTHENTICATION_PATH =
export const REST_OAUTH_AUTHENTICATION_PATH =
'/wc/v3/wc_paypal/authenticate/oauth';
+/**
+ * REST path to disconnect the current merchant from PayPal.
+ *
+ * Used by: Controls
+ * See: AuthenticateRestEndpoint.php
+ *
+ * @type {string}
+ */
+export const REST_DISCONNECT_MERCHANT_PATH =
+ '/wc/v3/wc_paypal/authenticate/disconnect';
+
/**
* REST path to generate an ISU URL for the PayPal-login.
*
diff --git a/modules/ppcp-settings/resources/js/data/common/controls.js b/modules/ppcp-settings/resources/js/data/common/controls.js
index a7e53a8da..6a5b4f9bc 100644
--- a/modules/ppcp-settings/resources/js/data/common/controls.js
+++ b/modules/ppcp-settings/resources/js/data/common/controls.js
@@ -16,6 +16,7 @@ import {
REST_HYDRATE_MERCHANT_PATH,
REST_REFRESH_FEATURES_PATH,
REST_OAUTH_AUTHENTICATION_PATH,
+ REST_DISCONNECT_MERCHANT_PATH,
REST_WEBHOOKS,
REST_WEBHOOKS_SIMULATE,
} from './constants';
@@ -98,6 +99,13 @@ export const controls = {
}
},
+ async [ ACTION_TYPES.DO_DISCONNECT ]() {
+ return await apiFetch( {
+ path: REST_DISCONNECT_MERCHANT_PATH,
+ method: 'POST',
+ } );
+ },
+
async [ ACTION_TYPES.DO_REFRESH_MERCHANT ]() {
try {
return await apiFetch( { path: REST_HYDRATE_MERCHANT_PATH } );
From 4b83d588ec76d1620a4ebdbcdd2ee810a2c5a467 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:21:52 +0100
Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=90=9B=20Fix=20a=20PHP=20error=20du?=
=?UTF-8?q?ring=20disconnect?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/src/Service/AuthenticationManager.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/ppcp-settings/src/Service/AuthenticationManager.php b/modules/ppcp-settings/src/Service/AuthenticationManager.php
index f722ab297..95acf068b 100644
--- a/modules/ppcp-settings/src/Service/AuthenticationManager.php
+++ b/modules/ppcp-settings/src/Service/AuthenticationManager.php
@@ -126,7 +126,7 @@ class AuthenticationManager {
/**
* Clear the APM eligibility flags from the default settings object.
*/
- do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
+ do_action( 'woocommerce_paypal_payments_clear_apm_product_status', null );
}
/**
@@ -428,7 +428,7 @@ class AuthenticationManager {
/**
* Clear the APM eligibility flags from the default settings object.
*/
- do_action( 'woocommerce_paypal_payments_clear_apm_product_status' );
+ do_action( 'woocommerce_paypal_payments_clear_apm_product_status', null );
/**
* Subscribe the new merchant to relevant PayPal webhooks.
From 364c1b55c5f2d883b2d83c7d7b83bd1473bb8ca2 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:41:08 +0100
Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20disconnect=20R?=
=?UTF-8?q?edux=20action?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/common/actions.js | 4 ++--
modules/ppcp-settings/resources/js/data/common/controls.js | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index 0c4cb4af1..8f2b14812 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -217,8 +217,8 @@ export const authenticateWithOAuth = function* (
*
* @return {Action} The action.
*/
-export const disconnectMerchant = function () {
- return { type: ACTION_TYPES.DO_DISCONNECT_MERCHANT };
+export const disconnectMerchant = function* () {
+ return yield { type: ACTION_TYPES.DO_DISCONNECT_MERCHANT };
};
/**
diff --git a/modules/ppcp-settings/resources/js/data/common/controls.js b/modules/ppcp-settings/resources/js/data/common/controls.js
index 6a5b4f9bc..a318e2116 100644
--- a/modules/ppcp-settings/resources/js/data/common/controls.js
+++ b/modules/ppcp-settings/resources/js/data/common/controls.js
@@ -11,10 +11,10 @@ import apiFetch from '@wordpress/api-fetch';
import {
REST_PERSIST_PATH,
- REST_DIRECT_AUTHENTICATION_PATH,
REST_CONNECTION_URL_PATH,
REST_HYDRATE_MERCHANT_PATH,
REST_REFRESH_FEATURES_PATH,
+ REST_DIRECT_AUTHENTICATION_PATH,
REST_OAUTH_AUTHENTICATION_PATH,
REST_DISCONNECT_MERCHANT_PATH,
REST_WEBHOOKS,
@@ -99,7 +99,7 @@ export const controls = {
}
},
- async [ ACTION_TYPES.DO_DISCONNECT ]() {
+ async [ ACTION_TYPES.DO_DISCONNECT_MERCHANT ]() {
return await apiFetch( {
path: REST_DISCONNECT_MERCHANT_PATH,
method: 'POST',
From 5173954776714c3dbcaccdf72a14ad6a72ac391d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:42:05 +0100
Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Add?=
=?UTF-8?q?=20debug=20tool=20to=20disconnect=20merchant?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
modules/ppcp-settings/resources/js/data/debug.js | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/debug.js b/modules/ppcp-settings/resources/js/data/debug.js
index 6380c6d6a..a57c62a05 100644
--- a/modules/ppcp-settings/resources/js/data/debug.js
+++ b/modules/ppcp-settings/resources/js/data/debug.js
@@ -5,6 +5,7 @@ export const addDebugTools = ( context, modules ) => {
return;
}
+ // Dump the current state of all our Redux stores.
context.dumpStore = async () => {
/* eslint-disable no-console */
if ( ! console?.groupCollapsed ) {
@@ -43,10 +44,15 @@ export const addDebugTools = ( context, modules ) => {
} );
};
- context.startOnboarding = () => {
- const onboarding = wp.data.dispatch( OnboardingStoreName );
- onboarding.setCompleted( false );
- onboarding.setStep( 0 );
- onboarding.persist();
+ // Disconnect the merchant and display the onboarding wizard.
+ context.disconnect = () => {
+ const common = wp.data.dispatch( CommonStoreName );
+
+ common.disconnectMerchant();
+
+ // eslint-disable-next-line no-console
+ console.log( 'Disconnected from PayPal. Reloading the page...' );
+
+ window.location.reload();
};
};
From 99d93888e1c3caa0ace72cd9db6b3ac567c42c0d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Mon, 13 Jan 2025 14:42:59 +0100
Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Debug?=
=?UTF-8?q?=20tool=20=E2=80=9Creset=E2=80=9D=20respects=20onboarding=20sta?=
=?UTF-8?q?te?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/reducer.js | 2 ++
.../ppcp-settings/resources/js/data/debug.js | 22 ++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/reducer.js b/modules/ppcp-settings/resources/js/data/common/reducer.js
index e9ff90a42..559024728 100644
--- a/modules/ppcp-settings/resources/js/data/common/reducer.js
+++ b/modules/ppcp-settings/resources/js/data/common/reducer.js
@@ -77,6 +77,8 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
// Keep "read-only" details and initialization flags.
cleanState.wooSettings = { ...state.wooSettings };
+ cleanState.merchant = { ...state.merchant };
+ cleanState.features = { ...state.features };
cleanState.isReady = true;
return cleanState;
diff --git a/modules/ppcp-settings/resources/js/data/debug.js b/modules/ppcp-settings/resources/js/data/debug.js
index a57c62a05..861af8de9 100644
--- a/modules/ppcp-settings/resources/js/data/debug.js
+++ b/modules/ppcp-settings/resources/js/data/debug.js
@@ -33,12 +33,32 @@ export const addDebugTools = ( context, modules ) => {
/* eslint-enable no-console */
};
+ // Reset all Redux stores to their initial state.
context.resetStore = () => {
- const stores = [ OnboardingStoreName, CommonStoreName ];
+ const stores = [];
+ const { isConnected } = wp.data.select( CommonStoreName ).merchant();
+
+ if ( isConnected ) {
+ // Make sure the Onboarding wizard is "completed".
+ const onboarding = wp.data.dispatch( OnboardingStoreName );
+ onboarding.setCompleted( true );
+ onboarding.persist();
+
+ // Reset all stores, except for the onboarding store.
+ stores.push( CommonStoreName );
+ // TODO: Add other stores here once they are available.
+ } else {
+ // Only reset the common & onboarding stores to restart the onboarding wizard.
+ stores.push( CommonStoreName );
+ stores.push( OnboardingStoreName );
+ }
stores.forEach( ( storeName ) => {
const store = wp.data.dispatch( storeName );
+ // eslint-disable-next-line no-console
+ console.log( `Reset store: ${ storeName }...` );
+
store.reset();
store.persist();
} );