♻️ 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'; 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 * Used by: Controls
* See: AuthenticateRestEndpoint.php * See: AuthenticateRestEndpoint.php
* *
* @type {string} * @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. * REST path to generate an ISU URL for the PayPal-login.

View file

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

View file

@ -69,10 +69,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
public function register_routes() { public function register_routes() {
register_rest_route( register_rest_route(
$this->namespace, $this->namespace,
'/' . $this->rest_base, '/' . $this->rest_base . '/direct',
array( array(
'methods' => WP_REST_Server::EDITABLE, 'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'connect_manual' ), 'callback' => array( $this, 'connect_direct' ),
'permission_callback' => array( $this, 'check_permission' ), 'permission_callback' => array( $this, 'check_permission' ),
'args' => array( 'args' => array(
'clientId' => 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. * @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_id = $request->get_param( 'clientId' );
$client_secret = $request->get_param( 'clientSecret' ); $client_secret = $request->get_param( 'clientSecret' );
$use_sandbox = $request->get_param( 'useSandbox' ); $use_sandbox = $request->get_param( 'useSandbox' );