mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Get and resubscribe webhooks
This commit is contained in:
parent
484ecc17d7
commit
08f5b4fba5
13 changed files with 113 additions and 167 deletions
|
@ -15,6 +15,7 @@ const ButtonSettingsBlock = ( { title, description, ...props } ) => (
|
||||||
</Header>
|
</Header>
|
||||||
<Action>
|
<Action>
|
||||||
<Button
|
<Button
|
||||||
|
isBusy={ props.actionProps?.isBusy }
|
||||||
variant={ props.actionProps?.buttonType }
|
variant={ props.actionProps?.buttonType }
|
||||||
onClick={
|
onClick={
|
||||||
props.actionProps?.callback
|
props.actionProps?.callback
|
||||||
|
|
|
@ -8,8 +8,21 @@ import {
|
||||||
ButtonSettingsBlock,
|
ButtonSettingsBlock,
|
||||||
} from '../../../../ReusableComponents/SettingsBlocks';
|
} from '../../../../ReusableComponents/SettingsBlocks';
|
||||||
import SettingsBlock from '../../../../ReusableComponents/SettingsBlocks/SettingsBlock';
|
import SettingsBlock from '../../../../ReusableComponents/SettingsBlocks/SettingsBlock';
|
||||||
|
import { CommonHooks } from '../../../../../data';
|
||||||
|
import { useState } from '@wordpress/element';
|
||||||
|
|
||||||
const Troubleshooting = ( { updateFormValue, settings } ) => {
|
const Troubleshooting = ( { updateFormValue, settings } ) => {
|
||||||
|
const { webhooks, registerWebhooks, simulateWebhooks } =
|
||||||
|
CommonHooks.useWebhooks();
|
||||||
|
|
||||||
|
const [ resubscribing, setResubscribing ] = useState( false );
|
||||||
|
|
||||||
|
const resubscribeWebhooks = async () => {
|
||||||
|
setResubscribing( true );
|
||||||
|
await registerWebhooks();
|
||||||
|
setResubscribing( false );
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AccordionSettingsBlock
|
<AccordionSettingsBlock
|
||||||
className="ppcp-r-settings-block--troubleshooting"
|
className="ppcp-r-settings-block--troubleshooting"
|
||||||
|
@ -61,7 +74,7 @@ const Troubleshooting = ( { updateFormValue, settings } ) => {
|
||||||
.
|
.
|
||||||
</Description>
|
</Description>
|
||||||
</Header>
|
</Header>
|
||||||
<HooksTable data={ hooksExampleData() } />
|
<HooksTable data={ webhooks } />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
] }
|
] }
|
||||||
|
@ -78,11 +91,8 @@ const Troubleshooting = ( { updateFormValue, settings } ) => {
|
||||||
) }
|
) }
|
||||||
actionProps={ {
|
actionProps={ {
|
||||||
buttonType: 'secondary',
|
buttonType: 'secondary',
|
||||||
callback: () =>
|
isBusy: resubscribing,
|
||||||
console.log(
|
callback: () => resubscribeWebhooks(),
|
||||||
'Resubscribe webhooks',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
),
|
|
||||||
value: __(
|
value: __(
|
||||||
'Resubscribe webhooks',
|
'Resubscribe webhooks',
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
|
@ -97,11 +107,7 @@ const Troubleshooting = ( { updateFormValue, settings } ) => {
|
||||||
) }
|
) }
|
||||||
actionProps={ {
|
actionProps={ {
|
||||||
buttonType: 'secondary',
|
buttonType: 'secondary',
|
||||||
callback: () =>
|
callback: () => simulateWebhooks(),
|
||||||
console.log(
|
|
||||||
'Simulate webhooks',
|
|
||||||
'woocommerce-paypal-payments'
|
|
||||||
),
|
|
||||||
value: __(
|
value: __(
|
||||||
'Simulate webhooks',
|
'Simulate webhooks',
|
||||||
'woocommerce-paypal-payments'
|
'woocommerce-paypal-payments'
|
||||||
|
@ -112,32 +118,6 @@ const Troubleshooting = ( { updateFormValue, settings } ) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hooksExampleData = () => {
|
|
||||||
return {
|
|
||||||
url: 'https://www.rt3.tech/wordpress/paypal-ux-testin/index.php?rest_route=/paypal/v1/incoming',
|
|
||||||
hooks: [
|
|
||||||
'billing plan pricing-change activated',
|
|
||||||
'billing plan updated',
|
|
||||||
'billing subscription cancelled',
|
|
||||||
'catalog product updated',
|
|
||||||
'checkout order approved',
|
|
||||||
'checkout order completed',
|
|
||||||
'checkout payment-approval reversed',
|
|
||||||
'payment authorization voided',
|
|
||||||
'payment capture completed',
|
|
||||||
'payment capture denied',
|
|
||||||
'payment capture pending',
|
|
||||||
'payment capture refunded',
|
|
||||||
'payment capture reversed',
|
|
||||||
'payment order cancelled',
|
|
||||||
'payment sale completed',
|
|
||||||
'payment sale refunded',
|
|
||||||
'vault payment-token created',
|
|
||||||
'vault payment-token deleted',
|
|
||||||
],
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const HooksTable = ( { data } ) => {
|
const HooksTable = ( { data } ) => {
|
||||||
return (
|
return (
|
||||||
<table className="ppcp-r-table">
|
<table className="ppcp-r-table">
|
||||||
|
@ -156,15 +136,11 @@ const HooksTable = ( { data } ) => {
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="ppcp-r-table__hooks-url">{ data?.url }</td>
|
<td className="ppcp-r-table__hooks-url">{ data?.[ 0 ] }</td>
|
||||||
<td className="ppcp-r-table__hooks-events">
|
<td
|
||||||
{ data.hooks.map( ( hook, index ) => (
|
className="ppcp-r-table__hooks-events"
|
||||||
<span key={ hook }>
|
dangerouslySetInnerHTML={ { __html: data?.[ 1 ] } }
|
||||||
{ hook }{ ' ' }
|
></td>
|
||||||
{ index !== data.hooks.length - 1 && ',' }
|
|
||||||
</span>
|
|
||||||
) ) }
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -23,4 +23,5 @@ export default {
|
||||||
DO_SANDBOX_LOGIN: 'COMMON:DO_SANDBOX_LOGIN',
|
DO_SANDBOX_LOGIN: 'COMMON:DO_SANDBOX_LOGIN',
|
||||||
DO_PRODUCTION_LOGIN: 'COMMON:DO_PRODUCTION_LOGIN',
|
DO_PRODUCTION_LOGIN: 'COMMON:DO_PRODUCTION_LOGIN',
|
||||||
DO_REFRESH_MERCHANT: 'COMMON:DO_REFRESH_MERCHANT',
|
DO_REFRESH_MERCHANT: 'COMMON:DO_REFRESH_MERCHANT',
|
||||||
|
DO_WEBHOOKS_DATA: 'COMMON:DO_WEBHOOKS_DATA',
|
||||||
};
|
};
|
||||||
|
|
|
@ -134,6 +134,11 @@ export const setClientSecret = ( clientSecret ) => ( {
|
||||||
payload: { clientSecret },
|
payload: { clientSecret },
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
export const setWebhooks = ( webhooks ) => ( {
|
||||||
|
type: ACTION_TYPES.SET_PERSISTENT,
|
||||||
|
payload: { webhooks },
|
||||||
|
} );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Side effect. Saves the persistent details to the WP database.
|
* Side effect. Saves the persistent details to the WP database.
|
||||||
*
|
*
|
||||||
|
|
|
@ -53,3 +53,5 @@ export const REST_MANUAL_CONNECTION_PATH = '/wc/v3/wc_paypal/connect_manual';
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const REST_CONNECTION_URL_PATH = '/wc/v3/wc_paypal/login_link';
|
export const REST_CONNECTION_URL_PATH = '/wc/v3/wc_paypal/login_link';
|
||||||
|
export const REST_WEBHOOKS = '/wc/v3/wc_paypal/webhook_settings';
|
||||||
|
export const REST_WEBHOOKS_SIMULATE = '/wc/v3/wc_paypal/webhooks_simulate';
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { useCallback } from '@wordpress/element';
|
import { useCallback } from '@wordpress/element';
|
||||||
|
import { REST_WEBHOOKS, REST_WEBHOOKS_SIMULATE } from './constants';
|
||||||
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
|
|
||||||
import { STORE_NAME } from './constants';
|
import { STORE_NAME } from './constants';
|
||||||
|
|
||||||
|
@ -31,6 +33,7 @@ const useHooks = () => {
|
||||||
setManualConnectionMode,
|
setManualConnectionMode,
|
||||||
setClientId,
|
setClientId,
|
||||||
setClientSecret,
|
setClientSecret,
|
||||||
|
setWebhooks,
|
||||||
connectToSandbox,
|
connectToSandbox,
|
||||||
connectToProduction,
|
connectToProduction,
|
||||||
connectViaIdAndSecret,
|
connectViaIdAndSecret,
|
||||||
|
@ -44,7 +47,7 @@ const useHooks = () => {
|
||||||
const clientSecret = usePersistent( 'clientSecret' );
|
const clientSecret = usePersistent( 'clientSecret' );
|
||||||
const isSandboxMode = usePersistent( 'useSandbox' );
|
const isSandboxMode = usePersistent( 'useSandbox' );
|
||||||
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
||||||
|
const webhooks = usePersistent( 'webhooks' );
|
||||||
const merchant = useSelect(
|
const merchant = useSelect(
|
||||||
( select ) => select( STORE_NAME ).merchant(),
|
( select ) => select( STORE_NAME ).merchant(),
|
||||||
[]
|
[]
|
||||||
|
@ -77,11 +80,32 @@ const useHooks = () => {
|
||||||
setClientSecret: ( value ) => {
|
setClientSecret: ( value ) => {
|
||||||
return savePersistent( setClientSecret, value );
|
return savePersistent( setClientSecret, value );
|
||||||
},
|
},
|
||||||
|
setWebhooks: async () => {
|
||||||
|
const response = await apiFetch( {
|
||||||
|
method: 'GET',
|
||||||
|
path: REST_WEBHOOKS,
|
||||||
|
} );
|
||||||
|
setWebhooks( response?.data?.webhooks );
|
||||||
|
},
|
||||||
|
registerWebhooks: async () => {
|
||||||
|
const response = await apiFetch( {
|
||||||
|
method: 'POST',
|
||||||
|
path: REST_WEBHOOKS,
|
||||||
|
} );
|
||||||
|
setWebhooks( response?.data?.webhooks );
|
||||||
|
},
|
||||||
|
simulateWebhooks: async () => {
|
||||||
|
const response = await apiFetch( {
|
||||||
|
path: REST_WEBHOOKS_SIMULATE,
|
||||||
|
} );
|
||||||
|
console.log( response );
|
||||||
|
},
|
||||||
connectToSandbox,
|
connectToSandbox,
|
||||||
connectToProduction,
|
connectToProduction,
|
||||||
connectViaIdAndSecret,
|
connectViaIdAndSecret,
|
||||||
merchant,
|
merchant,
|
||||||
wooSettings,
|
wooSettings,
|
||||||
|
webhooks,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -125,6 +149,10 @@ export const useWooSettings = () => {
|
||||||
return wooSettings;
|
return wooSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useWebhooks = () => {
|
||||||
|
const { webhooks, setWebhooks, registerWebhooks } = useHooks();
|
||||||
|
return { webhooks, setWebhooks, registerWebhooks };
|
||||||
|
};
|
||||||
export const useMerchantInfo = () => {
|
export const useMerchantInfo = () => {
|
||||||
const { merchant } = useHooks();
|
const { merchant } = useHooks();
|
||||||
const { refreshMerchantData } = useDispatch( STORE_NAME );
|
const { refreshMerchantData } = useDispatch( STORE_NAME );
|
||||||
|
|
|
@ -35,6 +35,7 @@ const defaultPersistent = Object.freeze( {
|
||||||
useManualConnection: false,
|
useManualConnection: false,
|
||||||
clientId: '',
|
clientId: '',
|
||||||
clientSecret: '',
|
clientSecret: '',
|
||||||
|
webhooks: 0,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Reducer logic.
|
// Reducer logic.
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { dispatch } from '@wordpress/data';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { apiFetch } from '@wordpress/data-controls';
|
import { apiFetch } from '@wordpress/data-controls';
|
||||||
|
|
||||||
import { STORE_NAME, REST_HYDRATE_PATH } from './constants';
|
import { STORE_NAME, REST_HYDRATE_PATH, REST_WEBHOOKS } from './constants';
|
||||||
|
|
||||||
export const resolvers = {
|
export const resolvers = {
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +21,9 @@ export const resolvers = {
|
||||||
*persistentData() {
|
*persistentData() {
|
||||||
try {
|
try {
|
||||||
const result = yield apiFetch( { path: REST_HYDRATE_PATH } );
|
const result = yield apiFetch( { path: REST_HYDRATE_PATH } );
|
||||||
|
const webhooks = yield apiFetch( { path: REST_WEBHOOKS } );
|
||||||
|
|
||||||
|
result.data = { ...result.data, ...webhooks.data };
|
||||||
yield dispatch( STORE_NAME ).hydrate( result );
|
yield dispatch( STORE_NAME ).hydrate( result );
|
||||||
yield dispatch( STORE_NAME ).setIsReady( true );
|
yield dispatch( STORE_NAME ).setIsReady( true );
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
|
|
|
@ -33,3 +33,7 @@ export const merchant = ( state ) => {
|
||||||
export const wooSettings = ( state ) => {
|
export const wooSettings = ( state ) => {
|
||||||
return getState( state ).wooSettings || EMPTY_OBJ;
|
return getState( state ).wooSettings || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const webhooks = ( state ) => {
|
||||||
|
return getState( state ).webhooks || EMPTY_OBJ;
|
||||||
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ use WooCommerce\PayPalCommerce\Settings\Endpoint\ConnectManualRestEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Endpoint\SwitchSettingsUiEndpoint;
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\SwitchSettingsUiEndpoint;
|
||||||
|
use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator;
|
use WooCommerce\PayPalCommerce\Settings\Service\ConnectionUrlGenerator;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
|
use WooCommerce\PayPalCommerce\Settings\Service\OnboardingUrlManager;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
@ -83,6 +84,13 @@ return array(
|
||||||
$container->get( 'settings.service.connection-url-generators' ),
|
$container->get( 'settings.service.connection-url-generators' ),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'settings.rest.webhooks' => static function ( ContainerInterface $container ) : WebhookSettingsEndpoint {
|
||||||
|
return new WebhookSettingsEndpoint(
|
||||||
|
$container->get('webhook.status.registered-webhooks-data'),
|
||||||
|
$container->get( 'webhook.registrar'),
|
||||||
|
$container->get('webhook.status.simulation')
|
||||||
|
);
|
||||||
|
},
|
||||||
'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array {
|
'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array {
|
||||||
return array(
|
return array(
|
||||||
'AR',
|
'AR',
|
||||||
|
|
|
@ -58,6 +58,9 @@ class CommonRestEndpoint extends RestEndpoint {
|
||||||
'js_name' => 'clientSecret',
|
'js_name' => 'clientSecret',
|
||||||
'sanitize' => 'sanitize_text_field',
|
'sanitize' => 'sanitize_text_field',
|
||||||
),
|
),
|
||||||
|
'webhooks' => array(
|
||||||
|
'js_name' => 'webhooks'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,88 +9,24 @@ declare( strict_types = 1 );
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
||||||
|
|
||||||
use WP_REST_Server;
|
use WooCommerce\PayPalCommerce\Webhooks\Status\WebhookSimulation;
|
||||||
|
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use WP_REST_Request;
|
use WP_REST_Server;
|
||||||
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* REST controller for the onboarding module.
|
|
||||||
*
|
|
||||||
* This API acts as the intermediary between the "external world" and our
|
|
||||||
* internal data model.
|
|
||||||
*/
|
|
||||||
class WebhookSettingsEndpoint extends RestEndpoint {
|
class WebhookSettingsEndpoint extends RestEndpoint {
|
||||||
/**
|
protected $rest_base = 'webhook_settings';
|
||||||
* The base path for this REST controller.
|
protected string $rest_simulate_base = 'webhooks_simulate';
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $rest_base = 'webhook-settings';
|
|
||||||
|
|
||||||
/**
|
private array $webhooksData;
|
||||||
* The settings instance.
|
private WebhookRegistrar $webhookRegistrar;
|
||||||
*
|
private WebhookSimulation $webhookSimulation;
|
||||||
* @var OnboardingProfile
|
|
||||||
*/
|
|
||||||
protected OnboardingProfile $profile;
|
|
||||||
|
|
||||||
/**
|
public function __construct(array $webhooksData, WebhookRegistrar $webhookRegistrar, WebhookSimulation $webhookSimulation)
|
||||||
* Field mapping for request to profile transformation.
|
{
|
||||||
*
|
$this->webhooksData = $webhooksData;
|
||||||
* @var array
|
$this->webhookRegistrar = $webhookRegistrar;
|
||||||
*/
|
$this->webhookSimulation = $webhookSimulation;
|
||||||
private array $field_map = array(
|
|
||||||
'completed' => array(
|
|
||||||
'js_name' => 'completed',
|
|
||||||
'sanitize' => 'to_boolean',
|
|
||||||
),
|
|
||||||
'step' => array(
|
|
||||||
'js_name' => 'step',
|
|
||||||
'sanitize' => 'to_number',
|
|
||||||
),
|
|
||||||
'is_casual_seller' => array(
|
|
||||||
'js_name' => 'isCasualSeller',
|
|
||||||
'sanitize' => 'to_boolean',
|
|
||||||
),
|
|
||||||
'are_optional_payment_methods_enabled' => array(
|
|
||||||
'js_name' => 'areOptionalPaymentMethodsEnabled',
|
|
||||||
'sanitize' => 'to_boolean',
|
|
||||||
),
|
|
||||||
'products' => array(
|
|
||||||
'js_name' => 'products',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Map the internal flags to JS names.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private array $flag_map = array(
|
|
||||||
'can_use_casual_selling' => array(
|
|
||||||
'js_name' => 'canUseCasualSelling',
|
|
||||||
),
|
|
||||||
'can_use_vaulting' => array(
|
|
||||||
'js_name' => 'canUseVaulting',
|
|
||||||
),
|
|
||||||
'can_use_card_payments' => array(
|
|
||||||
'js_name' => 'canUseCardPayments',
|
|
||||||
),
|
|
||||||
'can_use_subscriptions' => array(
|
|
||||||
'js_name' => 'canUseSubscriptions',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param OnboardingProfile $profile The settings instance.
|
|
||||||
*/
|
|
||||||
public function __construct( OnboardingProfile $profile ) {
|
|
||||||
$this->profile = $profile;
|
|
||||||
|
|
||||||
$this->field_map['products']['sanitize'] = fn( $list ) => array_map( 'sanitize_text_field', $list );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,65 +39,43 @@ class WebhookSettingsEndpoint extends RestEndpoint {
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::READABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( $this, 'get_details' ),
|
'callback' => array( $this, 'get_webhooks' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array($this, 'register_webhooks'),
|
||||||
|
'permission_callback' => array($this, 'check_permission')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
register_rest_route(
|
register_rest_route(
|
||||||
$this->namespace,
|
$this->namespace,
|
||||||
'/' . $this->rest_base,
|
'/' . $this->rest_simulate_base,
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::EDITABLE,
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array( $this, 'update_details' ),
|
'callback' => array( $this, 'simulate_webhooks' ),
|
||||||
'permission_callback' => array( $this, 'check_permission' ),
|
'permission_callback' => array( $this, 'check_permission' ),
|
||||||
),
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function get_webhooks(): WP_REST_Response{
|
||||||
* Returns all details of the current onboarding wizard progress.
|
return $this->return_success( ["webhooks" => $this->webhooksData['data'][0]] );
|
||||||
*
|
|
||||||
* @return WP_REST_Response The current state of the onboarding wizard.
|
|
||||||
*/
|
|
||||||
public function get_details() : WP_REST_Response {
|
|
||||||
$js_data = $this->sanitize_for_javascript(
|
|
||||||
$this->profile->to_array(),
|
|
||||||
$this->field_map
|
|
||||||
);
|
|
||||||
|
|
||||||
$js_flags = $this->sanitize_for_javascript(
|
|
||||||
$this->profile->get_flags(),
|
|
||||||
$this->flag_map
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->return_success(
|
|
||||||
$js_data,
|
|
||||||
array(
|
|
||||||
'flags' => $js_flags,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function register_webhooks(): WP_REST_Response{
|
||||||
* Updates onboarding details based on the request.
|
if ( ! $this->webhookRegistrar->register() ) {
|
||||||
*
|
return $this->return_error('Webhook subscription failed.');
|
||||||
* @param WP_REST_Request $request Full data about the request.
|
}
|
||||||
*
|
|
||||||
* @return WP_REST_Response The updated state of the onboarding wizard.
|
|
||||||
*/
|
|
||||||
public function update_details( WP_REST_Request $request ) : WP_REST_Response {
|
|
||||||
$wp_data = $this->sanitize_for_wordpress(
|
|
||||||
$request->get_params(),
|
|
||||||
$this->field_map
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->profile->from_array( $wp_data );
|
return $this->return_success(["webhooks" => $this->webhooksData['data'][0]]);
|
||||||
$this->profile->save();
|
}
|
||||||
|
|
||||||
return $this->get_details();
|
public function simulate_webhooks(): WP_REST_Response{
|
||||||
|
$this->return_success(['success' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,7 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
||||||
$container->get( 'settings.rest.common' ),
|
$container->get( 'settings.rest.common' ),
|
||||||
$container->get( 'settings.rest.connect_manual' ),
|
$container->get( 'settings.rest.connect_manual' ),
|
||||||
$container->get( 'settings.rest.login_link' ),
|
$container->get( 'settings.rest.login_link' ),
|
||||||
|
$container->get('settings.rest.webhooks')
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $endpoints as $endpoint ) {
|
foreach ( $endpoints as $endpoint ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue