From 83912f2b93e2b0aea8f6657631ff35caadef9c60 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 29 Jan 2025 16:41:50 +0100 Subject: [PATCH 1/9] Add rest endpoint boilerplate --- modules/ppcp-settings/services.php | 4 + .../Endpoint/PayLaterMessagingEndpoint.php | 88 +++++++++++++++++++ modules/ppcp-settings/src/SettingsModule.php | 1 + 3 files changed, 93 insertions(+) create mode 100644 modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index cf397b8bf..cc993f0d6 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -21,6 +21,7 @@ use WooCommerce\PayPalCommerce\Settings\Endpoint\AuthenticationRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\CommonRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\LoginLinkRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\OnboardingRestEndpoint; +use WooCommerce\PayPalCommerce\Settings\Endpoint\PayLaterMessagingEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\PaymentRestEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\RefreshFeatureStatusEndpoint; use WooCommerce\PayPalCommerce\Settings\Endpoint\WebhookSettingsEndpoint; @@ -120,6 +121,9 @@ return array( $container->get( 'webhook.status.simulation' ) ); }, + 'settings.rest.pay_later_messaging' => static function ( ContainerInterface $container ) : PayLaterMessagingEndpoint { + return new PayLaterMessagingEndpoint(); + }, 'settings.casual-selling.supported-countries' => static function ( ContainerInterface $container ) : array { return array( 'AR', diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php new file mode 100644 index 000000000..5e5643261 --- /dev/null +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -0,0 +1,88 @@ +namespace, + '/' . $this->rest_base, + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_details' ), + 'permission_callback' => array( $this, 'check_permission' ), + ) + ); + + /** + * POST wc/v3/wc_paypal/pay_later_messaging + * { + * [gateway_id]: { + * enabled + * title + * description + * } + * } + */ + register_rest_route( + $this->namespace, + '/' . $this->rest_base, + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'update_details' ), + 'permission_callback' => array( $this, 'check_permission' ), + ) + ); + } + + /** + * Returns all payment methods details. + * + * @return WP_REST_Response The current payment methods details. + */ + public function get_details() : WP_REST_Response { + return $this->return_success( array() ); + } + + /** + * Updates payment methods details based on the request. + * + * @param WP_REST_Request $request Full data about the request. + * + * @return WP_REST_Response The updated payment methods details. + */ + public function update_details( WP_REST_Request $request ) : WP_REST_Response { + return $this->get_details(); + } + +} diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php index b7c334425..c6fea6621 100644 --- a/modules/ppcp-settings/src/SettingsModule.php +++ b/modules/ppcp-settings/src/SettingsModule.php @@ -238,6 +238,7 @@ class SettingsModule implements ServiceModule, ExecutableModule { 'settings' => $container->get( 'settings.rest.settings' ), 'styling' => $container->get( 'settings.rest.styling' ), 'todos' => $container->get( 'settings.rest.todos' ), + 'pay_later_messaging' => $container->get( 'settings.rest.pay_later_messaging' ), ); foreach ( $endpoints as $endpoint ) { From 40edcdfc3d57db84a72dcb62420746456d91dbac Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 29 Jan 2025 16:51:12 +0100 Subject: [PATCH 2/9] Add get response details --- modules/ppcp-settings/services.php | 4 ++- .../Endpoint/PayLaterMessagingEndpoint.php | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 97f561a9e..0016a0096 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -127,7 +127,9 @@ return array( ); }, 'settings.rest.pay_later_messaging' => static function ( ContainerInterface $container ) : PayLaterMessagingEndpoint { - return new PayLaterMessagingEndpoint(); + return new PayLaterMessagingEndpoint( + $container->get( 'wcgateway.settings' ) + ); }, 'settings.rest.settings' => static function ( ContainerInterface $container ) : SettingsRestEndpoint { return new SettingsRestEndpoint( diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php index 5e5643261..5dfbe7613 100644 --- a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -9,6 +9,8 @@ declare( strict_types = 1 ); namespace WooCommerce\PayPalCommerce\Settings\Endpoint; +use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory; +use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WP_REST_Request; use WP_REST_Response; use WP_REST_Server; @@ -27,6 +29,22 @@ class PayLaterMessagingEndpoint extends RestEndpoint { */ protected $rest_base = 'pay_later_messaging'; + /** + * The settings. + * + * @var Settings + */ + protected $settings; + + /** + * PayLaterMessagingEndpoint constructor. + * + * @param Settings $settings The settings. + */ + public function __construct( Settings $settings ) { + $this->settings = $settings; + } + /** * Configure REST API routes. */ @@ -46,13 +64,6 @@ class PayLaterMessagingEndpoint extends RestEndpoint { /** * POST wc/v3/wc_paypal/pay_later_messaging - * { - * [gateway_id]: { - * enabled - * title - * description - * } - * } */ register_rest_route( $this->namespace, @@ -71,7 +82,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint { * @return WP_REST_Response The current payment methods details. */ public function get_details() : WP_REST_Response { - return $this->return_success( array() ); + return $this->return_success( ( new ConfigFactory() )->from_settings( $this->settings ) ); } /** From 442a33778fdd6993f8d4e85ff587046adcf6d2cf Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 29 Jan 2025 17:20:10 +0100 Subject: [PATCH 3/9] Add endpoint save config --- .../src/Endpoint/SaveConfig.php | 2 +- modules/ppcp-settings/services.php | 3 ++- .../Endpoint/PayLaterMessagingEndpoint.php | 23 ++++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php b/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php index df4e4affa..b1f77de85 100644 --- a/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php +++ b/modules/ppcp-paylater-configurator/src/Endpoint/SaveConfig.php @@ -94,7 +94,7 @@ class SaveConfig { * * @param array $config The configurator config. */ - private function save_config( array $config ): void { + public function save_config( array $config ): void { $this->settings->set( 'pay_later_enable_styling_per_messaging_location', true ); $this->settings->set( 'pay_later_messaging_enabled', true ); diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 0016a0096..3ce60b18e 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -128,7 +128,8 @@ return array( }, 'settings.rest.pay_later_messaging' => static function ( ContainerInterface $container ) : PayLaterMessagingEndpoint { return new PayLaterMessagingEndpoint( - $container->get( 'wcgateway.settings' ) + $container->get( 'wcgateway.settings' ), + $container->get( 'paylater-configurator.endpoint.save-config' ) ); }, 'settings.rest.settings' => static function ( ContainerInterface $container ) : SettingsRestEndpoint { diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php index 5dfbe7613..c39fa056f 100644 --- a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -9,6 +9,7 @@ declare( strict_types = 1 ); namespace WooCommerce\PayPalCommerce\Settings\Endpoint; +use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory; use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings; use WP_REST_Request; @@ -36,13 +37,22 @@ class PayLaterMessagingEndpoint extends RestEndpoint { */ protected $settings; + /** + * Save config handler. + * + * @var SaveConfig + */ + private $save_config; + /** * PayLaterMessagingEndpoint constructor. * - * @param Settings $settings The settings. + * @param Settings $settings The settings. + * @param SaveConfig $save_config Save config handler. */ - public function __construct( Settings $settings ) { - $this->settings = $settings; + public function __construct( Settings $settings, SaveConfig $save_config ) { + $this->settings = $settings; + $this->save_config = $save_config; } /** @@ -77,7 +87,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint { } /** - * Returns all payment methods details. + * Returns Pay Later Messaging configuration details. * * @return WP_REST_Response The current payment methods details. */ @@ -86,14 +96,15 @@ class PayLaterMessagingEndpoint extends RestEndpoint { } /** - * Updates payment methods details based on the request. + * Updates Pay Later Messaging configuration details based on the request. * * @param WP_REST_Request $request Full data about the request. * * @return WP_REST_Response The updated payment methods details. */ public function update_details( WP_REST_Request $request ) : WP_REST_Response { + $this->save_config->save_config( $request->get_params() ); + return $this->get_details(); } - } From 0e89cde688d0357cf8f5f864bc815e95868942f3 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 29 Jan 2025 17:57:50 +0100 Subject: [PATCH 4/9] Add data store boilerplate --- .../ppcp-settings/resources/js/data/index.js | 13 ++- .../js/data/pay-later-messaging/README.md | 45 +++++++++++ .../data/pay-later-messaging/action-types.js | 18 +++++ .../js/data/pay-later-messaging/actions.js | 80 +++++++++++++++++++ .../js/data/pay-later-messaging/constants.js | 28 +++++++ .../js/data/pay-later-messaging/controls.js | 23 ++++++ .../js/data/pay-later-messaging/hooks.js | 50 ++++++++++++ .../js/data/pay-later-messaging/index.js | 32 ++++++++ .../js/data/pay-later-messaging/reducer.js | 62 ++++++++++++++ .../js/data/pay-later-messaging/resolvers.js | 39 +++++++++ .../js/data/pay-later-messaging/selectors.js | 21 +++++ .../Endpoint/PayLaterMessagingEndpoint.php | 2 +- 12 files changed, 411 insertions(+), 2 deletions(-) create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/action-types.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/actions.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/constants.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/controls.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/index.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js create mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/selectors.js diff --git a/modules/ppcp-settings/resources/js/data/index.js b/modules/ppcp-settings/resources/js/data/index.js index 0985aa972..227a62226 100644 --- a/modules/ppcp-settings/resources/js/data/index.js +++ b/modules/ppcp-settings/resources/js/data/index.js @@ -5,8 +5,17 @@ import * as Payment from './payment'; import * as Settings from './settings'; import * as Styling from './styling'; import * as Todos from './todos'; +import * as PayLaterMessaging from './pay-later-messaging'; -const stores = [ Onboarding, Common, Payment, Settings, Styling, Todos ]; +const stores = [ + Onboarding, + Common, + Payment, + Settings, + Styling, + Todos, + PayLaterMessaging, +]; stores.forEach( ( store ) => { try { @@ -30,6 +39,7 @@ export const PaymentHooks = Payment.hooks; export const SettingsHooks = Settings.hooks; export const StylingHooks = Styling.hooks; export const TodosHooks = Todos.hooks; +export const PayLaterMessagingHooks = PayLaterMessaging.hooks; export const OnboardingStoreName = Onboarding.STORE_NAME; export const CommonStoreName = Common.STORE_NAME; @@ -37,6 +47,7 @@ export const PaymentStoreName = Payment.STORE_NAME; export const SettingsStoreName = Settings.STORE_NAME; export const StylingStoreName = Styling.STORE_NAME; export const TodosStoreName = Todos.STORE_NAME; +export const PayLaterMessagingStoreName = PayLaterMessaging.STORE_NAME; export * from './configuration'; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md b/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md new file mode 100644 index 000000000..b97f6ca4c --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md @@ -0,0 +1,45 @@ +# Store template + +This template contains all files for a Redux store. + +## New Store: Redux integration + +1. Copy this folder, give it a correct name. +2. Check each file for `` placeholders and `TODO` remarks. +3. Edit the main store-index file and add the relevant store integration there. +4. Check the debug-module, and add relevant debug code. + - Register the store in the `reset()` method. + +--- + +Main store-index: +`modules/ppcp-settings/resources/js/data/index.js` + +Sample store integration: +```js +import * as YourStore from './yourStore'; +// ... +YourStore.initStore(); +// ... +export const YourStoreHooks = YourStore.hooks; +// ... +export const YourStoreName = YourStore.STORE_NAME; +// ... +addDebugTools( window.ppcpSettings, [ ..., YourStoreName ] ); +``` + +--- + +### New Store: PHP integration + +1. Create the **REST endpoint** for hydrating and persisting data. + - `modules/ppcp-settings/src/Endpoint/YourStoreRestEndpoint.php` + - Extend from base class `RestEndpoint` +2. Create the **data model** class to manage the DB interaction. + - `modules/ppcp-settings/src/Data/YourStoreSettings.php` + - Extend from base class `AbstractDataModel` +3. Create relevant **DI services** for both files. + - `modules/ppcp-settings/services.php` +4. Register the REST endpoint in the **service module**. + - `modules/ppcp-settings/src/SettingsModule.php` + - Find the action `rest_api_init` diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/action-types.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/action-types.js new file mode 100644 index 000000000..70913ddd6 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/action-types.js @@ -0,0 +1,18 @@ +/** + * Action Types: Define unique identifiers for actions across all store modules. + * + * @file + */ + +export default { + // Transient data. + SET_TRANSIENT: 'PAY_LATER_MESSAGING:SET_TRANSIENT', + + // Persistent data. + SET_PERSISTENT: 'PAY_LATER_MESSAGING:SET_PERSISTENT', + RESET: 'PAY_LATER_MESSAGING:RESET', + HYDRATE: 'PAY_LATER_MESSAGING:HYDRATE', + + // Controls - always start with "DO_". + DO_PERSIST_DATA: 'PAY_LATER_MESSAGING:DO_PERSIST_DATA', +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/actions.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/actions.js new file mode 100644 index 000000000..59d68d37c --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/actions.js @@ -0,0 +1,80 @@ +/** + * Action Creators: Define functions to create action objects. + * + * These functions update state or trigger side effects (e.g., async operations). + * Actions are categorized as Transient, Persistent, or Side effect. + * + * @file + */ + +import { select } from '@wordpress/data'; + +import ACTION_TYPES from './action-types'; +import { STORE_NAME } from './constants'; + +/** + * @typedef {Object} Action An action object that is handled by a reducer or control. + * @property {string} type - The action type. + * @property {Object?} payload - Optional payload for the action. + */ + +/** + * Special. Resets all values in the store to initial defaults. + * + * @return {Action} The action. + */ +export const reset = () => ( { type: ACTION_TYPES.RESET } ); + +/** + * Persistent. Set the full store details during app initialization. + * + * @param {{data: {}, flags?: {}}} payload + * @return {Action} The action. + */ +export const hydrate = ( payload ) => ( { + type: ACTION_TYPES.HYDRATE, + payload, +} ); + +/** + * Generic transient-data updater. + * + * @param {string} prop Name of the property to update. + * @param {any} value The new value of the property. + * @return {Action} The action. + */ +export const setTransient = ( prop, value ) => ( { + type: ACTION_TYPES.SET_TRANSIENT, + payload: { [ prop ]: value }, +} ); + +/** + * Generic persistent-data updater. + * + * @param {string} prop Name of the property to update. + * @param {any} value The new value of the property. + * @return {Action} The action. + */ +export const setPersistent = ( prop, value ) => ( { + type: ACTION_TYPES.SET_PERSISTENT, + payload: { [ prop ]: value }, +} ); + +/** + * Transient. Marks the store as "ready", i.e., fully initialized. + * + * @param {boolean} isReady + * @return {Action} The action. + */ +export const setIsReady = ( isReady ) => setTransient( 'isReady', isReady ); + +/** + * Side effect. Triggers the persistence of store data to the server. + * + * @return {Action} The action. + */ +export const persist = function* () { + const data = yield select( STORE_NAME ).persistentData(); + + yield { type: ACTION_TYPES.DO_PERSIST_DATA, data }; +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/constants.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/constants.js new file mode 100644 index 000000000..09f3bab52 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/constants.js @@ -0,0 +1,28 @@ +/** + * Name of the Redux store module. + * + * Used by: Reducer, Selector, Index + * + * @type {string} + */ +export const STORE_NAME = 'wc/paypal/pay_later_messaging'; + +/** + * REST path to hydrate data of this module by loading data from the WP DB. + * + * Used by: Resolvers + * See: PayLaterMessagingEndpoint.php + * + * @type {string} + */ +export const REST_HYDRATE_PATH = '/wc/v3/wc_paypal/pay_later_messaging'; + +/** + * REST path to persist data of this module to the WP DB. + * + * Used by: Controls + * See: PayLaterMessagingEndpoint.php + * + * @type {string} + */ +export const REST_PERSIST_PATH = '/wc/v3/wc_paypal/pay_later_messaging'; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/controls.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/controls.js new file mode 100644 index 000000000..9295b62bc --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/controls.js @@ -0,0 +1,23 @@ +/** + * Controls: Implement side effects, typically asynchronous operations. + * + * Controls use ACTION_TYPES keys as identifiers. + * They are triggered by corresponding actions and handle external interactions. + * + * @file + */ + +import apiFetch from '@wordpress/api-fetch'; + +import { REST_PERSIST_PATH } from './constants'; +import ACTION_TYPES from './action-types'; + +export const controls = { + async [ ACTION_TYPES.DO_PERSIST_DATA ]( { data } ) { + return await apiFetch( { + path: REST_PERSIST_PATH, + method: 'POST', + data, + } ); + }, +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js new file mode 100644 index 000000000..b6878c2a9 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js @@ -0,0 +1,50 @@ +/** + * Hooks: Provide the main API for components to interact with the store. + * + * These encapsulate store interactions, offering a consistent interface. + * Hooks simplify data access and manipulation for components. + * + * @file + */ + +import { useDispatch } from '@wordpress/data'; + +import { createHooksForStore } from '../utils'; +import { STORE_NAME } from './constants'; + +const useHooks = () => { + const { useTransient, usePersistent } = createHooksForStore( STORE_NAME ); + const { persist } = useDispatch( STORE_NAME ); + + // Read-only flags and derived state. + // Nothing here yet. + + // Transient accessors. + const [ isReady ] = useTransient( 'isReady' ); + + // Persistent accessors. + // TODO: Replace with real property. + const [ sampleValue, setSampleValue ] = usePersistent( 'sampleValue' ); + + return { + persist, + isReady, + sampleValue, + setSampleValue, + }; +}; + +export const useState = () => { + const { persist, isReady } = useHooks(); + return { persist, isReady }; +}; + +// TODO: Replace with real hook. +export const useSampleValue = () => { + const { sampleValue, setSampleValue } = useHooks(); + + return { + sampleValue, + setSampleValue, + }; +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/index.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/index.js new file mode 100644 index 000000000..3bd6e4459 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/index.js @@ -0,0 +1,32 @@ +import { createReduxStore, register } from '@wordpress/data'; +import { controls as wpControls } from '@wordpress/data-controls'; + +import { STORE_NAME } from './constants'; +import reducer from './reducer'; +import * as selectors from './selectors'; +import * as actions from './actions'; +import * as hooks from './hooks'; +import { resolvers } from './resolvers'; +import { controls } from './controls'; + +/** + * Initializes and registers the settings store with WordPress data layer. + * Combines custom controls with WordPress data controls. + * + * @return {boolean} True if initialization succeeded, false otherwise. + */ +export const initStore = () => { + const store = createReduxStore( STORE_NAME, { + reducer, + controls: { ...wpControls, ...controls }, + actions, + selectors, + resolvers, + } ); + + register( store ); + + return Boolean( wp.data.select( STORE_NAME ) ); +}; + +export { hooks, selectors, STORE_NAME }; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js new file mode 100644 index 000000000..7111d9302 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js @@ -0,0 +1,62 @@ +/** + * Reducer: Defines store structure and state updates for this module. + * + * Manages both transient (temporary) and persistent (saved) state. + * The initial state must define all properties, as dynamic additions are not supported. + * + * @file + */ + +import { createReducer, createReducerSetters } from '../utils'; +import ACTION_TYPES from './action-types'; + +// Store structure. + +// Transient: Values that are _not_ saved to the DB (like app lifecycle-flags). +const defaultTransient = Object.freeze( { + isReady: false, +} ); + +// Persistent: Values that are loaded from the DB. +const defaultPersistent = Object.freeze( { + // TODO: Add real DB properties here. + sampleValue: 'foo', + cart: {}, + checkout: {}, + product: {}, + shop: {}, + home: {}, + custom_placement: [], +} ); + +// Reducer logic. + +const [ changeTransient, changePersistent ] = createReducerSetters( + defaultTransient, + defaultPersistent +); + +const reducer = createReducer( defaultTransient, defaultPersistent, { + [ ACTION_TYPES.SET_TRANSIENT ]: ( state, payload ) => + changeTransient( state, payload ), + + [ ACTION_TYPES.SET_PERSISTENT ]: ( state, payload ) => + changePersistent( state, payload ), + + [ ACTION_TYPES.RESET ]: ( state ) => { + const cleanState = changeTransient( + changePersistent( state, defaultPersistent ), + defaultTransient + ); + + // Keep "read-only" details and initialization flags. + cleanState.isReady = true; + + return cleanState; + }, + + [ ACTION_TYPES.HYDRATE ]: ( state, payload ) => + changePersistent( state, payload.data ), +} ); + +export default reducer; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js new file mode 100644 index 000000000..4b9bc4230 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js @@ -0,0 +1,39 @@ +/** + * Resolvers: Handle asynchronous data fetching for the store. + * + * These functions update store state with data from external sources. + * Each resolver corresponds to a specific selector (selector with same name must exist). + * Resolvers are called automatically when selectors request unavailable data. + * + * @file + */ + +import { dispatch } from '@wordpress/data'; +import { __ } from '@wordpress/i18n'; +import { apiFetch } from '@wordpress/data-controls'; + +import { STORE_NAME, REST_HYDRATE_PATH } from './constants'; + +export const resolvers = { + /** + * Retrieve settings from the site's REST API. + */ + *persistentData() { + try { + const result = yield apiFetch( { path: REST_HYDRATE_PATH } ); + + console.log( result ); + + yield dispatch( STORE_NAME ).hydrate( result ); + yield dispatch( STORE_NAME ).setIsReady( true ); + } catch ( e ) { + yield dispatch( 'core/notices' ).createErrorNotice( + // TODO: Add the module name to the error message. + __( + 'Error retrieving Pay Later Messaging config details.', + 'woocommerce-paypal-payments' + ) + ); + } + }, +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/selectors.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/selectors.js new file mode 100644 index 000000000..14334fcf3 --- /dev/null +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/selectors.js @@ -0,0 +1,21 @@ +/** + * Selectors: Extract specific pieces of state from the store. + * + * These functions provide a consistent interface for accessing store data. + * They allow components to retrieve data without knowing the store structure. + * + * @file + */ + +const EMPTY_OBJ = Object.freeze( {} ); + +const getState = ( state ) => state || EMPTY_OBJ; + +export const persistentData = ( state ) => { + return getState( state ).data || EMPTY_OBJ; +}; + +export const transientData = ( state ) => { + const { data, ...transientState } = getState( state ); + return transientState || EMPTY_OBJ; +}; diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php index c39fa056f..d448e1a9b 100644 --- a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -100,7 +100,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint { * * @param WP_REST_Request $request Full data about the request. * - * @return WP_REST_Response The updated payment methods details. + * @return WP_REST_Response The updated Pay Later Messaging configuration details. */ public function update_details( WP_REST_Request $request ) : WP_REST_Response { $this->save_config->save_config( $request->get_params() ); From a652f21629a51b556522a559a36ded6bf09c9f01 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 30 Jan 2025 10:50:44 +0100 Subject: [PATCH 5/9] Read config from store --- .../resources/js/paylater-configurator.js | 1 + .../Screens/Overview/TabPayLaterMessaging.js | 5 ++-- .../js/data/pay-later-messaging/hooks.js | 28 +++++++++++++++++++ .../js/data/pay-later-messaging/resolvers.js | 2 -- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js index f3daad01e..27145de16 100644 --- a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js +++ b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js @@ -51,6 +51,7 @@ document.addEventListener( 'DOMContentLoaded', () => { .then( ( data ) => { if ( data.success ) { const config = data.data; + console.log( config ); merchantConfigurators.Messaging( { config, diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js index a3a3083c9..d22318d26 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js @@ -1,7 +1,8 @@ import React, { useEffect } from 'react'; +import { PayLaterMessagingHooks } from '../../../data'; const TabPayLaterMessaging = () => { - const config = {}; // Replace with the appropriate/saved configuration. + const { config } = PayLaterMessagingHooks.usePayLaterMessaging(); const PcpPayLaterConfigurator = window.ppcpSettings?.PcpPayLaterConfigurator; @@ -37,7 +38,7 @@ const TabPayLaterMessaging = () => { }, } ); } - }, [ PcpPayLaterConfigurator ] ); + }, [ PcpPayLaterConfigurator, config ] ); return (
{ // TODO: Replace with real property. const [ sampleValue, setSampleValue ] = usePersistent( 'sampleValue' ); + const [ cart ] = usePersistent( 'cart' ); + const [ checkout ] = usePersistent( 'checkout' ); + const [ product ] = usePersistent( 'product' ); + const [ shop ] = usePersistent( 'shop' ); + const [ home ] = usePersistent( 'home' ); + const [ custom_placement ] = usePersistent( 'custom_placement' ); + return { persist, isReady, sampleValue, setSampleValue, + cart, + checkout, + product, + shop, + home, + custom_placement, }; }; @@ -48,3 +61,18 @@ export const useSampleValue = () => { setSampleValue, }; }; + +export const usePayLaterMessaging = () => { + const { cart, checkout, product, shop, home, customPlacement } = useHooks(); + + return { + config: { + cart, + checkout, + product, + shop, + home, + customPlacement, + }, + }; +}; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js index 4b9bc4230..39ff6c343 100644 --- a/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/resolvers.js @@ -22,8 +22,6 @@ export const resolvers = { try { const result = yield apiFetch( { path: REST_HYDRATE_PATH } ); - console.log( result ); - yield dispatch( STORE_NAME ).hydrate( result ); yield dispatch( STORE_NAME ).setIsReady( true ); } catch ( e ) { From 66c6fb17b81e2da4e3ae25bff92426d20914b60e Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 30 Jan 2025 16:39:26 +0100 Subject: [PATCH 6/9] Save pay later messaging config to database --- .../Screens/Overview/TabPayLaterMessaging.js | 23 +++++--- .../resources/js/data/_example/hooks.js | 2 +- .../js/data/pay-later-messaging/hooks.js | 59 +++++++++++-------- .../js/data/pay-later-messaging/reducer.js | 2 - .../resources/js/hooks/useSaveSettings.js | 19 +++++- .../Endpoint/PayLaterMessagingEndpoint.php | 2 +- 6 files changed, 70 insertions(+), 37 deletions(-) diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js index d22318d26..274ef91c2 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Overview/TabPayLaterMessaging.js @@ -2,7 +2,15 @@ import React, { useEffect } from 'react'; import { PayLaterMessagingHooks } from '../../../data'; const TabPayLaterMessaging = () => { - const { config } = PayLaterMessagingHooks.usePayLaterMessaging(); + const { + config, + setCart, + setCheckout, + setProduct, + setShop, + setHome, + setCustom_placement, + } = PayLaterMessagingHooks.usePayLaterMessaging(); const PcpPayLaterConfigurator = window.ppcpSettings?.PcpPayLaterConfigurator; @@ -28,13 +36,12 @@ const TabPayLaterMessaging = () => { subheader: 'ppcp-r-paylater-configurator__subheader', }, onSave: ( data ) => { - /* - TODO: - - The saving will be handled in a separate PR. - - One option could be: - - When saving the settings, programmatically click on the configurator's - "Save Changes" button and send the request to PHP. - */ + setCart( data.config.cart ); + setCheckout( data.config.checkout ); + setProduct( data.config.product ); + setShop( data.config.shop ); + setHome( data.config.home ); + setCustom_placement( data.config.custom_placement ); }, } ); } diff --git a/modules/ppcp-settings/resources/js/data/_example/hooks.js b/modules/ppcp-settings/resources/js/data/_example/hooks.js index b6878c2a9..95db3765e 100644 --- a/modules/ppcp-settings/resources/js/data/_example/hooks.js +++ b/modules/ppcp-settings/resources/js/data/_example/hooks.js @@ -34,7 +34,7 @@ const useHooks = () => { }; }; -export const useState = () => { +export const useStore = () => { const { persist, isReady } = useHooks(); return { persist, isReady }; }; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js index 174e618e7..0f51051cd 100644 --- a/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/hooks.js @@ -23,47 +23,52 @@ const useHooks = () => { const [ isReady ] = useTransient( 'isReady' ); // Persistent accessors. - // TODO: Replace with real property. - const [ sampleValue, setSampleValue ] = usePersistent( 'sampleValue' ); - - const [ cart ] = usePersistent( 'cart' ); - const [ checkout ] = usePersistent( 'checkout' ); - const [ product ] = usePersistent( 'product' ); - const [ shop ] = usePersistent( 'shop' ); - const [ home ] = usePersistent( 'home' ); - const [ custom_placement ] = usePersistent( 'custom_placement' ); + const [ cart, setCart ] = usePersistent( 'cart' ); + const [ checkout, setCheckout ] = usePersistent( 'checkout' ); + const [ product, setProduct ] = usePersistent( 'product' ); + const [ shop, setShop ] = usePersistent( 'shop' ); + const [ home, setHome ] = usePersistent( 'home' ); + const [ custom_placement, setCustom_placement ] = + usePersistent( 'custom_placement' ); return { persist, isReady, - sampleValue, - setSampleValue, cart, + setCart, checkout, + setCheckout, product, + setProduct, shop, + setShop, home, + setHome, custom_placement, + setCustom_placement, }; }; -export const useState = () => { +export const useStore = () => { const { persist, isReady } = useHooks(); return { persist, isReady }; }; -// TODO: Replace with real hook. -export const useSampleValue = () => { - const { sampleValue, setSampleValue } = useHooks(); - - return { - sampleValue, - setSampleValue, - }; -}; - export const usePayLaterMessaging = () => { - const { cart, checkout, product, shop, home, customPlacement } = useHooks(); + const { + cart, + setCart, + checkout, + setCheckout, + product, + setProduct, + shop, + setShop, + home, + setHome, + custom_placement, + setCustom_placement, + } = useHooks(); return { config: { @@ -72,7 +77,13 @@ export const usePayLaterMessaging = () => { product, shop, home, - customPlacement, + custom_placement, }, + setCart, + setCheckout, + setProduct, + setShop, + setHome, + setCustom_placement, }; }; diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js b/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js index 7111d9302..5843ef400 100644 --- a/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js +++ b/modules/ppcp-settings/resources/js/data/pay-later-messaging/reducer.js @@ -19,8 +19,6 @@ const defaultTransient = Object.freeze( { // Persistent: Values that are loaded from the DB. const defaultPersistent = Object.freeze( { - // TODO: Add real DB properties here. - sampleValue: 'foo', cart: {}, checkout: {}, product: {}, diff --git a/modules/ppcp-settings/resources/js/hooks/useSaveSettings.js b/modules/ppcp-settings/resources/js/hooks/useSaveSettings.js index f268d3214..ca594e39d 100644 --- a/modules/ppcp-settings/resources/js/hooks/useSaveSettings.js +++ b/modules/ppcp-settings/resources/js/hooks/useSaveSettings.js @@ -2,6 +2,7 @@ import { useCallback } from '@wordpress/element'; import { CommonHooks, + PayLaterMessagingHooks, PaymentHooks, SettingsHooks, StylingHooks, @@ -13,8 +14,13 @@ export const useSaveSettings = () => { const { persist: persistPayment } = PaymentHooks.useStore(); const { persist: persistSettings } = SettingsHooks.useStore(); const { persist: persistStyling } = StylingHooks.useStore(); + const { persist: persistPayLaterMessaging } = + PayLaterMessagingHooks.useStore(); const persistAll = useCallback( () => { + // Executes onSave on TabPayLaterMessaging component. + document.getElementById( 'configurator-publishButton' )?.click(); + withActivity( 'persist-methods', 'Save payment methods', @@ -30,7 +36,18 @@ export const useSaveSettings = () => { 'Save styling details', persistStyling ); - }, [ persistPayment, persistSettings, persistStyling, withActivity ] ); + withActivity( + 'persist-pay-later-messaging', + 'Save pay later messaging details', + persistPayLaterMessaging + ); + }, [ + persistPayment, + persistSettings, + persistStyling, + persistPayLaterMessaging, + withActivity, + ] ); return { persistAll }; }; diff --git a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php index d448e1a9b..5713ce570 100644 --- a/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/PayLaterMessagingEndpoint.php @@ -103,7 +103,7 @@ class PayLaterMessagingEndpoint extends RestEndpoint { * @return WP_REST_Response The updated Pay Later Messaging configuration details. */ public function update_details( WP_REST_Request $request ) : WP_REST_Response { - $this->save_config->save_config( $request->get_params() ); + $this->save_config->save_config( $request->get_json_params() ); return $this->get_details(); } From 84a30d84d9e8b2534c43332fb395c1275d58f229 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 30 Jan 2025 16:48:06 +0100 Subject: [PATCH 7/9] Remove readme boilerplace example --- .../js/data/pay-later-messaging/README.md | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md diff --git a/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md b/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md deleted file mode 100644 index b97f6ca4c..000000000 --- a/modules/ppcp-settings/resources/js/data/pay-later-messaging/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Store template - -This template contains all files for a Redux store. - -## New Store: Redux integration - -1. Copy this folder, give it a correct name. -2. Check each file for `` placeholders and `TODO` remarks. -3. Edit the main store-index file and add the relevant store integration there. -4. Check the debug-module, and add relevant debug code. - - Register the store in the `reset()` method. - ---- - -Main store-index: -`modules/ppcp-settings/resources/js/data/index.js` - -Sample store integration: -```js -import * as YourStore from './yourStore'; -// ... -YourStore.initStore(); -// ... -export const YourStoreHooks = YourStore.hooks; -// ... -export const YourStoreName = YourStore.STORE_NAME; -// ... -addDebugTools( window.ppcpSettings, [ ..., YourStoreName ] ); -``` - ---- - -### New Store: PHP integration - -1. Create the **REST endpoint** for hydrating and persisting data. - - `modules/ppcp-settings/src/Endpoint/YourStoreRestEndpoint.php` - - Extend from base class `RestEndpoint` -2. Create the **data model** class to manage the DB interaction. - - `modules/ppcp-settings/src/Data/YourStoreSettings.php` - - Extend from base class `AbstractDataModel` -3. Create relevant **DI services** for both files. - - `modules/ppcp-settings/services.php` -4. Register the REST endpoint in the **service module**. - - `modules/ppcp-settings/src/SettingsModule.php` - - Find the action `rest_api_init` From f907558262b18982d48a062e156b2a8683f9490b Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Thu, 30 Jan 2025 16:50:34 +0100 Subject: [PATCH 8/9] Remove console.log --- .../resources/js/paylater-configurator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js index 27145de16..f3daad01e 100644 --- a/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js +++ b/modules/ppcp-paylater-configurator/resources/js/paylater-configurator.js @@ -51,7 +51,6 @@ document.addEventListener( 'DOMContentLoaded', () => { .then( ( data ) => { if ( data.success ) { const config = data.data; - console.log( config ); merchantConfigurators.Messaging( { config, From 2387902a18a9e6bc42834585d01ad941836b661c Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 31 Jan 2025 10:46:16 +0100 Subject: [PATCH 9/9] Change UK to GB --- .../resources/js/utils/countryPriceInfo.js | 126 +++++++++--------- tests/PHPUnit/ApiClient/Entity/PayerTest.php | 10 +- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/modules/ppcp-settings/resources/js/utils/countryPriceInfo.js b/modules/ppcp-settings/resources/js/utils/countryPriceInfo.js index c5cf52a3e..e32d8e6ce 100644 --- a/modules/ppcp-settings/resources/js/utils/countryPriceInfo.js +++ b/modules/ppcp-settings/resources/js/utils/countryPriceInfo.js @@ -2,139 +2,139 @@ export const countryPriceInfo = { US: { fixedFee: { USD: 0.49, - GBP: 0.39, - CAD: 0.59, - AUD: 0.59, - EUR: 0.39, + GBP: 0.39, + CAD: 0.59, + AUD: 0.59, + EUR: 0.39, }, checkout: 3.49, - plater: 4.99, - ccf: { - percentage: 2.59, - fixedFee: 0.29, - }, + plater: 4.99, + ccf: { + percentage: 2.59, + fixedFee: 0.29, + }, dw: { - percentage: 2.59, - fixedFee: 0.29, - }, + percentage: 2.59, + fixedFee: 0.29, + }, apm: { - percentage: 2.89, - fixedFee: 0.29, - }, - fast: { - percentage: 2.59, - fixedFee: 0.29, - }, + percentage: 2.89, + fixedFee: 0.29, + }, + fast: { + percentage: 2.59, + fixedFee: 0.29, + }, standardCardFields: 2.99, }, - UK: { + GB: { fixedFee: { GPB: 0.3, - USD: 0.3, - CAD: 0.3, - AUD: 0.3, - EUR: 0.35, + USD: 0.3, + CAD: 0.3, + AUD: 0.3, + EUR: 0.35, }, checkout: 2.9, - plater: 2.9, + plater: 2.9, ccf: 1.2, dw: 1.2, - fast: 1.2, + fast: 1.2, apm: 1.2, standardCardFields: 1.2, }, CA: { fixedFee: { CAD: 0.3, - USD: 0.3, - GBP: 0.2, - AUD: 0.3, - EUR: 0.35, + USD: 0.3, + GBP: 0.2, + AUD: 0.3, + EUR: 0.35, }, checkout: 2.9, ccf: 2.7, dw: 2.7, - fast: 2.7, + fast: 2.7, apm: 2.9, standardCardFields: 2.9, }, AU: { fixedFee: { AUD: 0.3, - USD: 0.3, - GBP: 0.2, - CAD: 0.3, - EUR: 0.35, + USD: 0.3, + GBP: 0.2, + CAD: 0.3, + EUR: 0.35, }, checkout: 2.6, - plater: 2.6, + plater: 2.6, ccf: 1.75, dw: 1.75, - fast: 1.75, + fast: 1.75, apm: 2.6, standardCardFields: 2.6, }, FR: { fixedFee: { EUR: 0.35, - USD: 0.3, - GBP: 0.3, - CAD: 0.3, - AUD: 0.3, + USD: 0.3, + GBP: 0.3, + CAD: 0.3, + AUD: 0.3, }, checkout: 2.9, - plater: 2.9, + plater: 2.9, ccf: 1.2, dw: 1.2, - fast: 1.2, + fast: 1.2, apm: 1.2, standardCardFields: 1.2, }, IT: { fixedFee: { - EUR: 0.35, - USD: 0.3, - GBP: 0.3, - CAD: 0.3, - AUD: 0.3, + EUR: 0.35, + USD: 0.3, + GBP: 0.3, + CAD: 0.3, + AUD: 0.3, }, checkout: 3.4, - plater: 3.4, + plater: 3.4, ccf: 1.2, dw: 1.2, - fast: 1.2, + fast: 1.2, apm: 1.2, standardCardFields: 1.2, }, DE: { fixedFee: { EUR: 0.39, - USD: 0.49, - GBP: 0.29, - CAD: 0.59, - AUD: 0.59, + USD: 0.49, + GBP: 0.29, + CAD: 0.59, + AUD: 0.59, }, checkout: 2.99, - plater: 2.99, + plater: 2.99, ccf: 2.99, dw: 2.99, - fast: 2.99, + fast: 2.99, apm: 2.99, standardCardFields: 2.99, }, ES: { fixedFee: { - EUR: 0.35, - USD: 0.3, - GBP: 0.3, - CAD: 0.3, - AUD: 0.3, + EUR: 0.35, + USD: 0.3, + GBP: 0.3, + CAD: 0.3, + AUD: 0.3, }, checkout: 2.9, - plater: 2.9, + plater: 2.9, ccf: 1.2, dw: 1.2, - fast: 1.2, + fast: 1.2, apm: 1.2, standardCardFields: 1.2, }, diff --git a/tests/PHPUnit/ApiClient/Entity/PayerTest.php b/tests/PHPUnit/ApiClient/Entity/PayerTest.php index affdc206d..9efc603d5 100644 --- a/tests/PHPUnit/ApiClient/Entity/PayerTest.php +++ b/tests/PHPUnit/ApiClient/Entity/PayerTest.php @@ -18,7 +18,7 @@ class PayerTest extends TestCase ->andReturn(['address']); $address ->expects('country_code') - ->andReturn('UK'); + ->andReturn('GB'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') @@ -70,7 +70,7 @@ class PayerTest extends TestCase ->andReturn(['address']); $address ->expects('country_code') - ->andReturn('UK'); + ->andReturn('GB'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') @@ -110,7 +110,7 @@ class PayerTest extends TestCase ->andReturn(['address']); $address ->expects('country_code') - ->andReturn('UK'); + ->andReturn('GB'); $phone = null; $taxInfo = Mockery::mock(PayerTaxInfo::class); $taxInfo @@ -147,7 +147,7 @@ class PayerTest extends TestCase ->andReturn(['address']); $address ->expects('country_code') - ->andReturn('UK'); + ->andReturn('GB'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array') @@ -184,7 +184,7 @@ class PayerTest extends TestCase ->andReturn(['address']); $address ->expects('country_code') - ->andReturn('UK'); + ->andReturn('GB'); $phone = Mockery::mock(PhoneWithType::class); $phone ->expects('to_array')