|
30 | 30 | return select( 'wc/store/cart' ).getCartTotals(); |
31 | 31 | }, [] ); |
32 | 32 |
|
33 | | - useEffect( () => { |
34 | | - // Don't modify the Place Order button if using redirect flow |
35 | | - if ( isRedirectFlow ) { |
36 | | - return; |
37 | | - } |
38 | | - |
39 | | - const placeOrderButton = document.querySelector( |
40 | | - '.wc-block-components-button.wp-element-button.wc-block-components-checkout-place-order-button.wc-block-components-checkout-place-order-button' |
41 | | - ); |
42 | | - if ( activePaymentMethod === 'monei_bizum' ) { |
43 | | - if ( placeOrderButton ) { |
44 | | - //on hover over the button the text should not change color to white |
45 | | - placeOrderButton.style.color = 'black'; |
46 | | - placeOrderButton.style.backgroundColor = '#ccc'; |
47 | | - placeOrderButton.disabled = true; |
48 | | - } |
49 | | - } |
50 | | - return () => { |
51 | | - if ( placeOrderButton ) { |
52 | | - placeOrderButton.style.color = ''; |
53 | | - placeOrderButton.style.backgroundColor = ''; |
54 | | - placeOrderButton.disabled = false; |
55 | | - } |
56 | | - }; |
57 | | - }, [ activePaymentMethod, isRedirectFlow ] ); |
58 | | - |
59 | | - useEffect( () => { |
60 | | - // Don't initialize Bizum component if using redirect flow |
61 | | - if ( isRedirectFlow ) { |
62 | | - return; |
63 | | - } |
64 | | - |
65 | | - // We assume the MONEI SDK is already loaded via wp_enqueue_script on the backend. |
66 | | - if ( |
67 | | - typeof monei !== 'undefined' && |
68 | | - monei.Bizum && |
69 | | - ! isInitializedRef.current |
70 | | - ) { |
71 | | - initMoneiCard(); |
72 | | - isInitializedRef.current = true; |
73 | | - } else if ( ! monei || ! monei.Bizum ) { |
74 | | - console.error( 'MONEI SDK is not available' ); |
75 | | - } |
76 | | - }, [ initMoneiCard, isRedirectFlow ] ); |
77 | | - |
78 | | - useEffect( () => { |
79 | | - // Don't update amount if using redirect flow |
80 | | - if ( isRedirectFlow ) { |
81 | | - return; |
82 | | - } |
83 | | - |
84 | | - // Only update amount if instance exists and cart totals changed |
85 | | - if ( |
86 | | - isInitializedRef.current && |
87 | | - currentBizumInstanceRef.current && |
88 | | - cartTotals |
89 | | - ) { |
90 | | - updateBizumAmount(); |
91 | | - } |
92 | | - }, [ cartTotals, updateBizumAmount, isRedirectFlow ] ); |
93 | | - |
94 | 33 | /** |
95 | 34 | * Initialize MONEI Bizum instance once. |
96 | 35 | */ |
97 | | - const initMoneiCard = useCallback( () => { |
| 36 | + const initMoneiBizum = useCallback( () => { |
98 | 37 | const currentTotal = cartTotals?.total_price |
99 | 38 | ? parseInt( cartTotals.total_price ) |
100 | 39 | : parseInt( bizumData.total * 100 ); |
|
237 | 176 | } |
238 | 177 | }, [ cartTotals ] ); |
239 | 178 |
|
| 179 | + useEffect( () => { |
| 180 | + // Don't modify the Place Order button if using redirect flow |
| 181 | + if ( isRedirectFlow ) { |
| 182 | + return; |
| 183 | + } |
| 184 | + |
| 185 | + const placeOrderButton = document.querySelector( |
| 186 | + '.wc-block-components-button.wp-element-button.wc-block-components-checkout-place-order-button.wc-block-components-checkout-place-order-button' |
| 187 | + ); |
| 188 | + if ( activePaymentMethod === 'monei_bizum' ) { |
| 189 | + if ( placeOrderButton ) { |
| 190 | + //on hover over the button the text should not change color to white |
| 191 | + placeOrderButton.style.color = 'black'; |
| 192 | + placeOrderButton.style.backgroundColor = '#ccc'; |
| 193 | + placeOrderButton.disabled = true; |
| 194 | + } |
| 195 | + } |
| 196 | + return () => { |
| 197 | + if ( placeOrderButton ) { |
| 198 | + placeOrderButton.style.color = ''; |
| 199 | + placeOrderButton.style.backgroundColor = ''; |
| 200 | + placeOrderButton.disabled = false; |
| 201 | + } |
| 202 | + }; |
| 203 | + }, [ activePaymentMethod, isRedirectFlow ] ); |
| 204 | + |
| 205 | + useEffect( () => { |
| 206 | + // Don't initialize Bizum component if using redirect flow |
| 207 | + if ( isRedirectFlow ) { |
| 208 | + return; |
| 209 | + } |
| 210 | + |
| 211 | + // We assume the MONEI SDK is already loaded via wp_enqueue_script on the backend. |
| 212 | + if ( |
| 213 | + typeof monei !== 'undefined' && |
| 214 | + monei.Bizum && |
| 215 | + ! isInitializedRef.current |
| 216 | + ) { |
| 217 | + initMoneiBizum(); |
| 218 | + isInitializedRef.current = true; |
| 219 | + } else if ( ! monei || ! monei.Bizum ) { |
| 220 | + console.error( 'MONEI SDK is not available' ); |
| 221 | + } |
| 222 | + }, [ initMoneiBizum, isRedirectFlow ] ); |
| 223 | + |
| 224 | + useEffect( () => { |
| 225 | + // Don't update amount if using redirect flow |
| 226 | + if ( isRedirectFlow ) { |
| 227 | + return; |
| 228 | + } |
| 229 | + |
| 230 | + // Only update amount if instance exists and cart totals changed |
| 231 | + if ( |
| 232 | + isInitializedRef.current && |
| 233 | + currentBizumInstanceRef.current && |
| 234 | + cartTotals |
| 235 | + ) { |
| 236 | + updateBizumAmount(); |
| 237 | + } |
| 238 | + }, [ cartTotals, updateBizumAmount, isRedirectFlow ] ); |
| 239 | + |
240 | 240 | // Hook into the payment setup |
241 | 241 | useEffect( () => { |
242 | 242 | const unsubscribePaymentSetup = onPaymentSetup( () => { |
|
0 commit comments