Skip to content

Commit 624872e

Browse files
committed
fix: fix redirect mode for payment methods and description field visibility
- Fix Credit Card settings filter name from 'wc_monei_settings' to 'wc_monei_cc_settings' - Fix JavaScript selector for Credit Card description field (gateway ID is 'monei' not 'monei_cc') - Fix redirect_flow logic across all gateways (parentheses placement in empty() checks) - Fix hide_logo, hide_title, enabled, and tokenization logic (same parentheses bug) - Add redirectFlow flag support to PayPal and Bizum Blocks checkout - Pass description field to Blocks for redirect mode display - Standardize description display in redirect mode across all payment methods - Remove description field from Apple/Google Pay (doesn't support redirect mode) The redirect mode was never working due to incorrect boolean expression: Before: ! empty( $option && 'yes' === $option ) After: ! empty( $option ) && 'yes' === $option
1 parent b2159c4 commit 624872e

14 files changed

+125
-46
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export const MoneiCCContent = ( props ) => {
4242
// If hosted workflow, show redirect message
4343
if ( isHostedWorkflow ) {
4444
return (
45-
<div className="wc-block-components-text-input wc-block-components-address-form__email">
46-
<p>{ moneiData.redirected }</p>
45+
<div className="monei-redirect-description">
46+
{ moneiData.description }
4747
</div>
4848
);
4949
}

assets/js/monei-block-checkout-bizum.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
const { onPaymentSetup, onCheckoutSuccess } = props.eventRegistration;
1111
const { activePaymentMethod } = props;
1212

13+
// Check if redirect flow is enabled
14+
const isRedirectFlow = bizumData.redirectFlow === true;
15+
1316
// Use useRef to persist values across re-renders
1417
const requestTokenRef = useRef( null );
1518
const currentBizumInstanceRef = useRef( null );
@@ -22,6 +25,11 @@
2225
}, [] );
2326

2427
useEffect( () => {
28+
// Don't modify the Place Order button if using redirect flow
29+
if ( isRedirectFlow ) {
30+
return;
31+
}
32+
2533
const placeOrderButton = document.querySelector(
2634
'.wc-block-components-button.wp-element-button.wc-block-components-checkout-place-order-button.wc-block-components-checkout-place-order-button'
2735
);
@@ -43,6 +51,11 @@
4351
}, [ activePaymentMethod ] );
4452

4553
useEffect( () => {
54+
// Don't initialize Bizum component if using redirect flow
55+
if ( isRedirectFlow ) {
56+
return;
57+
}
58+
4659
// We assume the MONEI SDK is already loaded via wp_enqueue_script on the backend.
4760
if (
4861
typeof monei !== 'undefined' &&
@@ -57,6 +70,11 @@
5770
}, [] ); // Only initialize once on mount
5871

5972
useEffect( () => {
73+
// Don't update amount if using redirect flow
74+
if ( isRedirectFlow ) {
75+
return;
76+
}
77+
6078
// Only update amount if instance exists and cart totals changed
6179
if (
6280
isInitializedRef.current &&
@@ -185,6 +203,18 @@
185203
// Hook into the payment setup
186204
useEffect( () => {
187205
const unsubscribePaymentSetup = onPaymentSetup( () => {
206+
// In redirect mode, no token is needed - form submits normally
207+
if ( isRedirectFlow ) {
208+
return {
209+
type: responseTypes.SUCCESS,
210+
meta: {
211+
paymentMethodData: {
212+
monei_is_block_checkout: 'yes',
213+
},
214+
},
215+
};
216+
}
217+
188218
// If no token was created, fail
189219
if ( ! requestTokenRef.current ) {
190220
return {
@@ -276,6 +306,15 @@
276306
};
277307
}, [] );
278308

309+
// In redirect mode, show description instead of Bizum button
310+
if ( isRedirectFlow ) {
311+
return (
312+
<div className="monei-redirect-description">
313+
{ bizumData.description }
314+
</div>
315+
);
316+
}
317+
279318
return (
280319
<fieldset className="monei-fieldset monei-payment-request-fieldset">
281320
<div

assets/js/monei-block-checkout-paypal.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
let requestToken = null;
1313
let paypalInstance = null;
1414
let paypalContainer = null;
15+
16+
// Check if redirect flow is enabled
17+
const isRedirectFlow = paypalData.redirectFlow === true;
18+
1519
useEffect( () => {
20+
// Don't modify the Place Order button if using redirect flow
21+
if ( isRedirectFlow ) {
22+
return;
23+
}
24+
1625
const placeOrderButton = document.querySelector(
1726
'.wc-block-components-checkout-place-order-button'
1827
);
@@ -38,6 +47,11 @@
3847
};
3948
}, [ activePaymentMethod ] );
4049
useEffect( () => {
50+
// Don't initialize PayPal component if using redirect flow
51+
if ( isRedirectFlow ) {
52+
return;
53+
}
54+
4155
// We assume the MONEI SDK is already loaded via wp_enqueue_script on the backend.
4256
if ( typeof monei !== 'undefined' && monei.PayPal ) {
4357
if ( counter === 0 ) {
@@ -89,6 +103,18 @@
89103
// Hook into the payment setup
90104
useEffect( () => {
91105
const unsubscribePaymentSetup = onPaymentSetup( () => {
106+
// In redirect mode, no token is needed - form submits normally
107+
if ( isRedirectFlow ) {
108+
return {
109+
type: responseTypes.SUCCESS,
110+
meta: {
111+
paymentMethodData: {
112+
monei_is_block_checkout: 'yes',
113+
},
114+
},
115+
};
116+
}
117+
92118
// If no token was created, fail
93119
if ( ! requestToken ) {
94120
return {
@@ -161,6 +187,15 @@
161187
unsubscribeSuccess();
162188
};
163189
}, [ onCheckoutSuccess ] );
190+
// In redirect mode, show description instead of PayPal button
191+
if ( isRedirectFlow ) {
192+
return (
193+
<div className="monei-redirect-description">
194+
{ paypalData.description }
195+
</div>
196+
);
197+
}
198+
164199
return (
165200
<fieldset className="monei-fieldset monei-payment-request-fieldset">
166201
<div

assets/js/monei-settings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ jQuery( document ).ready( function ( $ ) {
1313

1414
// Generic function to toggle description fields based on redirect mode
1515
function toggleDescriptionField( paymentMethod ) {
16-
const redirectCheckbox = $( '#woocommerce_monei_' + paymentMethod + '_' + paymentMethod + '_mode' );
16+
// Credit Card gateway ID is 'monei', not 'monei_cc', so handle it specially
17+
const gatewayId = paymentMethod === 'cc' ? 'monei' : 'monei_' + paymentMethod;
18+
const redirectCheckbox = $( '#woocommerce_' + gatewayId + '_' + paymentMethod + '_mode' );
1719
const descriptionField = $( '.monei-' + paymentMethod + '-description-field' );
1820

1921
if ( redirectCheckbox.length ) {
@@ -42,7 +44,8 @@ jQuery( document ).ready( function ( $ ) {
4244
// Bind the function to the change event of the selectors
4345
$( '#monei_apikey_mode' ).change( toggleApiKeyFields );
4446
paymentMethods.forEach( function( method ) {
45-
$( '#woocommerce_monei_' + method + '_' + method + '_mode' ).change( function() {
47+
const gatewayId = method === 'cc' ? 'monei' : 'monei_' + method;
48+
$( '#woocommerce_' + gatewayId + '_' + method + '_mode' ).change( function() {
4649
toggleDescriptionField( method );
4750
} );
4851
} );

includes/admin/monei-apple-google-settings.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
'label' => __( 'Enable Apple Pay and Google Pay by MONEI', 'monei' ),
3232
'default' => 'no',
3333
),
34-
'description' => array(
35-
'title' => __( 'Description', 'monei' ),
36-
'type' => 'textarea',
37-
'description' => __( 'Payment method description shown to customers during checkout.', 'monei' ),
38-
'default' => __( 'You will be redirected to Apple Pay or Google Pay to complete the payment. Powered by MONEI.', 'monei' ),
39-
'desc_tip' => true,
40-
),
4134
'payment_request_style' => array(
4235
'title' => __( 'Apple Pay / Google Pay Style', 'monei' ),
4336
'type' => 'textarea',

includes/admin/monei-cc-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/** Monei Gateway Settings. */
1919
return apply_filters(
20-
'wc_monei_settings',
20+
'wc_monei_cc_settings',
2121
array(
2222
'top_link' => array(
2323
'title' => '',

src/Gateways/Blocks/MoneiBizumBlocksSupport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public function get_payment_method_data() {
6868
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
6969
$cart_has_subscription = $this->handler ? $this->handler->cart_has_subscription() : false;
7070
$bizum_style = $this->get_setting( 'bizum_style' );
71+
$bizum_mode = $this->get_setting( 'bizum_mode' );
72+
$redirect_flow = ( ! empty( $bizum_mode ) && 'yes' === $bizum_mode );
73+
7174
if ( ! $bizum_style ) {
7275
$bizum_style = '{}';
7376
}
@@ -87,6 +90,8 @@ public function get_payment_method_data() {
8790
'sessionId' => wc()->session !== null ? wc()->session->get_customer_id() : '',
8891
'cart_has_subscription' => $cart_has_subscription,
8992
'bizumStyle' => json_decode( $bizum_style ),
93+
'redirectFlow' => $redirect_flow,
94+
'description' => $this->get_setting( 'description' ),
9095
);
9196

9297
$hide_logo = $this->get_setting( 'hide_logo' );

src/Gateways/Blocks/MoneiPaypalBlocksSupport.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,31 @@ public function is_active() {
6060
}
6161

6262
public function get_payment_method_data() {
63-
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
64-
$paypal_style = $this->get_setting( 'paypal_style' );
63+
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
64+
$paypal_style = $this->get_setting( 'paypal_style' );
65+
$paypal_mode = $this->get_setting( 'paypal_mode' );
66+
$redirect_flow = ( ! empty( $paypal_mode ) && 'yes' === $paypal_mode );
67+
6568
if ( ! $paypal_style ) {
6669
$paypal_style = '{}';
6770
}
6871
$data = array(
6972

70-
'title' => $this->gateway->title,
71-
'logo' => WC_Monei()->plugin_url() . '/public/images/paypal-logo.svg',
72-
'supports' => $this->get_supported_features(),
73-
'currency' => get_woocommerce_currency(),
74-
'total' => $total,
75-
'language' => locale_iso_639_1_code(),
73+
'title' => $this->gateway->title,
74+
'logo' => WC_Monei()->plugin_url() . '/public/images/paypal-logo.svg',
75+
'supports' => $this->get_supported_features(),
76+
'currency' => get_woocommerce_currency(),
77+
'total' => $total,
78+
'language' => locale_iso_639_1_code(),
7679

7780
// yes: test mode.
7881
// no: live,
79-
'test_mode' => $this->gateway->getTestmode() ?? false,
80-
'accountId' => $this->gateway->getAccountId() ?? false,
81-
'sessionId' => wc()->session !== null ? wc()->session->get_customer_id() : '',
82-
'paypalStyle' => json_decode( $paypal_style ),
82+
'test_mode' => $this->gateway->getTestmode() ?? false,
83+
'accountId' => $this->gateway->getAccountId() ?? false,
84+
'sessionId' => wc()->session !== null ? wc()->session->get_customer_id() : '',
85+
'paypalStyle' => json_decode( $paypal_style ),
86+
'redirectFlow' => $redirect_flow,
87+
'description' => $this->get_setting( 'description' ),
8388
);
8489

8590
$hide_logo = $this->get_setting( 'hide_logo' );

src/Gateways/PaymentMethods/WCGatewayMoneiAppleGoogle.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ public function __construct(
6161
$this->id = 'monei_apple_google';
6262
$this->method_title = __( 'MONEI - Apple Pay / Google Pay', 'monei' );
6363
$this->method_description = __( 'Accept Apple Pay and Google Pay payments.', 'monei' );
64-
$hide_title = ( ! empty( $this->get_option( 'hide_title' ) && 'yes' === $this->get_option( 'hide_title' ) ) ) ? true : false;
64+
$hide_title = ( ! empty( $this->get_option( 'hide_title' ) ) && 'yes' === $this->get_option( 'hide_title' ) ) ? true : false;
6565
$default_title = __( 'Apple Pay / Google Pay', 'monei' );
6666
$saved_title = $this->get_option( 'title' );
6767
$this->title = $hide_title ? '' : ( ! empty( $saved_title ) ? $saved_title : $default_title );
68-
$this->description = ( ! empty( $this->get_option( 'description' ) ) ) ? $this->get_option( 'description' ) : '';
69-
$this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false;
68+
$this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) ) && 'yes' === $this->get_option( 'hide_logo' ) ) ? true : false;
7069
$iconUrl = apply_filters( 'woocommerce_monei_icon', WC_Monei()->image_url( 'google-logo.svg' ) );
7170
$iconMarkup = '<img src="' . $iconUrl . '" alt="MONEI" class="monei-icons" />';
7271
$this->testmode = $this->getTestmode();
@@ -75,7 +74,7 @@ public function __construct(
7574
}
7675
$this->icon = ( $this->hide_logo ) ? '' : $iconMarkup;
7776
$this->settings = get_option( 'woocommerce_monei_apple_google_settings', array() );
78-
$this->enabled = ( ! empty( $this->get_option( 'enabled' ) && 'yes' === $this->get_option( 'enabled' ) ) && $this->is_valid_for_use() ) ? 'yes' : false;
77+
$this->enabled = ( ! empty( $this->get_option( 'enabled' ) ) && 'yes' === $this->get_option( 'enabled' ) && $this->is_valid_for_use() ) ? 'yes' : false;
7978
$this->account_id = $this->getAccountId();
8079
$this->api_key = $this->getApiKey();
8180
$this->shop_name = get_bloginfo( 'name' );

src/Gateways/PaymentMethods/WCGatewayMoneiBizum.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
$this->id = MONEI_GATEWAY_ID . '_bizum';
4747
$this->method_title = __( 'MONEI - Bizum', 'monei' );
4848
$this->method_description = __( 'Accept Bizum payments.', 'monei' );
49-
$this->enabled = ( ! empty( $this->get_option( 'enabled' ) && 'yes' === $this->get_option( 'enabled' ) ) && $this->is_valid_for_use() ) ? 'yes' : false;
49+
$this->enabled = ( ! empty( $this->get_option( 'enabled' ) ) && 'yes' === $this->get_option( 'enabled' ) && $this->is_valid_for_use() ) ? 'yes' : false;
5050

5151
// Load the form fields.
5252
$this->init_form_fields();
@@ -58,11 +58,11 @@ public function __construct(
5858
$iconUrl = apply_filters( 'woocommerce_monei_bizum_icon', WC_Monei()->image_url( 'bizum-logo.svg' ) );
5959
$iconMarkup = '<img src="' . $iconUrl . '" alt="MONEI" class="monei-icons" />';
6060
// Settings variable
61-
$this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false;
61+
$this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) ) && 'yes' === $this->get_option( 'hide_logo' ) ) ? true : false;
6262
$this->icon = ( $this->hide_logo ) ? '' : $iconMarkup;
63-
$this->redirect_flow = ( ! empty( $this->get_option( 'bizum_mode' ) && 'yes' === $this->get_option( 'bizum_mode' ) ) ) ? true : false;
63+
$this->redirect_flow = ( ! empty( $this->get_option( 'bizum_mode' ) ) && 'yes' === $this->get_option( 'bizum_mode' ) ) ? true : false;
6464
$this->testmode = $this->getTestmode();
65-
$hide_title = ( ! empty( $this->get_option( 'hide_title' ) && 'yes' === $this->get_option( 'hide_title' ) ) ) ? true : false;
65+
$hide_title = ( ! empty( $this->get_option( 'hide_title' ) ) && 'yes' === $this->get_option( 'hide_title' ) ) ? true : false;
6666
$this->title = ( ! $hide_title && ! empty( $this->get_option( 'title' ) ) ) ? $this->get_option( 'title' ) : '';
6767
if ( $this->testmode && ! empty( $this->title ) ) {
6868
$this->title .= ' (' . __( 'Test Mode', 'monei' ) . ')';

0 commit comments

Comments
 (0)