-
+
+ { renderSeparator() }
);
};
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
index db3775e59..acc78af72 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
@@ -122,7 +122,7 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
{ __( 'Connect Account', 'woocommerce-paypal-payments' ) }
-
+
Date: Thu, 21 Nov 2024 17:42:48 +0100
Subject: [PATCH 50/61] =?UTF-8?q?=F0=9F=8E=A8=20Small=20code=20cleanup?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/common/actions.js | 8 +--
.../resources/js/data/onboarding/actions.js | 66 ++++---------------
2 files changed, 14 insertions(+), 60 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index 63ace933b..edf6d8d4b 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -101,11 +101,9 @@ export const setClientSecret = ( clientSecret ) => ( {
* @return {Action} The action.
*/
export const persist = function* () {
- yield setIsBusy( true );
- yield {
- type: ACTION_TYPES.DO_PERSIST_DATA,
- };
- yield setIsBusy( false );
+ const data = yield select( STORE_NAME ).persistentData();
+
+ yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
};
/**
diff --git a/modules/ppcp-settings/resources/js/data/onboarding/actions.js b/modules/ppcp-settings/resources/js/data/onboarding/actions.js
index 84bca8e1a..1742048e1 100644
--- a/modules/ppcp-settings/resources/js/data/onboarding/actions.js
+++ b/modules/ppcp-settings/resources/js/data/onboarding/actions.js
@@ -25,17 +25,6 @@ import { STORE_NAME } from './constants';
*/
export const reset = () => ( { type: ACTION_TYPES.RESET } );
-/**
- * Transient. Marks the onboarding details as "ready", i.e., fully initialized.
- *
- * @param {boolean} isReady
- * @return {Action} The action.
- */
-export const setIsReady = ( isReady ) => ( {
- type: ACTION_TYPES.SET_TRANSIENT,
- payload: { isReady },
-} );
-
/**
* Persistent. Set the full onboarding details, usually during app initialization.
*
@@ -47,6 +36,17 @@ export const hydrate = ( payload ) => ( {
payload,
} );
+/**
+ * Transient. Marks the onboarding details as "ready", i.e., fully initialized.
+ *
+ * @param {boolean} isReady
+ * @return {Action} The action.
+ */
+export const setIsReady = ( isReady ) => ( {
+ type: ACTION_TYPES.SET_TRANSIENT,
+ payload: { isReady },
+} );
+
/**
* Persistent.Set the "onboarding completed" flag which shows or hides the wizard.
*
@@ -69,50 +69,6 @@ export const setStep = ( step ) => ( {
payload: { step },
} );
-/**
- * Persistent. Sets the sandbox mode on or off.
- *
- * @param {boolean} useSandbox
- * @return {Action} The action.
- */
-export const setSandboxMode = ( useSandbox ) => ( {
- type: ACTION_TYPES.SET_PERSISTENT,
- payload: { useSandbox },
-} );
-
-/**
- * Persistent. Toggles the "Manual Connection" mode on or off.
- *
- * @param {boolean} useManualConnection
- * @return {Action} The action.
- */
-export const setManualConnectionMode = ( useManualConnection ) => ( {
- type: ACTION_TYPES.SET_PERSISTENT,
- payload: { useManualConnection },
-} );
-
-/**
- * Persistent. Changes the "client ID" value.
- *
- * @param {string} clientId
- * @return {Action} The action.
- */
-export const setClientId = ( clientId ) => ( {
- type: ACTION_TYPES.SET_PERSISTENT,
- payload: { clientId },
-} );
-
-/**
- * Persistent. Changes the "client secret" value.
- *
- * @param {string} clientSecret
- * @return {Action} The action.
- */
-export const setClientSecret = ( clientSecret ) => ( {
- type: ACTION_TYPES.SET_PERSISTENT,
- payload: { clientSecret },
-} );
-
/**
* Persistent. Sets the "isCasualSeller" value.
*
From f2f0329e4e5729b3f9f53cfe9adefb7d136cca8c Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 17:43:22 +0100
Subject: [PATCH 51/61] =?UTF-8?q?=F0=9F=90=9B=20Implement=20missing=20comm?=
=?UTF-8?q?on-store=20action?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ppcp-settings/resources/js/data/common/actions.js | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index edf6d8d4b..6c20ca5a6 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -18,6 +18,17 @@ import { STORE_NAME } from './constants';
* @property {Object?} payload - Optional payload for the action.
*/
+/**
+ * Persistent. Set the full onboarding details, usually during app initialization.
+ *
+ * @param {{data: {}, flags?: {}}} payload
+ * @return {Action} The action.
+ */
+export const hydrate = ( payload ) => ( {
+ type: ACTION_TYPES.HYDRATE,
+ payload,
+} );
+
/**
* Transient. Marks the onboarding details as "ready", i.e., fully initialized.
*
From a0910962b4ba4b9d078a84f124268ca0aa19dab1 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 18:04:11 +0100
Subject: [PATCH 52/61] =?UTF-8?q?=F0=9F=90=9B=20Move=20required=20action?=
=?UTF-8?q?=20type=20to=20common=20store?=
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 | 1 +
modules/ppcp-settings/resources/js/data/common/hooks.js | 2 +-
.../ppcp-settings/resources/js/data/onboarding/action-types.js | 1 -
3 files changed, 2 insertions(+), 2 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 5d5968591..908d3ebad 100644
--- a/modules/ppcp-settings/resources/js/data/common/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/common/action-types.js
@@ -14,4 +14,5 @@ export default {
// Controls - always start with "DO_".
DO_PERSIST_DATA: 'COMMON:DO_PERSIST_DATA',
+ DO_MANUAL_CONNECTION: 'COMMON:DO_MANUAL_CONNECTION',
};
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index 642eed3dc..97b16e6a6 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -8,9 +8,9 @@
*/
import { useDispatch, useSelect } from '@wordpress/data';
+import { useCallback } from '@wordpress/element';
import { STORE_NAME } from './constants';
-import { useCallback } from '@wordpress/element';
const useTransient = ( key ) =>
useSelect(
diff --git a/modules/ppcp-settings/resources/js/data/onboarding/action-types.js b/modules/ppcp-settings/resources/js/data/onboarding/action-types.js
index f5d9944d3..2e16f8468 100644
--- a/modules/ppcp-settings/resources/js/data/onboarding/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/onboarding/action-types.js
@@ -15,5 +15,4 @@ export default {
// Controls - always start with "DO_".
DO_PERSIST_DATA: 'ONBOARDING:DO_PERSIST_DATA',
- DO_MANUAL_CONNECTION: 'ONBOARDING:DO_MANUAL_CONNECTION',
};
From b7ef3242bf703afaf4645d1e302e34d4e9dbdb60 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 19:04:27 +0100
Subject: [PATCH 53/61] =?UTF-8?q?=E2=9C=A8=20Standardize=20REST=20response?=
=?UTF-8?q?=20format?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/Endpoint/CommonRestEndpoint.php | 6 +--
.../Endpoint/ConnectManualRestEndpoint.php | 27 +++-------
.../src/Endpoint/LoginLinkRestEndpoint.php | 7 +--
.../src/Endpoint/OnboardingRestEndpoint.php | 4 +-
.../src/Endpoint/RestEndpoint.php | 49 +++++++++++++++++++
5 files changed, 62 insertions(+), 31 deletions(-)
diff --git a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
index 18c9de902..c7345148e 100644
--- a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php
@@ -109,11 +109,7 @@ class CommonRestEndpoint extends RestEndpoint {
$this->field_map
);
- return rest_ensure_response(
- array(
- 'data' => $js_data,
- )
- );
+ return $this->return_success( $js_data );
}
/**
diff --git a/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
index 5225b4d13..e394b880b 100644
--- a/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/ConnectManualRestEndpoint.php
@@ -126,33 +126,22 @@ class ConnectManualRestEndpoint extends RestEndpoint {
$use_sandbox = (bool) ( $data['use_sandbox'] ?? false );
if ( empty( $client_id ) || empty( $client_secret ) ) {
- return rest_ensure_response(
- array(
- 'success' => false,
- 'message' => 'No client ID or secret provided.',
- )
- );
+ return $this->return_error( 'No client ID or secret provided.' );
}
try {
$payee = $this->request_payee( $client_id, $client_secret, $use_sandbox );
} catch ( Exception $exception ) {
- return rest_ensure_response(
- array(
- 'success' => false,
- 'message' => $exception->getMessage(),
- )
- );
-
+ return $this->return_error( $exception->getMessage() );
}
- $result = array(
- 'merchantId' => $payee->merchant_id,
- 'email' => $payee->email_address,
- 'success' => true,
+ return $this->return_success(
+ array(
+ 'merchantId' => $payee->merchant_id,
+ 'email' => $payee->email_address,
+ 'success' => true,
+ )
);
-
- return rest_ensure_response( $result );
}
/**
diff --git a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
index cb969c7ca..85ced8276 100644
--- a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
@@ -93,12 +93,9 @@ class LoginLinkRestEndpoint extends RestEndpoint {
try {
$url = $url_generator->generate( $products );
- return rest_ensure_response( $url );
+ return $this->return_success( $url );
} catch ( \Exception $e ) {
- return new WP_REST_Response(
- array( 'error' => $e->getMessage() ),
- 500
- );
+ return $this->return_error( $e->getMessage() );
}
}
}
diff --git a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
index 03690d3bf..0a102c178 100644
--- a/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/OnboardingRestEndpoint.php
@@ -131,9 +131,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
$this->flag_map
);
- return rest_ensure_response(
+ return $this->return_success(
+ $js_data,
array(
- 'data' => $js_data,
'flags' => $js_flags,
)
);
diff --git a/modules/ppcp-settings/src/Endpoint/RestEndpoint.php b/modules/ppcp-settings/src/Endpoint/RestEndpoint.php
index 35b2912fe..76626ac0c 100644
--- a/modules/ppcp-settings/src/Endpoint/RestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/RestEndpoint.php
@@ -10,6 +10,7 @@ declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
use WC_REST_Controller;
+use WP_REST_Response;
/**
* Base class for REST controllers in the settings module.
@@ -31,6 +32,54 @@ abstract class RestEndpoint extends WC_REST_Controller {
return current_user_can( 'manage_woocommerce' );
}
+ /**
+ * Returns a successful REST API response.
+ *
+ * @param mixed $data The main response data.
+ * @param array $extra Optional, additional response data.
+ *
+ * @return WP_REST_Response The successful response.
+ */
+ protected function return_success( $data, array $extra = array() ) : WP_REST_Response {
+ $response = array(
+ 'success' => true,
+ 'data' => $data,
+ );
+
+ if ( $extra ) {
+ foreach ( $extra as $key => $value ) {
+ if ( isset( $response[ $key ] ) ) {
+ continue;
+ }
+
+ $response[ $key ] = $value;
+ }
+ }
+
+ return rest_ensure_response( $response );
+ }
+
+ /**
+ * Returns an error REST API response.
+ *
+ * @param string $reason The reason for the error.
+ * @param mixed $details Optional details about the error.
+ *
+ * @return WP_REST_Response The error response.
+ */
+ protected function return_error( string $reason, $details = null ) : WP_REST_Response {
+ $response = array(
+ 'success' => false,
+ 'message' => $reason,
+ );
+
+ if ( ! is_null( $details ) ) {
+ $response['details'] = $details;
+ }
+
+ return rest_ensure_response( $response );
+ }
+
/**
* Sanitizes parameters based on a field mapping.
*
From 2a28f38491549fe73ddf46fb52b9759f59a3b3d1 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 19:07:32 +0100
Subject: [PATCH 54/61] =?UTF-8?q?=E2=9C=A8=20Implement=20sandbox=20login?=
=?UTF-8?q?=20actions?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/AdvancedOptionsForm.js | 21 ++++++++++++--
.../resources/js/data/common/action-types.js | 1 +
.../resources/js/data/common/actions.js | 14 ++++++++++
.../resources/js/data/common/constants.js | 10 +++++++
.../resources/js/data/common/controls.js | 28 ++++++++++++++++++-
.../resources/js/data/common/hooks.js | 6 ++--
.../src/Endpoint/LoginLinkRestEndpoint.php | 10 +++++--
7 files changed, 82 insertions(+), 8 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
index acc78af72..3702a6e14 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
@@ -11,7 +11,8 @@ import { OnboardingHooks, CommonHooks } from '../../../../data';
const AdvancedOptionsForm = ( { setCompleted } ) => {
const { isBusy } = CommonHooks.useBusyState();
- const { isSandboxMode, setSandboxMode } = CommonHooks.useSandbox();
+ const { isSandboxMode, setSandboxMode, connectViaSandbox } =
+ CommonHooks.useSandbox();
const {
isManualConnectionMode,
setManualConnectionMode,
@@ -81,6 +82,21 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
setCompleted( true );
};
+ const handleSandboxConnect = async () => {
+ const res = await connectViaSandbox();
+
+ if ( ! res.success || ! res.data ) {
+ handleServerError(
+ res,
+ __(
+ 'Could not generate a Sandbox login link.',
+ 'woocommerce-paypal-payments'
+ )
+ );
+ return;
+ }
+ };
+
const handleConnect = async () => {
if ( ! handleFormValidation() ) {
return;
@@ -117,8 +133,9 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
) }
isToggled={ !! isSandboxMode }
setToggled={ setSandboxMode }
+ isLoading={ isBusy }
>
-
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 908d3ebad..47de76afe 100644
--- a/modules/ppcp-settings/resources/js/data/common/action-types.js
+++ b/modules/ppcp-settings/resources/js/data/common/action-types.js
@@ -15,4 +15,5 @@ export default {
// Controls - always start with "DO_".
DO_PERSIST_DATA: 'COMMON:DO_PERSIST_DATA',
DO_MANUAL_CONNECTION: 'COMMON:DO_MANUAL_CONNECTION',
+ DO_SANDBOX_LOGIN: 'COMMON:DO_SANDBOX_LOGIN',
};
diff --git a/modules/ppcp-settings/resources/js/data/common/actions.js b/modules/ppcp-settings/resources/js/data/common/actions.js
index 6c20ca5a6..619aaca5f 100644
--- a/modules/ppcp-settings/resources/js/data/common/actions.js
+++ b/modules/ppcp-settings/resources/js/data/common/actions.js
@@ -117,6 +117,20 @@ export const persist = function* () {
yield { type: ACTION_TYPES.DO_PERSIST_DATA, data };
};
+/**
+ * Side effect. Initiates the sandbox login ISU.
+ *
+ * @return {Action} The action.
+ */
+export const connectViaSandbox = function* () {
+ yield setIsBusy( true );
+
+ const result = yield { type: ACTION_TYPES.DO_SANDBOX_LOGIN };
+ yield setIsBusy( false );
+
+ return result;
+};
+
/**
* Side effect. Initiates a manual connection attempt using the provided client ID and secret.
*
diff --git a/modules/ppcp-settings/resources/js/data/common/constants.js b/modules/ppcp-settings/resources/js/data/common/constants.js
index c0fa5200f..c7ea9b4c1 100644
--- a/modules/ppcp-settings/resources/js/data/common/constants.js
+++ b/modules/ppcp-settings/resources/js/data/common/constants.js
@@ -34,3 +34,13 @@ export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/common';
* @type {string}
*/
export const REST_MANUAL_CONNECTION_PATH = '/wc/v3/wc_paypal/connect_manual';
+
+/**
+ * REST path to generate an ISU URL for the sandbox-login.
+ *
+ * Used by: Controls
+ * See: LoginLinkRestEndpoint.php
+ *
+ * @type {string}
+ */
+export const REST_SANDBOX_CONNECTION_PATH = '/wc/v3/wc_paypal/login_link';
diff --git a/modules/ppcp-settings/resources/js/data/common/controls.js b/modules/ppcp-settings/resources/js/data/common/controls.js
index 78dcc7f38..6de513e0b 100644
--- a/modules/ppcp-settings/resources/js/data/common/controls.js
+++ b/modules/ppcp-settings/resources/js/data/common/controls.js
@@ -9,7 +9,11 @@
import apiFetch from '@wordpress/api-fetch';
-import { REST_PERSIST_PATH, REST_MANUAL_CONNECTION_PATH } from './constants';
+import {
+ REST_PERSIST_PATH,
+ REST_MANUAL_CONNECTION_PATH,
+ REST_SANDBOX_CONNECTION_PATH,
+} from './constants';
import ACTION_TYPES from './action-types';
export const controls = {
@@ -25,6 +29,28 @@ export const controls = {
}
},
+ async [ ACTION_TYPES.DO_SANDBOX_LOGIN ]() {
+ let result = null;
+
+ try {
+ result = await apiFetch( {
+ path: REST_SANDBOX_CONNECTION_PATH,
+ method: 'POST',
+ data: {
+ environment: 'sandbox',
+ products: [ 'EXPRESS_CHECKOUT' ],
+ },
+ } );
+ } catch ( e ) {
+ result = {
+ success: false,
+ error: e,
+ };
+ }
+
+ return result;
+ },
+
async [ ACTION_TYPES.DO_MANUAL_CONNECTION ]( {
clientId,
clientSecret,
diff --git a/modules/ppcp-settings/resources/js/data/common/hooks.js b/modules/ppcp-settings/resources/js/data/common/hooks.js
index 97b16e6a6..8be3857b0 100644
--- a/modules/ppcp-settings/resources/js/data/common/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/common/hooks.js
@@ -31,6 +31,7 @@ const useHooks = () => {
setManualConnectionMode,
setClientId,
setClientSecret,
+ connectViaSandbox,
connectViaIdAndSecret,
} = useDispatch( STORE_NAME );
@@ -66,6 +67,7 @@ const useHooks = () => {
setClientSecret: ( value ) => {
return savePersistent( setClientSecret, value );
},
+ connectViaSandbox,
connectViaIdAndSecret,
};
};
@@ -81,9 +83,9 @@ export const useBusyState = () => {
};
export const useSandbox = () => {
- const { isSandboxMode, setSandboxMode } = useHooks();
+ const { isSandboxMode, setSandboxMode, connectViaSandbox } = useHooks();
- return { isSandboxMode, setSandboxMode };
+ return { isSandboxMode, setSandboxMode, connectViaSandbox };
};
export const useManualConnection = () => {
diff --git a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
index 85ced8276..8ed204383 100644
--- a/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
+++ b/modules/ppcp-settings/src/Endpoint/LoginLinkRestEndpoint.php
@@ -47,14 +47,18 @@ class LoginLinkRestEndpoint extends RestEndpoint {
public function register_routes() {
register_rest_route(
$this->namespace,
- '/' . $this->rest_base . '/(?P
[\w]+)',
+ '/' . $this->rest_base,
array(
array(
- 'methods' => WP_REST_Server::READABLE,
+ 'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'get_login_url' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
- 'products' => array(
+ 'environment' => array(
+ 'required' => true,
+ 'type' => 'string',
+ ),
+ 'products' => array(
'required' => true,
'type' => 'array',
'items' => array(
From 88f2ed9185fd8f8f9a035e54572055807c8a100a Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 19:08:50 +0100
Subject: [PATCH 55/61] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Minor=20code=20impro?=
=?UTF-8?q?vement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/AdvancedOptionsForm.js | 24 +++++++++----------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
index 3702a6e14..79724a533 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
@@ -7,7 +7,7 @@ import { store as noticesStore } from '@wordpress/notices';
import SettingsToggleBlock from '../../../ReusableComponents/SettingsToggleBlock';
import Separator from '../../../ReusableComponents/Separator';
import DataStoreControl from '../../../ReusableComponents/DataStoreControl';
-import { OnboardingHooks, CommonHooks } from '../../../../data';
+import { CommonHooks } from '../../../../data';
const AdvancedOptionsForm = ( { setCompleted } ) => {
const { isBusy } = CommonHooks.useBusyState();
@@ -61,17 +61,9 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
return true;
};
- const handleServerError = ( res ) => {
- if ( res.message ) {
- createErrorNotice( res.message );
- } else {
- createErrorNotice(
- __(
- 'Could not connect to PayPal. Please make sure your Client ID and Secret Key are correct.',
- 'woocommerce-paypal-payments'
- )
- );
- }
+ const handleServerError = ( res, genericMessage ) => {
+ console.error( 'Connection error', res );
+ createErrorNotice( res?.message ?? genericMessage );
};
const handleServerSuccess = () => {
@@ -107,7 +99,13 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
if ( res.success ) {
handleServerSuccess();
} else {
- handleServerError( res );
+ handleServerError(
+ res,
+ __(
+ 'Could not connect to PayPal. Please make sure your Client ID and Secret Key are correct.',
+ 'woocommerce-paypal-payments'
+ )
+ );
}
};
From 5f8dda098039db479268cda91ceb98c40c59024c Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 19:10:02 +0100
Subject: [PATCH 56/61] =?UTF-8?q?=E2=9C=A8=20Implement=20PayPal=20connecti?=
=?UTF-8?q?on=20via=20popup?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Components/AdvancedOptionsForm.js | 17 +++++++-
.../resources/js/utils/window.js | 42 +++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
create mode 100644 modules/ppcp-settings/resources/js/utils/window.js
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
index 79724a533..b18edc6fb 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/Components/AdvancedOptionsForm.js
@@ -8,6 +8,7 @@ import SettingsToggleBlock from '../../../ReusableComponents/SettingsToggleBlock
import Separator from '../../../ReusableComponents/Separator';
import DataStoreControl from '../../../ReusableComponents/DataStoreControl';
import { CommonHooks } from '../../../../data';
+import { openPopup } from '../../../../utils/window';
const AdvancedOptionsForm = ( { setCompleted } ) => {
const { isBusy } = CommonHooks.useBusyState();
@@ -87,9 +88,21 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
);
return;
}
+
+ const connectionUrl = res.data;
+ const popup = openPopup( connectionUrl );
+
+ if ( ! popup ) {
+ createErrorNotice(
+ __(
+ 'Popup blocked. Please allow popups for this site to connect to PayPal.',
+ 'woocommerce-paypal-payments'
+ )
+ );
+ }
};
- const handleConnect = async () => {
+ const handleManualConnect = async () => {
if ( ! handleFormValidation() ) {
return;
}
@@ -183,7 +196,7 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
onChange={ setClientSecret }
type="password"
/>
-
+
{ __( 'Connect Account', 'woocommerce-paypal-payments' ) }
diff --git a/modules/ppcp-settings/resources/js/utils/window.js b/modules/ppcp-settings/resources/js/utils/window.js
new file mode 100644
index 000000000..165874302
--- /dev/null
+++ b/modules/ppcp-settings/resources/js/utils/window.js
@@ -0,0 +1,42 @@
+/**
+ * Opens the provided URL, preferably in a popup window.
+ *
+ * Popups are usually only supported on desktop devices, when the browser is not in fullscreen mode.
+ *
+ * @param {string} url
+ * @param {Object} options
+ * @param {string} options.name
+ * @param {number} options.width
+ * @param {number} options.height
+ * @param {boolean} options.resizeable
+ * @return {null|Window} Popup window instance, or null.
+ */
+export const openPopup = (
+ url,
+ { name = '_blank', width = 450, height = 720, resizeable = false } = {}
+) => {
+ width = Math.max( 100, Math.min( window.screen.width - 40, width ) );
+ height = Math.max( 100, Math.min( window.screen.height - 40, height ) );
+
+ const left = ( window.screen.width - width ) / 2;
+ const top = ( window.screen.height - height ) / 2;
+
+ const features = [
+ `width=${ width }`,
+ `height=${ height }`,
+ `left=${ left }`,
+ `top=${ top }`,
+ `resizable=${ resizeable ? 'yes' : 'no' }`,
+ `scrollbars=yes`,
+ `status=no`,
+ ];
+
+ const popup = window.open( url, name, features.join( ',' ) );
+
+ if ( popup && ! popup.closed ) {
+ popup.focus();
+ return popup;
+ }
+
+ return null;
+};
From a95296b8ed5b91795fa3ac0ef09992963093668d Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Thu, 21 Nov 2024 19:28:08 +0100
Subject: [PATCH 57/61] =?UTF-8?q?=F0=9F=8E=A8=20Code=20format=20&=20cleanu?=
=?UTF-8?q?p?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Screens/Onboarding/StepBusiness.js | 47 ++++++++-----------
.../Screens/Onboarding/StepCompleteSetup.js | 10 ++--
.../Screens/Onboarding/StepProducts.js | 10 ++--
.../Screens/Onboarding/StepWelcome.js | 4 +-
4 files changed, 28 insertions(+), 43 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepBusiness.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepBusiness.js
index 6dcf435c9..a223686ff 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepBusiness.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepBusiness.js
@@ -1,18 +1,13 @@
+import { __ } from '@wordpress/i18n';
+
import OnboardingHeader from '../../ReusableComponents/OnboardingHeader';
import SelectBoxWrapper from '../../ReusableComponents/SelectBoxWrapper';
import SelectBox from '../../ReusableComponents/SelectBox';
-import { __ } from '@wordpress/i18n';
-import PaymentMethodIcons from '../../ReusableComponents/PaymentMethodIcons';
import { OnboardingHooks, BUSINESS_TYPES } from '../../../data';
const BUSINESS_RADIO_GROUP_NAME = 'business';
-const StepBusiness = ( {
- setStep,
- currentStep,
- stepperOrder,
- setCompleted,
-} ) => {
+const StepBusiness = ( {} ) => {
const { isCasualSeller, setIsCasualSeller } = OnboardingHooks.useBusiness();
const handleSellerTypeChange = ( value ) => {
@@ -39,23 +34,22 @@ const StepBusiness = ( {
/>
-
-
+
-
+ >
diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepCompleteSetup.js b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepCompleteSetup.js
index 5dc18f619..76afa8de2 100644
--- a/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepCompleteSetup.js
+++ b/modules/ppcp-settings/resources/js/Components/Screens/Onboarding/StepCompleteSetup.js
@@ -1,13 +1,9 @@
-import OnboardingHeader from '../../ReusableComponents/OnboardingHeader';
import { __ } from '@wordpress/i18n';
import { Button, Icon } from '@wordpress/components';
-const StepCompleteSetup = ( {
- setStep,
- currentStep,
- stepperOrder,
- setCompleted,
-} ) => {
+import OnboardingHeader from '../../ReusableComponents/OnboardingHeader';
+
+const StepCompleteSetup = ( { setCompleted } ) => {
const ButtonIcon = () => (