woocommerce-paypal-payments/modules/ppcp-settings/resources/js/data/payment/hooks.js

186 lines
3.8 KiB
JavaScript
Raw Normal View History

/**
* 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 { STORE_NAME } from './constants';
import { createHooksForStore } from '../utils';
const useHooks = () => {
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
const { persist, setPersistent, changePaymentSettings } =
useDispatch( STORE_NAME );
// Read-only flags and derived state.
// Nothing here yet.
// Transient accessors.
const [ isReady ] = useTransient( 'isReady' );
2025-01-16 15:48:40 +01:00
// PayPal checkout.
const [ paypal ] = usePersistent( 'ppcp-gateway' );
const [ venmo ] = usePersistent( 'venmo' );
const [ payLater ] = usePersistent( 'pay-later' );
const [ creditCard ] = usePersistent( 'ppcp-card-button-gateway' );
2025-01-16 15:48:40 +01:00
// Online card Payments.
const [ advancedCreditCard ] = usePersistent( 'ppcp-credit-card-gateway' );
const [ fastlane ] = usePersistent( 'ppcp-axo-gateway' );
const [ applePay ] = usePersistent( 'ppcp-applepay' );
const [ googlePay ] = usePersistent( 'ppcp-googlepay' );
2025-01-16 15:48:40 +01:00
// Alternative payment methods.
const [ bancontact ] = usePersistent( 'ppcp-bancontact' );
const [ blik ] = usePersistent( 'ppcp-blik' );
const [ eps ] = usePersistent( 'ppcp-eps' );
const [ ideal ] = usePersistent( 'ppcp-ideal' );
const [ mybank ] = usePersistent( 'ppcp-mybank' );
const [ p24 ] = usePersistent( 'ppcp-p24' );
const [ trustly ] = usePersistent( 'ppcp-trustly' );
const [ multibanco ] = usePersistent( 'ppcp-multibanco' );
const [ pui ] = usePersistent( 'ppcp-pay-upon-invoice-gateway' );
const [ oxxo ] = usePersistent( 'ppcp-oxxo-gateway' );
2025-01-23 10:54:10 +01:00
// Custom modal data.
const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
const [ threeDSecure ] = usePersistent( 'threeDSecure' );
const [ fastlaneCardholderName ] = usePersistent(
'fastlaneCardholderName'
);
const [ fastlaneDisplayWatermark ] = usePersistent(
2025-01-23 10:54:10 +01:00
'fastlaneDisplayWatermark'
);
return {
persist,
isReady,
setPersistent,
changePaymentSettings,
paypal,
2025-01-16 15:48:40 +01:00
venmo,
payLater,
creditCard,
advancedCreditCard,
2025-01-16 15:48:40 +01:00
fastlane,
applePay,
googlePay,
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
2025-01-23 10:54:10 +01:00
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
};
};
2025-01-21 13:15:05 +01:00
export const useStore = () => {
const { persist, isReady, setPersistent, changePaymentSettings } =
useHooks();
return { persist, isReady, setPersistent, changePaymentSettings };
};
export const usePaymentMethods = () => {
2025-01-22 12:09:21 +01:00
const {
// PayPal Checkout.
2025-01-22 12:09:21 +01:00
paypal,
venmo,
payLater,
creditCard,
// Online card payments.
2025-01-22 12:09:21 +01:00
advancedCreditCard,
fastlane,
applePay,
googlePay,
// Local APMs.
2025-01-22 12:09:21 +01:00
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
} = useHooks();
const payPalCheckout = [ paypal, venmo, payLater, creditCard ];
const onlineCardPayments = [
advancedCreditCard,
fastlane,
applePay,
googlePay,
];
const alternative = [
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
];
2025-01-22 12:09:21 +01:00
const paymentMethods = [
paypal,
venmo,
payLater,
creditCard,
advancedCreditCard,
fastlane,
applePay,
googlePay,
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
2025-01-23 12:29:41 +01:00
];
return {
all: paymentMethods,
paypal: payPalCheckout,
cardPayment: onlineCardPayments,
apm: alternative,
};
2025-01-23 12:29:41 +01:00
};
export const usePaymentMethodsModal = () => {
const {
2025-01-23 10:54:10 +01:00
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
2025-01-23 12:29:41 +01:00
} = useHooks();
return {
2025-01-23 12:29:41 +01:00
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
};
};