Skip to content

Commit eaf9107

Browse files
committed
fix: improve payment component re-initialization and code quality
- Fix container recreation detection for all classic payment methods (CC, Bizum, PayPal, Apple/Google Pay) - Compare stored container with current DOM element to detect WooCommerce AJAX rebuilds - Prevents payment buttons from disappearing after shipping/total changes - Fix React hooks missing dependencies in CC block component - Refactor code formatting and style across PHP files (PSR-12 compliance) - Update GitHub Actions workflows to use latest versions - Add .nvmrc for consistent Node.js version management
1 parent 953cdab commit eaf9107

32 files changed

+207
-237
lines changed

.github/workflows/create-package.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout code
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Install Composer dependencies
1717
uses: ramsey/composer-install@v3
1818
with:
1919
composer-options: --no-dev --optimize-autoloader
2020

2121
- name: Setup Node.js
22-
uses: actions/setup-node@v3
22+
uses: actions/setup-node@v4
2323
with:
24-
node-version: '18'
24+
node-version-file: .nvmrc
25+
cache: yarn
2526

2627
- name: Enable Corepack
2728
run: corepack enable

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout code
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212

1313
- name: Install Composer dependencies
1414
uses: ramsey/composer-install@v3
1515
with:
1616
composer-options: --no-dev --optimize-autoloader
1717

1818
- name: Setup Node.js
19-
uses: actions/setup-node@v3
19+
uses: actions/setup-node@v4
2020
with:
21-
node-version: '18'
21+
node-version-file: .nvmrc
22+
cache: yarn
2223

2324
- name: Enable Corepack
2425
run: corepack enable

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

assets/js/components/monei-cc-component.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
useCardholderName,
3-
useMoneiCardInput,
43
useFormErrors,
4+
useMoneiCardInput,
55
} from '../helpers/monei-card-input-hooks';
66

77
const { useEffect, useState, useRef, useCallback, useMemo, createPortal } =
@@ -223,6 +223,7 @@ export const MoneiCCContent = ( props ) => {
223223
createPaymentToken,
224224
responseTypes,
225225
moneiData.tokenErrorString,
226+
shouldSavePayment,
226227
] );
227228

228229
// Setup checkout success hook
@@ -288,7 +289,12 @@ export const MoneiCCContent = ( props ) => {
288289
);
289290

290291
return unsubscribe;
291-
}, [ onCheckoutSuccess, cardholderName.value, shouldSavePayment ] );
292+
}, [
293+
onCheckoutSuccess,
294+
cardholderName.value,
295+
responseTypes,
296+
props.emitResponse.noticeContexts,
297+
] );
292298

293299
return (
294300
<fieldset className="monei-fieldset monei-card-fieldset wc-block-components-form">

assets/js/monei-apple-google-classic.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@
161161

162162
// If checkout is updated (and monei was initiated already), ex, selecting new shipping methods, checkout is re-render by the ajax call.
163163
// and we need to reset the counter in order to initiate again the monei component.
164-
if (
165-
wc_monei_form.$payment_request_container &&
166-
0 === wc_monei_form.$payment_request_container.childElementCount
167-
) {
168-
wc_monei_form.init_apple_counter = 0;
164+
if ( wc_monei_form.$payment_request_container ) {
165+
// Reset if stored container differs from current (recreated) OR current is empty
166+
if (
167+
wc_monei_form.$payment_request_container !== container ||
168+
container.childElementCount === 0
169+
) {
170+
wc_monei_form.init_apple_counter = 0;
171+
}
169172
}
170173

171174
// init monei just once, despite how many times this may be triggered.

assets/js/monei-bizum-classic.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,14 @@
180180

181181
// If checkout is updated (and monei was initiated already), ex, selecting new shipping methods, checkout is re-render by the ajax call.
182182
// and we need to reset the counter in order to initiate again the monei component.
183-
if (
184-
wc_bizum_form.$container &&
185-
0 === wc_bizum_form.$container.childElementCount
186-
) {
187-
wc_bizum_form.init_counter = 0;
183+
if ( wc_bizum_form.$container ) {
184+
// Reset if stored container differs from current (recreated) OR current is empty
185+
if (
186+
wc_bizum_form.$container !== container ||
187+
container.childElementCount === 0
188+
) {
189+
wc_bizum_form.init_counter = 0;
190+
}
188191
}
189192

190193
// init monei just once, despite how many times this may be triggered.

assets/js/monei-cc-classic.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@
150150
}
151151
// If checkout is updated (and monei was initiated already), ex, selecting new shipping methods, checkout is re-render by the ajax call.
152152
// and we need to reset the counter in order to initiate again the monei component.
153-
if (
154-
wc_monei_form.$container &&
155-
0 === wc_monei_form.$container.childElementCount
156-
) {
157-
wc_monei_form.init_counter = 0;
153+
if ( wc_monei_form.$container ) {
154+
// Reset if stored container differs from current (recreated) OR current is empty
155+
if (
156+
wc_monei_form.$container !== container ||
157+
container.childElementCount === 0
158+
) {
159+
wc_monei_form.init_counter = 0;
160+
}
158161
}
159162

160163
// init monei just once, despite how many times this may be triggered.

assets/js/monei-paypal-classic.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@
181181

182182
// If checkout is updated (and monei was initiated already), ex, selecting new shipping methods, checkout is re-render by the ajax call.
183183
// and we need to reset the counter in order to initiate again the monei component.
184-
if (
185-
wc_paypal_form.$container &&
186-
0 === wc_paypal_form.$container.childElementCount
187-
) {
188-
wc_paypal_form.init_counter = 0;
184+
if ( wc_paypal_form.$container ) {
185+
// Reset if stored container differs from current (recreated) OR current is empty
186+
if (
187+
wc_paypal_form.$container !== container ||
188+
container.childElementCount === 0
189+
) {
190+
wc_paypal_form.init_counter = 0;
191+
}
189192
}
190193

191194
// init monei just once, despite how many times this may be triggered.

includes/admin/monei-cc-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
'title' => __( 'Description', 'monei' ),
6666
'type' => 'textarea',
6767
'description' => __( 'This description is only displayed when using redirect mode. It will be shown to customers before they are redirected to the payment page.', 'monei' ),
68-
'default' => __( 'You will be redirected to the payment page to complete the payment. Powered by MONEI.', 'monei' ),
68+
'default' => __( 'You will be redirected to Credit Card to complete the payment. Powered by MONEI.', 'monei' ),
6969
'class' => 'monei-cc-description-field',
7070
),
7171
'card_input_style' => array(

includes/admin/monei-mbway-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'title' => __( 'Description', 'monei' ),
3636
'type' => 'textarea',
3737
'description' => __( 'Payment method description shown to customers during checkout.', 'monei' ),
38-
'default' => __( 'Pay with MBWay, you will be redirected to MBWay to complete the payment. Powered by MONEI.', 'monei' ),
38+
'default' => __( 'You will be redirected to MBWay to complete the payment. Powered by MONEI.', 'monei' ),
3939
'class' => 'monei-mbway-description-field',
4040
),
4141
'title' => array(

0 commit comments

Comments
 (0)