♻️ Rename REST endpoint for manual login

This commit is contained in:
Philipp Stracker 2025-01-02 14:35:24 +01:00
parent ff1df84ada
commit ef0e7e756c
No known key found for this signature in database
3 changed files with 12 additions and 8 deletions

View file

@ -35,14 +35,15 @@ export const REST_HYDRATE_MERCHANT_PATH = '/wc/v3/wc_paypal/common/merchant';
export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/common';
/**
* REST path to perform the manual connection check, using client ID and secret,
* REST path to perform the manual connection authentication, using client ID and secret.
*
* Used by: Controls
* See: AuthenticateRestEndpoint.php
*
* @type {string}
*/
export const REST_MANUAL_CONNECTION_PATH = '/wc/v3/wc_paypal/authenticate';
export const REST_DIRECT_AUTHENTICATION_PATH =
'/wc/v3/wc_paypal/authenticate/direct';
/**
* REST path to generate an ISU URL for the PayPal-login.

View file

@ -11,7 +11,7 @@ import apiFetch from '@wordpress/api-fetch';
import {
REST_PERSIST_PATH,
REST_MANUAL_CONNECTION_PATH,
REST_DIRECT_AUTHENTICATION_PATH,
REST_CONNECTION_URL_PATH,
REST_HYDRATE_MERCHANT_PATH,
REST_REFRESH_FEATURES_PATH,
@ -56,7 +56,7 @@ export const controls = {
} ) {
try {
return await apiFetch( {
path: REST_MANUAL_CONNECTION_PATH,
path: REST_DIRECT_AUTHENTICATION_PATH,
method: 'POST',
data: {
clientId,

View file

@ -69,10 +69,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
'/' . $this->rest_base . '/direct',
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'connect_manual' ),
'callback' => array( $this, 'connect_direct' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
'clientId' => array(
@ -99,11 +99,14 @@ class AuthenticationRestEndpoint extends RestEndpoint {
}
/**
* Retrieves merchantId and email.
* Direct login: Retrieves merchantId and email using clientId and clientSecret.
*
* This is the "Manual Login" logic, when a merchant already knows their
* API credentials.
*
* @param WP_REST_Request $request Full data about the request.
*/
public function connect_manual( WP_REST_Request $request ) : WP_REST_Response {
public function connect_direct( WP_REST_Request $request ) : WP_REST_Response {
$client_id = $request->get_param( 'clientId' );
$client_secret = $request->get_param( 'clientSecret' );
$use_sandbox = $request->get_param( 'useSandbox' );