Skip to content

Commit f9a1625

Browse files
committed
fix: ensure consistent fieldset layout across all payment methods
- Add monei-payment-request-container class to PayPal Blocks container div to match Bizum structure - Remove description from PayPal and Bizum Blocks data since they don't support redirect mode in WooCommerce Blocks - Add missing paypalStyle and bizumStyle configuration to Blocks support classes for proper component styling - Fix PHPStan errors for cart and session null checks
1 parent 074b5c0 commit f9a1625

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
( function () {
22
const { registerPaymentMethod } = wc.wcBlocksRegistry;
33
const { __ } = wp.i18n;
4-
const { useEffect} = wp.element;
4+
const { useEffect } = wp.element;
55
const paypalData = wc.wcSettings.getSetting( 'monei_paypal_data' );
66

77
const MoneiPayPalContent = ( props ) => {
@@ -28,20 +28,19 @@
2828
if ( paypalInstance ) {
2929
paypalInstance.close();
3030
paypalInstance = null;
31-
paypalContainer.innerHtml = ''
31+
paypalContainer.innerHtml = '';
3232
}
3333
if ( placeOrderButton ) {
3434
placeOrderButton.style.color = '';
3535
placeOrderButton.style.backgroundColor = '';
3636
placeOrderButton.disabled = false;
3737
}
38-
3938
};
4039
}, [ activePaymentMethod ] );
4140
useEffect( () => {
4241
// We assume the MONEI SDK is already loaded via wp_enqueue_script on the backend.
4342
if ( typeof monei !== 'undefined' && monei.PayPal ) {
44-
if(counter === 0) {
43+
if ( counter === 0 ) {
4544
initMoneiCard();
4645
}
4746
} else {
@@ -61,6 +60,7 @@
6160
language: paypalData.language,
6261
amount: parseInt( paypalData.total * 100 ),
6362
currency: paypalData.currency,
63+
style: paypalData.paypalStyle || {},
6464
onSubmit( result ) {
6565
if ( result.token ) {
6666
requestToken = result.token;
@@ -83,7 +83,7 @@
8383
} );
8484
paypalInstance.render( paypalContainer );
8585

86-
counter += 1
86+
counter += 1;
8787
};
8888

8989
// Hook into the payment setup
@@ -121,9 +121,11 @@
121121
if ( paymentDetails && paymentDetails.paymentId ) {
122122
const paymentId = paymentDetails.paymentId;
123123
const tokenValue = paymentDetails.token;
124-
monei.confirmPayment( {
125-
paymentId,
126-
paymentToken: tokenValue} )
124+
monei
125+
.confirmPayment( {
126+
paymentId,
127+
paymentToken: tokenValue,
128+
} )
127129
.then( ( result ) => {
128130
if (
129131
result.nextAction &&
@@ -161,7 +163,11 @@
161163
}, [ onCheckoutSuccess ] );
162164
return (
163165
<fieldset className="monei-fieldset monei-payment-request-fieldset">
164-
<div id="paypal-container">
166+
<div
167+
id="paypal-container"
168+
className="monei-payment-request-container"
169+
>
170+
{ /* PayPal button will be inserted here */ }
165171
</div>
166172
</fieldset>
167173
);
@@ -187,7 +193,7 @@
187193
ariaLabel: __( paypalData.title, 'monei' ),
188194
content: <MoneiPayPalContent />,
189195
edit: <div> { __( paypalData.title, 'monei' ) }</div>,
190-
canMakePayment: ( ) => true,
196+
canMakePayment: () => true,
191197
supports: paypalData.supports,
192198
};
193199

src/Gateways/Blocks/MoneiBizumBlocksSupport.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ public function is_active() {
6565
}
6666

6767
public function get_payment_method_data() {
68-
$total = isset( WC()->cart ) ? WC()->cart->get_total( false ) : 0;
68+
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
6969
$cart_has_subscription = $this->handler ? $this->handler->cart_has_subscription() : false;
70-
$data = array(
70+
$bizum_style = $this->get_setting( 'bizum_style' );
71+
if ( ! $bizum_style ) {
72+
$bizum_style = '{}';
73+
}
74+
$data = array(
7175

7276
'title' => $this->gateway->title,
73-
'description' => $this->gateway->description,
7477
'logo' => WC_Monei()->plugin_url() . '/public/images/bizum-logo.svg',
7578
'supports' => $this->get_supported_features(),
7679
'currency' => get_woocommerce_currency(),
@@ -81,14 +84,14 @@ public function get_payment_method_data() {
8184
// no: live,
8285
'test_mode' => $this->gateway->getTestmode() ?? false,
8386
'accountId' => $this->gateway->getAccountId() ?? false,
84-
'sessionId' => ( wc()->session ) ? wc()->session->get_customer_id() : '',
87+
'sessionId' => wc()->session !== null ? wc()->session->get_customer_id() : '',
8588
'cart_has_subscription' => $cart_has_subscription,
89+
'bizumStyle' => json_decode( $bizum_style ),
8690
);
8791

88-
if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) {
89-
92+
$hide_logo = $this->get_setting( 'hide_logo' );
93+
if ( 'yes' === $hide_logo ) {
9094
unset( $data['logo'] );
91-
9295
}
9396

9497
return $data;

src/Gateways/Blocks/MoneiPaypalBlocksSupport.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ public function is_active() {
6060
}
6161

6262
public function get_payment_method_data() {
63-
$total = isset( WC()->cart ) ? WC()->cart->get_total( false ) : 0;
64-
$data = array(
63+
$total = WC()->cart !== null ? WC()->cart->get_total( false ) : 0;
64+
$paypal_style = $this->get_setting( 'paypal_style' );
65+
if ( ! $paypal_style ) {
66+
$paypal_style = '{}';
67+
}
68+
$data = array(
6569

6670
'title' => $this->gateway->title,
67-
'description' => $this->gateway->description,
6871
'logo' => WC_Monei()->plugin_url() . '/public/images/paypal-logo.svg',
6972
'supports' => $this->get_supported_features(),
7073
'currency' => get_woocommerce_currency(),
@@ -75,13 +78,13 @@ public function get_payment_method_data() {
7578
// no: live,
7679
'test_mode' => $this->gateway->getTestmode() ?? false,
7780
'accountId' => $this->gateway->getAccountId() ?? false,
78-
'sessionId' => ( wc()->session ) ? wc()->session->get_customer_id() : '',
81+
'sessionId' => wc()->session !== null ? wc()->session->get_customer_id() : '',
82+
'paypalStyle' => json_decode( $paypal_style ),
7983
);
8084

81-
if ( 'yes' === $this->get_setting( 'hide_logo' ) ?? 'no' ) {
82-
85+
$hide_logo = $this->get_setting( 'hide_logo' );
86+
if ( 'yes' === $hide_logo ) {
8387
unset( $data['logo'] );
84-
8588
}
8689

8790
return $data;

0 commit comments

Comments
 (0)