Skip to content

Commit 074b5c0

Browse files
committed
fix: hide description in component mode for Bizum Classic checkout
1 parent bea5f04 commit 074b5c0

File tree

1 file changed

+66
-14
lines changed

1 file changed

+66
-14
lines changed

src/Gateways/PaymentMethods/WCGatewayMoneiBizum.php

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class WCGatewayMoneiBizum extends WCMoneiPaymentGatewayHosted {
2424

2525
const PAYMENT_METHOD = 'bizum';
2626

27+
/**
28+
* @var bool
29+
*/
30+
protected $redirect_flow;
31+
2732
/**
2833
* Constructor for the gateway.
2934
*
@@ -55,8 +60,9 @@ public function __construct(
5560
// Settings variable
5661
$this->hide_logo = ( ! empty( $this->get_option( 'hide_logo' ) && 'yes' === $this->get_option( 'hide_logo' ) ) ) ? true : false;
5762
$this->icon = ( $this->hide_logo ) ? '' : $iconMarkup;
63+
$this->redirect_flow = ( ! empty( $this->get_option( 'bizum_mode' ) && 'yes' === $this->get_option( 'bizum_mode' ) ) ) ? true : false;
5864
$this->title = ( ! empty( $this->get_option( 'title' ) ) ) ? $this->get_option( 'title' ) : '';
59-
$this->description = ( ! empty( $this->get_option( 'description' ) ) ) ? $this->get_option( 'description' ) : ' ';
65+
$this->description = ( ! empty( $this->get_option( 'description' ) ) ) ? $this->get_option( 'description' ) : '';
6066
$this->status_after_payment = ( ! empty( $this->get_option( 'orderdo' ) ) ) ? $this->get_option( 'orderdo' ) : '';
6167
$this->api_key = $this->getApiKey();
6268
$this->account_id = $this->getAccountId();
@@ -112,6 +118,39 @@ public function init_form_fields() {
112118
$this->form_fields = require WC_Monei()->plugin_path() . '/includes/admin/monei-bizum-settings.php';
113119
}
114120

121+
/**
122+
* Validate bizum_style field
123+
*
124+
* @param string $key
125+
* @param string $value
126+
* @return string
127+
*/
128+
public function validate_bizum_style_field( $key, $value ) {
129+
if ( empty( $value ) ) {
130+
return $value;
131+
}
132+
133+
// WordPress adds slashes to $_POST data, we need to remove them before validating JSON
134+
$value = stripslashes( $value );
135+
136+
// Try to decode JSON
137+
json_decode( $value );
138+
139+
// Check for JSON errors
140+
if ( json_last_error() !== JSON_ERROR_NONE ) {
141+
\WC_Admin_Settings::add_error(
142+
sprintf(
143+
/* translators: %s: JSON error message */
144+
__( 'Bizum Style field contains invalid JSON: %s', 'monei' ),
145+
json_last_error_msg()
146+
)
147+
);
148+
return $this->get_option( 'bizum_style', '{"height": "50px"}' );
149+
}
150+
151+
return $value;
152+
}
153+
115154
/**
116155
* Process the payment and return the result
117156
*
@@ -135,13 +174,20 @@ protected function get_frontend_generated_token() {
135174
}
136175

137176
public function payment_fields() {
138-
echo '<fieldset id="monei-bizum-form" class="monei-fieldset monei-payment-request-fieldset">
139-
<div
140-
id="bizum-container"
141-
class="monei-payment-request-container"
142-
>
143-
</div>
144-
</fieldset>';
177+
// Show description only in redirect mode
178+
if ( $this->redirect_flow && $this->description ) {
179+
echo wpautop( wptexturize( $this->description ) );
180+
}
181+
// Only render Bizum button if not using redirect flow
182+
if ( ! $this->redirect_flow ) {
183+
echo '<fieldset id="monei-bizum-form" class="monei-fieldset monei-payment-request-fieldset">
184+
<div
185+
id="bizum-container"
186+
class="monei-payment-request-container"
187+
>
188+
</div>
189+
</fieldset>';
190+
}
145191
}
146192

147193
public function bizum_scripts() {
@@ -151,6 +197,10 @@ public function bizum_scripts() {
151197
if ( 'no' === $this->enabled ) {
152198
return;
153199
}
200+
// Don't enqueue scripts if using redirect flow
201+
if ( $this->redirect_flow ) {
202+
return;
203+
}
154204
if ( ! wp_script_is( 'monei', 'registered' ) ) {
155205
wp_register_script( 'monei', 'https://js.monei.com/v2/monei.js', '', '1.0', true );
156206
}
@@ -170,17 +220,19 @@ public function bizum_scripts() {
170220
wp_enqueue_script( 'woocommerce_monei-bizum' );
171221

172222
// Determine the total amount to be passed
173-
$total = $this->determineTheTotalAmountToBePassed();
223+
$total = $this->determineTheTotalAmountToBePassed();
224+
$bizum_style = $this->get_option( 'bizum_style', '{}' );
174225

175226
wp_localize_script(
176227
'woocommerce_monei-bizum',
177228
'wc_bizum_params',
178229
array(
179-
'account_id' => $this->getAccountId(),
180-
'session_id' => WC()->session->get_customer_id(),
181-
'total' => monei_price_format( $total ),
182-
'currency' => get_woocommerce_currency(),
183-
'language' => locale_iso_639_1_code(),
230+
'account_id' => $this->getAccountId(),
231+
'session_id' => WC()->session->get_customer_id(),
232+
'total' => monei_price_format( $total ),
233+
'currency' => get_woocommerce_currency(),
234+
'language' => locale_iso_639_1_code(),
235+
'bizum_style' => json_decode( $bizum_style ),
184236
)
185237
);
186238
}

0 commit comments

Comments
 (0)