From b2b0bb8d7af0bd1a7f9ba6c7acd63239b02cb220 Mon Sep 17 00:00:00 2001
From: Philipp Stracker
Date: Fri, 14 Feb 2025 17:49:35 +0100
Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Convert=20payment-store=20?=
=?UTF-8?q?hooks=20to=20new=20code=20pattern?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../resources/js/data/payment/hooks.js | 109 ++++--------------
1 file changed, 25 insertions(+), 84 deletions(-)
diff --git a/modules/ppcp-settings/resources/js/data/payment/hooks.js b/modules/ppcp-settings/resources/js/data/payment/hooks.js
index 5a330f1b2..582fd86f6 100644
--- a/modules/ppcp-settings/resources/js/data/payment/hooks.js
+++ b/modules/ppcp-settings/resources/js/data/payment/hooks.js
@@ -37,7 +37,21 @@ const useStoreData = () => {
);
};
-const useHooks = () => {
+export const useStore = () => {
+ const { useTransient, dispatch } = useStoreData();
+ const { persist, refresh, setPersistent, changePaymentSettings } = dispatch;
+ const [ isReady ] = useTransient( 'isReady' );
+
+ return {
+ persist,
+ refresh,
+ setPersistent,
+ changePaymentSettings,
+ isReady,
+ };
+};
+
+export const usePaymentMethods = () => {
const { usePersistent } = useStoreData();
// PayPal checkout.
@@ -64,83 +78,6 @@ const useHooks = () => {
const [ pui ] = usePersistent( 'ppcp-pay-upon-invoice-gateway' );
const [ oxxo ] = usePersistent( 'ppcp-oxxo-gateway' );
- // Custom modal data.
- const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
- const [ threeDSecure ] = usePersistent( 'threeDSecure' );
- const [ fastlaneCardholderName ] = usePersistent(
- 'fastlaneCardholderName'
- );
- const [ fastlaneDisplayWatermark ] = usePersistent(
- 'fastlaneDisplayWatermark'
- );
-
- return {
- paypal,
- venmo,
- payLater,
- creditCard,
- advancedCreditCard,
- fastlane,
- applePay,
- googlePay,
- bancontact,
- blik,
- eps,
- ideal,
- mybank,
- p24,
- trustly,
- multibanco,
- pui,
- oxxo,
- paypalShowLogo,
- threeDSecure,
- fastlaneCardholderName,
- fastlaneDisplayWatermark,
- };
-};
-
-export const useStore = () => {
- const { useTransient, dispatch } = useStoreData();
- const { persist, refresh, setPersistent, changePaymentSettings } = dispatch;
- const [ isReady ] = useTransient( 'isReady' );
-
- return {
- persist,
- refresh,
- setPersistent,
- changePaymentSettings,
- isReady,
- };
-};
-
-export const usePaymentMethods = () => {
- const {
- // PayPal Checkout.
- paypal,
- venmo,
- payLater,
- creditCard,
-
- // Online card payments.
- advancedCreditCard,
- fastlane,
- applePay,
- googlePay,
-
- // Local APMs.
- bancontact,
- blik,
- eps,
- ideal,
- mybank,
- p24,
- trustly,
- multibanco,
- pui,
- oxxo,
- } = useHooks();
-
const payPalCheckout = [ paypal, venmo, payLater, creditCard ];
const onlineCardPayments = [
advancedCreditCard,
@@ -190,12 +127,16 @@ export const usePaymentMethods = () => {
};
export const usePaymentMethodsModal = () => {
- const {
- paypalShowLogo,
- threeDSecure,
- fastlaneCardholderName,
- fastlaneDisplayWatermark,
- } = useHooks();
+ const { usePersistent } = useStoreData();
+
+ const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
+ const [ threeDSecure ] = usePersistent( 'threeDSecure' );
+ const [ fastlaneCardholderName ] = usePersistent(
+ 'fastlaneCardholderName'
+ );
+ const [ fastlaneDisplayWatermark ] = usePersistent(
+ 'fastlaneDisplayWatermark'
+ );
return {
paypalShowLogo,