diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodsBlock.js index 17f610660..1e1e9ee30 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodsBlock.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/PaymentMethodsBlock.js @@ -1,25 +1,25 @@ -import { useState, useCallback } from '@wordpress/element'; import SettingsBlock from './SettingsBlock'; import PaymentMethodItemBlock from './PaymentMethodItemBlock'; +import { usePaymentMethods } from '../../../data/payment/hooks'; const PaymentMethodsBlock = ( { paymentMethods, className = '', onTriggerModal, } ) => { - const [ selectedMethods, setSelectedMethods ] = useState( {} ); - - const handleSelect = useCallback( ( methodId, isSelected ) => { - setSelectedMethods( ( prev ) => ( { - ...prev, - [ methodId ]: isSelected, - } ) ); - }, [] ); + const { setPersistent } = usePaymentMethods(); if ( ! paymentMethods?.length ) { return null; } + const handleSelect = ( paymentMethod, isSelected ) => { + setPersistent( paymentMethod.id, { + ...paymentMethod, + enabled: isSelected, + } ); + }; + return ( - handleSelect( paymentMethod.id, checked ) + handleSelect( paymentMethod, checked ) } onTriggerModal={ () => onTriggerModal?.( paymentMethod.id ) diff --git a/modules/ppcp-settings/resources/js/data/payment/actions.js b/modules/ppcp-settings/resources/js/data/payment/actions.js index 7360424f4..95c0235b1 100644 --- a/modules/ppcp-settings/resources/js/data/payment/actions.js +++ b/modules/ppcp-settings/resources/js/data/payment/actions.js @@ -47,18 +47,6 @@ export const setIsReady = ( isReady ) => ( { payload: { isReady }, } ); -/** - * Persistent. Sets a sample value. - * TODO: Replace with a real action/property. - * - * @param {string} value - * @return {Action} The action. - */ -export const setSampleValue = ( value ) => ( { - type: ACTION_TYPES.SET_PERSISTENT, - payload: { sampleValue: value }, -} ); - /** * Side effect. Triggers the persistence of store data to the server. * @@ -69,3 +57,15 @@ export const persist = function* () { yield { type: ACTION_TYPES.DO_PERSIST_DATA, data }; }; + +/** + * 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 }, +} ); diff --git a/modules/ppcp-settings/resources/js/data/payment/hooks.js b/modules/ppcp-settings/resources/js/data/payment/hooks.js index 54b6d9863..c10f0969e 100644 --- a/modules/ppcp-settings/resources/js/data/payment/hooks.js +++ b/modules/ppcp-settings/resources/js/data/payment/hooks.js @@ -24,12 +24,7 @@ const usePersistent = ( key ) => ); const useHooks = () => { - const { - persist, - - // TODO: Replace with real property. - setSampleValue, - } = useDispatch( STORE_NAME ); + const { persist, setPersistent } = useDispatch( STORE_NAME ); // Read-only flags and derived state. // Nothing here yet. @@ -37,9 +32,6 @@ const useHooks = () => { // Transient accessors. const isReady = useTransient( 'isReady' ); - // Persistent accessors. - const sampleValue = usePersistent( 'sampleValue' ); - // PayPal checkout. const paypal = usePersistent( 'ppcp-gateway' ); const venmo = usePersistent( 'venmo' ); @@ -67,8 +59,7 @@ const useHooks = () => { return { persist, isReady, - sampleValue, - setSampleValue, + setPersistent, paypal, venmo, payLater, @@ -95,13 +86,11 @@ export const useState = () => { return { persist, isReady }; }; -// TODO: Replace with real hook. -export const useSampleValue = () => { - const { sampleValue, setSampleValue } = useHooks(); +export const usePaymentMethods = () => { + const { setPersistent } = useHooks(); return { - sampleValue, - setSampleValue, + setPersistent, }; }; diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 838ebe3d5..e66a919d5 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -66,9 +66,6 @@ return array( $container->get( 'wcgateway.is-send-only-country' ) ); }, - 'settings.data.payment' => static function ( ContainerInterface $container ) : PaymentSettings { - return new PaymentSettings(); - }, 'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint { return new OnboardingRestEndpoint( $container->get( 'settings.data.onboarding' ) ); }, @@ -76,7 +73,7 @@ return array( return new CommonRestEndpoint( $container->get( 'settings.data.general' ) ); }, 'settings.rest.payment' => static function ( ContainerInterface $container ) : PaymentRestEndpoint { - return new PaymentRestEndpoint( $container->get( 'settings.data.payment' ) ); + return new PaymentRestEndpoint(); }, 'settings.rest.refresh_feature_status' => static function ( ContainerInterface $container ) : RefreshFeatureStatusEndpoint { return new RefreshFeatureStatusEndpoint( diff --git a/modules/ppcp-settings/src/Data/PaymentSettings.php b/modules/ppcp-settings/src/Data/PaymentSettings.php deleted file mode 100644 index d603a082f..000000000 --- a/modules/ppcp-settings/src/Data/PaymentSettings.php +++ /dev/null @@ -1,210 +0,0 @@ - array( - array( - 'id' => 'paypal', - 'title' => __( 'PayPal', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-paypal', - ), - array( - 'id' => 'venmo', - 'title' => __( 'Venmo', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Offer Venmo at checkout to millions of active users.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-venmo', - ), - array( - 'id' => 'paypal_credit', - 'title' => __( 'Pay Later', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Get paid in full at checkout while giving your customers the flexibility to pay in installments over time with no late fees.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-paypal', - ), - array( - 'id' => 'credit_and_debit_card_payments', - 'title' => __( - 'Credit and debit card payments', - 'woocommerce-paypal-payments' - ), - 'description' => __( - "Accept all major credit and debit cards - even if your customer doesn't have a PayPal account.", - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-cards', - ), - ), - 'paymentMethodsOnlineCardPayments' => array( - array( - 'id' => 'advanced_credit_and_debit_card_payments', - 'title' => __( - 'Advanced Credit and Debit Card Payments', - 'woocommerce-paypal-payments' - ), - 'description' => __( - "Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.", - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-advanced-cards', - ), - array( - 'id' => 'fastlane', - 'title' => __( 'Fastlane by PayPal', 'woocommerce-paypal-payments' ), - 'description' => __( - "Tap into the scale and trust of PayPal's customer network to recognize shoppers and make guest checkout more seamless than ever.", - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-fastlane', - ), - array( - 'id' => 'apple_pay', - 'title' => __( 'Apple Pay', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Allow customers to pay via their Apple Pay digital wallet.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-apple-pay', - ), - array( - 'id' => 'google_pay', - 'title' => __( 'Google Pay', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Allow customers to pay via their Google Pay digital wallet.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-google-pay', - ), - ), - 'paymentMethodsAlternative' => array( - array( - 'id' => 'bancontact', - 'title' => __( 'Bancontact', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Bancontact is the most widely used, accepted and trusted electronic payment method in Belgium. Bancontact makes it possible to pay directly through the online payment systems of all major Belgian banks.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-bancontact', - ), - array( - 'id' => 'ideal', - 'title' => __( 'iDEAL', 'woocommerce-paypal-payments' ), - 'description' => __( - 'iDEAL is a payment method in the Netherlands that allows buyers to select their issuing bank from a list of options.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-ideal', - ), - array( - 'id' => 'eps', - 'title' => __( 'eps', 'woocommerce-paypal-payments' ), - 'description' => __( - 'An online payment method in Austria, enabling Austrian buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-eps', - ), - array( - 'id' => 'blik', - 'title' => __( 'BLIK', 'woocommerce-paypal-payments' ), - 'description' => __( - 'A widely used mobile payment method in Poland, allowing Polish customers to pay directly via their banking apps. Transactions are processed in PLN.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-blik', - ), - array( - 'id' => 'mybank', - 'title' => __( 'MyBank', 'woocommerce-paypal-payments' ), - 'description' => __( - 'A European online banking payment solution primarily used in Italy, enabling customers to make secure bank transfers during checkout. Transactions are processed in EUR.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-mybank', - ), - array( - 'id' => 'przelewy24', - 'title' => __( 'Przelewy24', 'woocommerce-paypal-payments' ), - 'description' => __( - 'A popular online payment gateway in Poland, offering various payment options for Polish customers. Transactions can be processed in PLN or EUR.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-przelewy24', - ), - array( - 'id' => 'trustly', - 'title' => __( 'Trustly', 'woocommerce-paypal-payments' ), - 'description' => __( - 'A European payment method that allows buyers to make payments directly from their bank accounts, suitable for customers across multiple European countries. Supported currencies include EUR, DKK, SEK, GBP, and NOK.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-trustly', - ), - array( - 'id' => 'multibanco', - 'title' => __( 'Multibanco', 'woocommerce-paypal-payments' ), - 'description' => __( - 'An online payment method in Portugal, enabling Portuguese buyers to make secure payments directly through their bank accounts. Transactions are processed in EUR.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-multibanco', - ), - array( - 'id' => 'pui', - 'title' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ), - 'description' => __( - 'Pay upon Invoice is an invoice payment method in Germany. It is a local buy now, pay later payment method that allows the buyer to place an order, receive the goods, try them, verify they are in good order, and then pay the invoice within 30 days.', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-ratepay', - - ), - array( - 'id' => 'oxxo', - 'title' => __( 'OXXO', 'woocommerce-paypal-payments' ), - 'description' => __( - 'OXXO is a Mexican chain of convenience stores. *Get PayPal account permission to use OXXO payment functionality by contacting us at (+52) 800–925–0304', - 'woocommerce-paypal-payments' - ), - 'icon' => 'payment-method-oxxo', - ), - ), - ); - } -} diff --git a/modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php index ea692242a..7e5ea161e 100644 --- a/modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php @@ -52,7 +52,7 @@ class PaymentRestEndpoint extends RestEndpoint { return array( // PayPal checkout. PayPalGateway::ID => array( - 'id' => 'paypal', + 'id' => 'ppcp-gateway', 'title' => __( 'PayPal', 'woocommerce-paypal-payments' ), 'description' => __( 'Our all-in-one checkout solution lets you offer PayPal, Venmo, Pay Later options, and more to help maximize conversion.',