PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.1.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.1.1
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / fields / payment-markup.php

payment-markup.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.1.1, at inc/fields/payment-markup.php

701 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SureDonation Payment Markup Class file.
4 *
5 * @package SureDonation
6 * @since 0.0.1
7 */
8
9 namespace SureDonation\Inc\Fields;
10
11 use SureDonation\Inc\Helper;
12 use SureDonation\Inc\Payments\Offline\Offline_Helper;
13 use SureDonation\Inc\Payments\Payment_Helper;
14 use SureDonation\Inc\Payments\Stripe\Stripe_Helper;
15 use SureDonation\Inc\Post_Types\Donation_Form;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit; // Exit if accessed directly.
19 }
20
21 /**
22 * SureDonation Payment Markup Class.
23 *
24 * @since 0.0.1
25 */
26 class Payment_Markup extends Base {
27 /**
28 * Payment amount.
29 *
30 * @var float
31 * @since 0.0.1
32 */
33 protected $amount;
34
35 /**
36 * Payment currency.
37 *
38 * @var string
39 * @since 0.0.1
40 */
41 protected $currency;
42
43 /**
44 * Stripe publishable key.
45 *
46 * @var string
47 * @since 0.0.1
48 */
49 protected $stripe_publishable_key;
50
51 /**
52 * Whether Stripe is connected.
53 *
54 * @var bool
55 * @since 0.0.1
56 */
57 protected $stripe_connected;
58
59 /**
60 * Payment mode (live or test).
61 *
62 * @var string
63 * @since 0.0.1
64 */
65 protected $payment_mode;
66
67 /**
68 * Payment type.
69 *
70 * @var string
71 * @since 0.0.1
72 */
73 protected $payment_type;
74
75 /**
76 * Subscription plans.
77 *
78 * @var array<string, mixed>
79 * @since 0.0.1
80 */
81 protected $subscription_plan;
82
83 /**
84 * Amount type.
85 *
86 * @var string
87 * @since 0.0.1
88 */
89 protected $amount_type;
90
91 /**
92 * Fixed amount.
93 *
94 * @var float
95 * @since 0.0.1
96 */
97 protected $fixed_amount;
98
99 /**
100 * Minimum amount.
101 *
102 * @var float
103 * @since 0.0.1
104 */
105 protected $minimum_amount;
106
107 /**
108 * Customer name field slug.
109 *
110 * @var string
111 * @since 0.0.1
112 */
113 protected $customer_name_field;
114
115 /**
116 * Customer email field slug.
117 *
118 * @var string
119 * @since 0.0.1
120 */
121 protected $customer_email_field;
122
123 /**
124 * Variable amount field slug.
125 *
126 * @var string
127 * @since 0.0.1
128 */
129 protected $variable_amount_field;
130
131 /**
132 * Payment methods enabled for this block.
133 *
134 * @var array<string>
135 * @since 1.0.0
136 */
137 protected $payment_methods = [];
138
139 /**
140 * Aria-describedby attribute value.
141 *
142 * @var string
143 * @since 0.0.1
144 */
145 protected $aria_described_by = '';
146
147 /**
148 * Constructor for the Payment Markup class.
149 *
150 * @param array<mixed> $attributes Block attributes.
151 * @since 0.0.1
152 */
153 public function __construct( $attributes ) {
154 // Get payment settings from Stripe Helper.
155 $this->stripe_connected = Stripe_Helper::is_stripe_connected();
156 $this->payment_mode = Payment_Helper::get_payment_mode();
157
158 $this->slug = 'payment';
159 $this->set_properties( $attributes );
160 $this->set_unique_slug();
161 $this->set_markup_properties();
162
163 // Build aria-describedby attribute.
164 $this->aria_described_by = $this->get_aria_describedby();
165
166 // Set payment-specific properties.
167 $this->amount = $attributes['amount'] ?? 10;
168 $this->currency = $attributes['currency'] ?? 'USD';
169
170 // Use currency from settings if not specified in block.
171 if ( empty( $this->currency ) || 'USD' === $this->currency ) {
172 $this->currency = Payment_Helper::get_currency();
173 }
174
175 // Get appropriate Stripe publishable key based on mode.
176 $this->stripe_publishable_key = Stripe_Helper::get_stripe_publishable_key();
177
178 // Fall back to one-time if subscription is configured but pro is not active.
179 $configured_type = $attributes['paymentType'] ?? 'one-time';
180 $this->payment_type = 'subscription' === $configured_type && ! defined( 'SUREDONATION_PRO_VER' ) ? 'one-time' : $configured_type;
181 $this->subscription_plan = $attributes['subscriptionPlan'] ?? [];
182 $this->amount_type = $attributes['amountType'] ?? 'fixed';
183 $this->fixed_amount = $attributes['fixedAmount'] ?? 10;
184 $this->minimum_amount = $attributes['minimumAmount'] ?? 0;
185
186 // Set customer field mappings.
187 $this->customer_name_field = $attributes['customerNameField'] ?? '';
188 $this->customer_email_field = $attributes['customerEmailField'] ?? '';
189
190 // Set variable amount field mapping.
191 $this->variable_amount_field = $attributes['variableAmountField'] ?? '';
192
193 // Parse payment methods from block attributes (with backward compat fallback).
194 $block_payment_methods = $attributes['paymentMethods'] ?? null;
195 if ( ! is_array( $block_payment_methods ) || empty( $block_payment_methods ) ) {
196 $gateway = $attributes['gateway'] ?? 'stripe';
197 $block_payment_methods = [ is_string( $gateway ) ? $gateway : 'stripe' ];
198 }
199
200 // Filter to only globally-available gateways.
201 $available = [];
202 foreach ( $block_payment_methods as $method ) {
203 if ( 'stripe' === $method && $this->stripe_connected && ! empty( $this->stripe_publishable_key ) ) {
204 $available[] = 'stripe';
205 } elseif ( 'offline' === $method && Offline_Helper::is_offline_enabled() ) {
206 $available[] = 'offline';
207 }
208 }
209
210 /**
211 * Filter the list of available payment methods for this block.
212 *
213 * Allows extensions (e.g., PayPal) to add themselves when connected.
214 *
215 * @param array<string> $available Currently available method IDs.
216 * @param array<string> $block_payment_methods Methods selected in the block.
217 * @param array<string,mixed> $attributes Block attributes.
218 * @since 1.0.0
219 */
220 $available = apply_filters( 'suredonation_available_payment_methods', $available, $block_payment_methods, $attributes );
221
222 $this->payment_methods = ! empty( $available ) ? $available : $block_payment_methods;
223
224 // BACKWARD COMPATIBILITY: Migrate customer fields from subscriptionPlan.
225 if ( empty( $this->customer_name_field ) && ! empty( $this->subscription_plan['customer_name'] ) ) {
226 $this->customer_name_field = $this->subscription_plan['customer_name'];
227 }
228
229 if ( empty( $this->customer_email_field ) && ! empty( $this->subscription_plan['customer_email'] ) ) {
230 $this->customer_email_field = $this->subscription_plan['customer_email'];
231 }
232 }
233
234 /**
235 * Render the payment field markup.
236 *
237 * @return string
238 * @since 0.0.1
239 */
240 public function markup() {
241 $has_stripe = in_array( 'stripe', $this->payment_methods, true );
242
243 // Determine which gateways are actually connected/available for this form.
244 // get_registered_payment_methods() returns only enabled methods (Stripe when
245 // connected, Offline when enabled, plus any added by extensions such as
246 // PayPal), so it is the single gateway-agnostic source of truth.
247 $methods = $this->get_registered_payment_methods();
248
249 // No payment gateway is connected/available. Show a clear message instead of
250 // returning an empty string, which previously left donors with a silently
251 // broken form and no way to donate. See issue #219.
252 if ( empty( $methods ) ) {
253 return $this->render_gateway_unavailable_notice();
254 }
255
256 // Validate payment field requirements.
257 if ( ! $this->validate_payment_requirements() ) {
258 return '';
259 }
260
261 $field_classes = $this->get_field_classes();
262 $payment_methods_csv = implode( ',', $this->payment_methods );
263 $default_gateway = $this->payment_methods[0];
264
265 ob_start();
266 ?>
267 <div data-block-id="<?php echo esc_attr( $this->block_id ); ?>"
268 data-form-id="<?php echo esc_attr( $this->form_id ); ?>"
269 class="<?php echo esc_attr( $field_classes ); ?>"
270 data-payment-methods="<?php echo esc_attr( $payment_methods_csv ); ?>"
271 data-gateway="<?php echo esc_attr( $default_gateway ); ?>"
272 <?php if ( $has_stripe && ! empty( $this->stripe_publishable_key ) ) { ?>
273 data-stripe-key="<?php echo esc_attr( $this->stripe_publishable_key ); ?>"
274 <?php } ?>
275 data-currency="<?php echo esc_attr( strtolower( $this->currency ) ); ?>"
276 data-currency-symbol="<?php echo esc_attr( Payment_Helper::get_currency_symbol( $this->currency ) ); ?>"
277 data-payment-mode="<?php echo esc_attr( $this->payment_mode ); ?>"
278 data-amount-type="<?php echo esc_attr( $this->amount_type ); ?>"
279 data-fixed-amount="<?php echo esc_attr( (string) $this->fixed_amount ); ?>"
280 data-payment-type="<?php echo esc_attr( $this->payment_type ); ?>"
281 data-customer-name-field="<?php echo esc_attr( $this->customer_name_field ); ?>"
282 data-customer-email-field="<?php echo esc_attr( $this->customer_email_field ); ?>"
283 data-nonce="<?php echo esc_attr( wp_create_nonce( 'suredonation_donation_form' ) ); ?>"
284 <?php if ( 'variable' === $this->amount_type ) { ?>
285 data-variable-amount-field="<?php echo esc_attr( $this->variable_amount_field ); ?>"
286 <?php } ?>
287 <?php if ( $this->minimum_amount > 0 ) { ?>
288 data-minimum-amount="<?php echo esc_attr( (string) $this->minimum_amount ); ?>"
289 <?php } ?>
290 <?php if ( 'subscription' === $this->payment_type && ! empty( $this->subscription_plan ) ) { ?>
291 data-subscription-plan-name="<?php echo esc_attr( isset( $this->subscription_plan['name'] ) ? Helper::get_string_value( $this->subscription_plan['name'] ) : __( 'Subscription Plan', 'suredonation' ) ); ?>"
292 data-subscription-interval="<?php echo esc_attr( isset( $this->subscription_plan['interval'] ) ? Helper::get_string_value( $this->subscription_plan['interval'] ) : 'month' ); ?>"
293 data-subscription-billing-cycles="<?php echo esc_attr( isset( $this->subscription_plan['billingCycles'] ) ? Helper::get_string_value( $this->subscription_plan['billingCycles'] ) : '0' ); ?>"
294 <?php } ?>
295 >
296 <?php echo wp_kses_post( $this->label_markup ); ?>
297 <?php echo wp_kses_post( $this->help_markup ); ?>
298 <div class="sd-payment-field-wrapper">
299 <?php
300 // Amount display — uses wp_kses with data attributes allowed
301 // because wp_kses_post strips data-message-format, data-currency-symbol etc.
302 echo wp_kses( $this->render_amount_display(), Helper::get_allowed_form_html() );
303
304 // Test mode notice.
305 if ( 'test' === $this->payment_mode && $has_stripe ) {
306 echo wp_kses_post( $this->get_test_mode_notice() );
307 }
308
309 // Payment methods accordion ( $methods computed above ).
310 echo $this->render_payment_methods_accordion( $methods ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Method builds markup with esc_attr/esc_html on all dynamic values and wp_kses_post on content.
311 ?>
312
313 <!-- Payment error display (hidden via CSS; shown by JS on error). -->
314 <div class="sd-payment-error"></div>
315 </div>
316 </div>
317 <?php
318 $output = ob_get_clean();
319 return false !== $output ? $output : '';
320 }
321
322 /**
323 * Get registered payment methods for display.
324 *
325 * @return array<mixed> Array of payment method configurations.
326 * @since 1.0.0
327 */
328 private function get_registered_payment_methods() {
329 $available_methods = [
330 'stripe' => [
331 'id' => 'stripe',
332 'label' => __( 'Credit / Debit Card', 'suredonation' ),
333 'enabled' => $this->stripe_connected && ! empty( $this->stripe_publishable_key ),
334 'container_class' => 'sd-payment-element',
335 'container_id' => 'sd-payment-element-' . $this->block_id,
336 ],
337 'offline' => [
338 'id' => 'offline',
339 'label' => __( 'Offline Payment', 'suredonation' ),
340 'enabled' => Offline_Helper::is_offline_enabled(),
341 'container_class' => 'sd-offline-instructions',
342 'content' => Offline_Helper::get_offline_instructions( $this->get_campaign_name() ),
343 ],
344 ];
345
346 $methods = [];
347 foreach ( $this->payment_methods as $method_id ) {
348 if ( isset( $available_methods[ $method_id ] ) && $available_methods[ $method_id ]['enabled'] ) {
349 $methods[ $method_id ] = $available_methods[ $method_id ];
350 }
351 }
352
353 /**
354 * Filter the registered payment methods and their display config.
355 *
356 * Allows extensions to add payment methods (e.g., PayPal) with their
357 * label, container class, and enabled state for frontend rendering.
358 *
359 * @param array<string, array<string,mixed>> $methods Registered methods keyed by ID.
360 * @param array<string> $payment_methods Methods selected in this block.
361 * @param string $block_id The block ID.
362 * @since 1.0.0
363 */
364 return apply_filters( 'suredonation_registered_payment_methods', $methods, $this->payment_methods, $this->block_id );
365 }
366
367 /**
368 * Get the campaign name for this form.
369 *
370 * @return string Campaign name or empty string.
371 * @since 1.0.0
372 */
373 private function get_campaign_name() {
374 if ( empty( $this->form_id ) ) {
375 return '';
376 }
377
378 $campaign_id = Donation_Form::get_form_campaign_id( absint( $this->form_id ) );
379
380 if ( empty( $campaign_id ) ) {
381 return '';
382 }
383
384 return get_the_title( $campaign_id );
385 }
386
387 /**
388 * Render payment methods as accordion.
389 * Each payment method is an accordion item with header and collapsible content.
390 *
391 * @param array<mixed> $methods Array of payment methods.
392 * @return string Payment methods accordion markup.
393 * @since 1.0.0
394 */
395 private function render_payment_methods_accordion( $methods ) {
396 if ( empty( $methods ) || ! is_array( $methods ) ) {
397 return '';
398 }
399
400 $is_single_method = count( $methods ) === 1;
401 $is_first = true;
402
403 ob_start();
404 ?>
405 <div class="sd-payment-methods-accordion <?php echo esc_attr( $is_single_method ? 'sd-single-payment-method' : '' ); ?>">
406 <?php foreach ( $methods as $method ) { ?>
407 <div
408 class="sd-accordion-item <?php echo esc_attr( $is_first ? 'sd-payment-active' : '' ); ?>"
409 data-method="<?php echo esc_attr( $method['id'] ); ?>"
410 >
411 <div
412 class="sd-accordion-header"
413 role="button"
414 tabindex="0"
415 aria-expanded="<?php echo esc_attr( $is_first ? 'true' : 'false' ); ?>"
416 aria-controls="sd-accordion-content-<?php echo esc_attr( $method['id'] ); ?>-<?php echo esc_attr( $this->block_id ); ?>"
417 >
418 <div class="sd-payment-input-wrapper">
419 <input
420 type="radio"
421 name="sd-gateway-choice-<?php echo esc_attr( $this->block_id ); ?>"
422 value="<?php echo esc_attr( $method['id'] ); ?>"
423 class="sd-payment-method-radio"
424 data-method="<?php echo esc_attr( $method['id'] ); ?>"
425 <?php checked( $is_first ); ?>
426 aria-label="<?php echo esc_attr( $method['label'] ); ?>"
427 />
428 <span class="sd-accordion-title sd-block-label">
429 <?php echo esc_html( $method['label'] ); ?>
430 </span>
431 </div>
432 </div>
433 <div
434 id="sd-accordion-content-<?php echo esc_attr( $method['id'] ); ?>-<?php echo esc_attr( $this->block_id ); ?>"
435 class="sd-accordion-content"
436 role="region"
437 >
438 <div
439 class="sd-payment-method-content"
440 data-method="<?php echo esc_attr( $method['id'] ); ?>"
441 >
442 <div
443 <?php if ( ! empty( $method['container_id'] ) ) { ?>
444 id="<?php echo esc_attr( $method['container_id'] ); ?>"
445 <?php } ?>
446 class="<?php echo esc_attr( $method['container_class'] ); ?>"
447 >
448 <?php
449 if ( ! empty( $method['content'] ) ) {
450 echo wp_kses_post( $method['content'] );
451 }
452 ?>
453 </div>
454 </div>
455 </div>
456 </div>
457 <?php $is_first = false; ?>
458 <?php } ?>
459 </div>
460 <?php
461 $template = ob_get_clean();
462
463 return is_string( $template ) ? $template : '';
464 }
465
466 /**
467 * Render amount display section.
468 *
469 * @return string Amount display HTML.
470 * @since 0.0.1
471 */
472 private function render_amount_display() {
473 ob_start();
474
475 if ( 'fixed' === $this->amount_type ) {
476 ?>
477 <!-- Fixed Payment Amount Display. -->
478 <div class="sd-payment-amount sd-label">
479 <span class="sd-payment-value">
480 <?php
481 if ( 'subscription' === $this->payment_type && ! empty( $this->subscription_plan ) ) {
482 $interval = isset( $this->subscription_plan['interval'] ) ? Helper::get_string_value( $this->subscription_plan['interval'] ) : 'month';
483 $billing_cycles = isset( $this->subscription_plan['billingCycles'] ) ? Helper::get_string_value( $this->subscription_plan['billingCycles'] ) : '0';
484 $interval_label = $this->get_interval_label( $interval );
485
486 // Build subscription text.
487 if ( 'ongoing' === $billing_cycles ) {
488 echo esc_html(
489 sprintf(
490 /* translators: 1: Amount with currency, 2: Interval (day/week/month/quarter/year) */
491 __( '%1$s per %2$s (until cancelled)', 'suredonation' ),
492 $this->format_currency( $this->fixed_amount, $this->currency ),
493 $interval_label
494 )
495 );
496 } elseif ( (int) $billing_cycles > 0 ) {
497 echo esc_html(
498 sprintf(
499 /* translators: 1: Amount with currency, 2: Interval (day/week/month/quarter/year), 3: Number of billing cycles */
500 __( '%1$s per %2$s (%3$s payments)', 'suredonation' ),
501 $this->format_currency( $this->fixed_amount, $this->currency ),
502 $interval_label,
503 $billing_cycles
504 )
505 );
506 } else {
507 echo esc_html(
508 sprintf(
509 /* translators: 1: Amount with currency, 2: Interval (day/week/month/quarter/year) */
510 __( '%1$s per %2$s', 'suredonation' ),
511 $this->format_currency( $this->fixed_amount, $this->currency ),
512 $interval_label
513 )
514 );
515 }
516 } else {
517 echo esc_html( $this->format_currency( $this->fixed_amount, $this->currency ) );
518 }
519 ?>
520 </span>
521 </div>
522 <?php
523 } else {
524 ?>
525 <!-- Variable Payment Amount Display. -->
526 <div class="sd-variable-amount-display sd-label">
527 <div class="sd-payment-amount-wrapper">
528 <?php
529 // Generate message format for variable amounts.
530 $message_format = '{amount}';
531 if ( 'subscription' === $this->payment_type && ! empty( $this->subscription_plan ) ) {
532 $interval = isset( $this->subscription_plan['interval'] ) ? Helper::get_string_value( $this->subscription_plan['interval'] ) : 'month';
533 $billing_cycles = isset( $this->subscription_plan['billingCycles'] ) ? Helper::get_string_value( $this->subscription_plan['billingCycles'] ) : '0';
534 $interval_label = $this->get_interval_label( $interval );
535
536 // Build message format based on billing cycles.
537 if ( 'ongoing' === $billing_cycles ) {
538 /* translators: 1: Amount with currency placeholder, 2: Interval (day/week/month/quarter/year) */
539 $message_format = sprintf( __( '{amount} per %s (until cancelled)', 'suredonation' ), $interval_label );
540 } elseif ( (int) $billing_cycles > 0 ) {
541 /* translators: 1: Amount with currency placeholder, 2: Interval (day/week/month/quarter/year), 3: Number of billing cycles */
542 $message_format = sprintf( __( '{amount} per %1$s (%2$s payments)', 'suredonation' ), $interval_label, $billing_cycles );
543 } else {
544 /* translators: 1: Amount with currency placeholder, 2: Interval (day/week/month/quarter/year) */
545 $message_format = sprintf( __( '{amount} per %s', 'suredonation' ), $interval_label );
546 }
547 }
548 ?>
549 <span class="sd-payment-value" data-currency="<?php echo esc_attr( strtolower( $this->currency ) ); ?>" data-currency-symbol="<?php echo esc_attr( Payment_Helper::get_currency_symbol( $this->currency ) ); ?>" data-message-format="<?php echo esc_attr( $message_format ); ?>">
550 <?php esc_html_e( 'Complete the form to view the amount.', 'suredonation' ); ?>
551 </span>
552 </div>
553 <?php if ( $this->minimum_amount > 0 ) { ?>
554 <span class="sd-help">
555 <?php
556 echo esc_html(
557 sprintf(
558 /* translators: %s: Minimum amount with currency */
559 __( 'Minimum amount: %s', 'suredonation' ),
560 $this->format_currency( $this->minimum_amount, $this->currency )
561 )
562 );
563 ?>
564 </span>
565 <?php } ?>
566 </div>
567 <?php
568 }
569
570 return (string) ob_get_clean();
571 }
572
573 /**
574 * Validate payment field requirements.
575 *
576 * @return bool True if validation passes, false otherwise.
577 * @since 0.0.1
578 */
579 private function validate_payment_requirements() {
580 // Check customer email field requirement (highest priority).
581 if ( empty( $this->customer_email_field ) ) {
582 return false;
583 }
584
585 // Check subscription-specific requirements.
586 if ( 'subscription' === $this->payment_type ) {
587 if ( empty( $this->customer_name_field ) ) {
588 return false;
589 }
590
591 if ( empty( $this->subscription_plan ) || empty( $this->subscription_plan['name'] ) ) {
592 return false;
593 }
594 }
595
596 return true;
597 }
598
599 /**
600 * Format currency for display.
601 *
602 * @param float $amount Amount to format.
603 * @param string $currency Currency code.
604 * @return string
605 * @since 0.0.1
606 */
607 private function format_currency( $amount, $currency ) {
608 $symbol = Payment_Helper::get_currency_symbol( $currency );
609
610 // Format based on currency.
611 if ( in_array( $currency, [ 'JPY', 'KRW' ], true ) ) {
612 // No decimal places for these currencies.
613 return $symbol . number_format( $amount, 0 );
614 }
615
616 return $symbol . number_format( $amount, 2 );
617 }
618
619 /**
620 * Get the human-readable label for a payment interval slug.
621 *
622 * @param string $interval_slug The slug (e.g., 'day', 'week', 'month', 'quarter', 'yearly').
623 * @return string The translated interval label, or the slug itself if not found.
624 * @since 0.0.1
625 */
626 private function get_interval_label( $interval_slug ) {
627 $interval_labels = [
628 'day' => __( 'day', 'suredonation' ),
629 'week' => __( 'week', 'suredonation' ),
630 'month' => __( 'month', 'suredonation' ),
631 'quarter' => __( 'quarter', 'suredonation' ),
632 'yearly' => __( 'year', 'suredonation' ),
633 ];
634
635 return $interval_labels[ $interval_slug ] ?? $interval_slug;
636 }
637
638 /**
639 * Render test mode notice for admin users.
640 * Only shows if user has manage_options capability.
641 *
642 * @return string Test mode notice markup or empty string.
643 * @since 0.0.1
644 */
645 private function get_test_mode_notice() {
646 // Only show to users with manage_options capability.
647 if ( ! current_user_can( 'manage_options' ) ) {
648 return '';
649 }
650
651 // Build dynamic link to payment settings.
652 $settings_url = admin_url( 'admin.php?page=suredonation_settings&tab=payments' );
653
654 ob_start();
655 ?>
656 <div class="sd-test-mode-notice">
657 <strong><?php esc_html_e( 'Test mode is enabled:', 'suredonation' ); ?></strong>
658 <a href="<?php echo esc_url( $settings_url ); ?>" target="_blank" rel="noopener noreferrer">
659 <?php esc_html_e( 'Click here to enable live mode and accept payment', 'suredonation' ); ?>
660 </a>
661 </div>
662 <?php
663 $output = ob_get_clean();
664 return false !== $output ? $output : '';
665 }
666
667 /**
668 * Render the notice shown when no payment gateway is connected/available.
669 *
670 * Replaces the previous behavior of rendering nothing, which left donors with
671 * a silently broken form. The `data-payment-available="0"` marker lets the
672 * frontend script skip gateway init and hide the otherwise-inert submit
673 * button. See issue #219.
674 *
675 * @return string Notice markup.
676 * @since 1.1.1
677 */
678 private function render_gateway_unavailable_notice() {
679 $field_classes = $this->get_field_classes( [ 'sd-payment-unavailable' ] );
680
681 ob_start();
682 ?>
683 <div
684 data-block-id="<?php echo esc_attr( $this->block_id ); ?>"
685 data-form-id="<?php echo esc_attr( $this->form_id ); ?>"
686 data-payment-available="0"
687 class="<?php echo esc_attr( $field_classes ); ?>"
688 >
689 <?php echo wp_kses_post( $this->label_markup ); ?>
690 <div class="sd-payment-field-wrapper">
691 <div class="sd-payment-notice" role="status">
692 <p><?php esc_html_e( 'Payment gateways are not configured. Please contact the site administrator.', 'suredonation' ); ?></p>
693 </div>
694 </div>
695 </div>
696 <?php
697 $output = ob_get_clean();
698 return false !== $output ? $output : '';
699 }
700 }
701