PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.0
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / includes / Classes / Handler.php

Handler.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.0, at includes/Classes/Handler.php

1,667 lines 101.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Classes;
4
5 use Better_Payment\Lite\Admin\DB;
6 use Better_Payment\Lite\Controller;
7 use Better_Payment\Lite\Classes\Helper;
8 use Better_Payment\Lite\Traits\Helper as TraitsHelper;
9
10 /**
11 * Exit if accessed directly
12 */
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * The plugin handler class
19 *
20 * @since 0.0.1
21 */
22 class Handler extends Controller{
23 use TraitsHelper;
24
25 /**
26 * PayPal button
27 *
28 * @since 0.0.1
29 */
30 public static function paypal_button( $widget_id = '' , $settings = [], $args = [] ) {
31 global $wp;
32
33 $args['extra_classes'] = ! empty( $args['extra_classes'] ) ? $args['extra_classes'] : '';
34 $args['extra_classes'] = is_array($args['extra_classes']) ? implode(' ', $args['extra_classes']) : $args['extra_classes'];
35 $args['button_text_default'] = ! empty( $args['button_text_default'] ) ? sanitize_text_field( $args['button_text_default'] ) : 'Proceed to Payment';
36
37 $paypal_button_text = ! empty( $settings["better_payment_form_form_buttons_paypal_button_text"] ) ? sanitize_text_field( $settings["better_payment_form_form_buttons_paypal_button_text"] ) : __( $args['button_text_default'], 'better-payment' );
38
39 $return_url = add_query_arg( $wp->query_vars, get_the_permalink() . '?better_payment_paypal_status=success&better_payment_widget_id=' . $widget_id );
40 $cancel_url = add_query_arg( $wp->query_vars, get_the_permalink() . '?better_payment_error_status=error&better_payment_widget_id=' . $widget_id );
41
42 ob_start();
43 $error_info = [
44 'business_email' => !empty($settings['better_payment_paypal_business_email'])
45 ];
46 ?>
47 <input type="hidden" name="return" value="<?php echo esc_url( $return_url ); ?>">
48 <input type="hidden" name="action" value="paypal_form_handle">
49 <input type="hidden" name="security" value="<?php echo esc_attr( wp_create_nonce('better-payment-paypal') ); ?>">
50 <input type="hidden" name="cancel_return" value="<?php echo esc_url( $cancel_url ); ?>">
51 <button data-paypal-info = <?php echo esc_attr(wp_json_encode( $error_info) ) ; ?> class="button is-medium is-fullwidth better-payment-paypal-bt <?php echo esc_attr( self::hide_show_payment_button_class($settings, 'paypal') ); ?> <?php echo esc_attr( $args['extra_classes'] ); ?>" ><?php echo esc_html( $paypal_button_text ); ?></button>
52
53 <?php
54 $paypal_button_html = ob_get_clean();
55 $paypal_button_html = apply_filters( 'better_payment/elementor/editor/paypal_button_html', $paypal_button_html, $widget_id, $settings );
56
57 echo $paypal_button_html;
58 }
59
60 /**
61 * Stripe button
62 *
63 * @since 0.0.1
64 */
65 public static function stripe_button( $widget_id = '' , $settings = [], $args = [] ) {
66 $args['extra_classes'] = ! empty( $args['extra_classes'] ) ? $args['extra_classes'] : '';
67 $args['extra_classes'] = is_array($args['extra_classes']) ? implode(' ', $args['extra_classes']) : $args['extra_classes'];
68 $args['button_text_default'] = ! empty( $args['button_text_default'] ) ? sanitize_text_field( $args['button_text_default'] ) : 'Proceed to Payment';
69
70 $stripe_button_text = ! empty( $settings["better_payment_form_form_buttons_stripe_button_text"] ) ? sanitize_text_field( $settings["better_payment_form_form_buttons_stripe_button_text"] ) : __( $args['button_text_default'], 'better-payment' );
71
72 ob_start();
73 ?>
74 <button class="button is-medium is-fullwidth better-payment-stripe-bt <?php echo esc_attr( self::hide_show_payment_button_class($settings, 'stripe') ); ?> <?php echo esc_attr( $args['extra_classes'] ); ?>" ><?php echo esc_html( $stripe_button_text ); ?></button>
75 <?php
76 $stripe_button_html = ob_get_clean();
77 $stripe_button_html = apply_filters( 'better_payment/elementor/editor/stripe_button_html', $stripe_button_html, $widget_id, $settings );
78
79 echo wp_kses( $stripe_button_html, (new Handler())->bp_allowed_tags() );
80 }
81
82 /**
83 * Paystack button
84 *
85 * @since 0.0.1
86 */
87 public static function paystack_button( $widget_id = '' , $settings = [], $args = [] ) {
88 $args['extra_classes'] = ! empty( $args['extra_classes'] ) ? $args['extra_classes'] : '';
89 $args['extra_classes'] = is_array($args['extra_classes']) ? implode(' ', $args['extra_classes']) : $args['extra_classes'];
90 $args['button_text_default'] = ! empty( $args['button_text_default'] ) ? sanitize_text_field( $args['button_text_default'] ) : 'Proceed to Payment';
91
92 $paystack_button_text = ! empty( $settings["better_payment_form_form_buttons_paystack_button_text"] ) ? sanitize_text_field( $settings["better_payment_form_form_buttons_paystack_button_text"] ) : __( $args['button_text_default'], 'better-payment' );
93
94 ob_start();
95 ?>
96 <button class="button is-medium is-fullwidth better-payment-paystack-bt <?php echo esc_attr( self::hide_show_payment_button_class($settings, 'paystack') ); ?> <?php echo esc_attr( $args['extra_classes'] ); ?>" ><?php echo esc_html( $paystack_button_text ); ?></button>
97 <?php
98 $paystack_button_html = ob_get_clean();
99 $paystack_button_html = apply_filters( 'better_payment/elementor/editor/paystack_button_html', $paystack_button_html, $widget_id, $settings );
100
101 echo wp_kses( $paystack_button_html, (new Handler())->bp_allowed_tags() );
102 }
103
104 public static function hide_show_payment_button_class( $settings, $type = 'paypal' ){
105 $button_hidden_class = 'is-hidden';
106 $types = ['paypal', 'stripe', 'paystack'];
107
108 if( ! in_array($type, $types) ){
109 return $button_hidden_class;
110 }
111
112 $is_type_enable = ! empty( $settings[ "better_payment_form_{$type}_enable" ] ) && 'yes' === $settings[ "better_payment_form_{$type}_enable" ];
113
114 if( ! $is_type_enable ){
115 return $button_hidden_class;
116 }
117
118 $is_paypal_enable = ! empty( $settings[ "better_payment_form_paypal_enable" ] ) && 'yes' === $settings[ "better_payment_form_paypal_enable" ];
119 $is_stripe_enable = ! empty( $settings[ "better_payment_form_stripe_enable" ] ) && 'yes' === $settings[ "better_payment_form_stripe_enable" ];
120 $is_paystack_enable = ! empty( $settings[ "better_payment_form_paystack_enable" ] ) && 'yes' === $settings[ "better_payment_form_paystack_enable" ];
121
122 switch( $type ){
123 case 'paypal':
124 $button_hidden_class = '';
125 break;
126
127 case 'stripe':
128 if( ( ! $is_paypal_enable ) ){
129 $button_hidden_class = '';
130 }
131
132 break;
133
134 case 'paystack':
135 if( ( ! $is_paypal_enable ) && ( ! $is_stripe_enable ) ){
136 $button_hidden_class = '';
137 }
138 break;
139
140 default:
141 break;
142 }
143
144 return $button_hidden_class;
145 }
146
147 /**
148 * Payment create in db
149 *
150 * @since 0.0.1
151 */
152 public static function payment_create( $data ) {
153 global $wpdb;
154 $table = "{$wpdb->prefix}better_payment";
155 $wpdb->insert( $table, $data );
156 if ( $wpdb->insert_id ) {
157 return $wpdb->insert_id;
158 } else {
159 return false;
160 }
161 }
162
163 /**
164 * Mamage response
165 *
166 * @since 0.0.1
167 */
168 public static function manage_response( $settings = [], $widget_id = '' ) {
169 $status = false;
170
171 //if widget id is different then return false
172 if ( !empty( $_REQUEST[ 'better_payment_widget_id' ] ) && $_REQUEST[ 'better_payment_widget_id' ] !== $widget_id ) {
173 return $status;
174 }
175
176 if ( !empty( $_REQUEST[ 'better_payment_error_status' ] ) ) {
177 // Determine order_id based on payment method
178 $order_id = '';
179 if ( !empty( $_REQUEST['better_payment_stripe_id'] ) ) {
180 $order_id = sanitize_text_field( $_REQUEST['better_payment_stripe_id'] );
181 } elseif ( !empty( $_REQUEST['better_payment_paystack_id'] ) ) {
182 $order_id = sanitize_text_field( $_REQUEST['better_payment_paystack_id'] );
183 } elseif ( !empty( $_REQUEST['better_payment_paypal_id'] ) ) {
184 $order_id = sanitize_text_field( $_REQUEST['better_payment_paypal_id'] );
185 }
186
187 // Fetch transaction data from database
188 $transaction_data = self::get_failed_transaction_data( $order_id );
189
190 self::failed_message_template( $settings, $transaction_data );
191 $redirection_url_error = ! empty( $settings['better_payment_form_error_page_url']['url'] ) ? esc_url( $settings['better_payment_form_error_page_url']['url'] ) : '';
192
193 if( $redirection_url_error ){
194 ?>
195 <script>
196 setTimeout(function(){
197 window.location.replace("<?php echo esc_url( $redirection_url_error ); ?>");
198 }, 2000);
199 </script>
200 <?php
201 }
202
203 return $status;
204 }
205
206 if ( !empty( $_REQUEST[ 'better_payment_paypal_status' ] ) && $_REQUEST[ 'better_payment_paypal_status' ] == 'success' ) {
207 $status = self::paypal_payment_success( $settings );
208 } elseif ( !empty( $_REQUEST[ 'better_payment_stripe_status' ] ) && $_REQUEST[ 'better_payment_stripe_status' ] == 'success' ) {
209 $status = self::stripe_payment_success( $settings );
210 } elseif ( !empty( $_REQUEST[ 'better_payment_paystack_status' ] ) && $_REQUEST[ 'better_payment_paystack_status' ] == 'success' ) {
211 $status = self::paystack_payment_success( $settings );
212 }
213
214 if ( $status ) {
215 self::success_message_template( $settings, $status );
216 $redirection_url_success = ! empty( $settings['better_payment_form_success_page_url']['url'] ) ? esc_url( $settings['better_payment_form_success_page_url']['url'] ) : '';
217
218 if( $redirection_url_success ){
219 ?>
220 <script>
221 setTimeout(function(){
222 window.location.replace("<?php echo esc_url( $redirection_url_success ); ?>");
223 }, 2000);
224 </script>
225 <?php
226 }
227 }
228 self::remove_arg();
229
230 return $status;
231 }
232
233 /**
234 * Paypal payment success
235 *
236 * @since 0.0.1
237 */
238 public static function paypal_payment_success( $settings = [] ) {
239 $data = $_REQUEST;
240 $frontend_data = [
241 'amount' => ! empty( $data['payment_gross'] ) ? floatval( $data['payment_gross'] ) : 0,
242 'email' => ! empty( $data['payer_email'] ) ? sanitize_email( $data['payer_email'] ) : '',
243 'transaction_id' => ! empty( $data[ 'txn_id' ] ) ? sanitize_text_field( $data[ 'txn_id' ] ) : '',
244 'currency' => ! empty( $data['mc_currency'] ) ? sanitize_text_field( $data['mc_currency'] ) : __( 'USD', 'better-payment' ),
245 'method' => 'paypal',
246 ];
247 if ( !empty( $data[ 'payment_status' ] ) && !empty( $data[ 'payer_id' ] ) && !empty( $data[ 'payer_status' ] ) ) {
248 global $wpdb;
249 $table = "{$wpdb->prefix}better_payment";
250 $results = $wpdb->get_row(
251 $wpdb->prepare( "SELECT id,form_fields_info,referer FROM $table WHERE order_id=%s and status is NULL limit 1", sanitize_text_field( $_REQUEST[ 'item_number' ] ) )
252 );
253
254 if ( !empty( $results->id ) ) {
255 $updated = $wpdb->update(
256 $table,
257 array(
258 'transaction_id' => sanitize_text_field( $data[ 'txn_id' ] ),
259 'status' => sanitize_text_field( $data[ 'payment_status' ] ),
260 'email' => sanitize_email( $data[ 'payer_email' ] ),
261 'customer_info' => maybe_serialize( $data ),
262 ),
263 array( 'ID' => $results->id )
264 );
265
266 if ( false !== $updated ) {
267 //Send email notification
268 if (
269 ( isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' )
270 || ( $results->referer === 'elementor-form' )
271 ) {
272 $is_elementor_form = ! empty( $results->referer ) && $results->referer === 'elementor-form' ? 1 : 0;
273 self::better_email_notification(sanitize_text_field( $data[ 'txn_id' ] ), sanitize_email( $data[ 'payer_email' ] ), $settings, 'PayPal', $results->form_fields_info, $is_elementor_form);
274 }
275
276 do_action( 'better_payment/payment/success', sanitize_text_field( $_REQUEST['item_number'] ?? '' ), (int) $results->id, 'paypal' );
277 do_action( 'better_payment/payment_confirmed', (int) $results->id );
278
279 return $frontend_data;
280 }
281 }
282 }else if($data['better_payment_paypal_status'] === 'success'){
283 return ( isset($data[ 'txn_id' ]) && !empty( sanitize_text_field( $data[ 'txn_id' ] ) ) ) ? $frontend_data : __('Payment under processing!', 'better-payment');
284 }
285 return false;
286 }
287
288 /**
289 * Stripe payment success
290 *
291 * @since 0.0.1
292 */
293 public static function stripe_payment_success( $settings = [] ) {
294
295 $data = $_REQUEST;
296
297 if ( !empty( $data[ 'better_payment_stripe_id' ] ) ) {
298 global $wpdb;
299 $table = "{$wpdb->prefix}better_payment";
300 $results = $wpdb->get_row(
301 $wpdb->prepare( "SELECT id, obj_id, amount, transaction_id, currency, form_fields_info, referer FROM $table WHERE order_id=%s and status = 'unpaid' limit 1", sanitize_text_field( $data[ 'better_payment_stripe_id' ] ) )
302 );
303
304 if ( !empty( $results->obj_id ) && !empty( $settings[ 'better_payment_stripe_secret_key' ] ) ) {
305 $header = array(
306 'Authorization' => 'Basic ' . base64_encode( sanitize_text_field( $settings[ 'better_payment_stripe_secret_key' ] ) . ':' ),
307 'Stripe-Version' => '2019-05-16',
308 );
309
310 $request = [
311 'expand' => [
312 'subscription.latest_invoice.payment_intent',
313 'payment_intent'
314 ]
315 ];
316 $form_fields_info = maybe_unserialize($results->form_fields_info);
317 $is_payment_recurring = ! empty( $form_fields_info['mode'] ) && 'subscription' === $form_fields_info['mode'];
318 $is_payment_split_payment = ( $is_payment_recurring ) && ( ! empty( $form_fields_info['is_payment_split_payment'] ) && 1 === intval( $form_fields_info['is_payment_split_payment'] ) );
319
320 $action_data = [
321 'form_fields_info' => $form_fields_info,
322 'is_payment_recurring' => $is_payment_recurring,
323 'is_payment_split_payment' => $is_payment_split_payment,
324 'checkout_session_id' => $results->obj_id,
325 ];
326
327 $response = wp_safe_remote_post(
328 'https://api.stripe.com/v1/checkout/sessions/' . $results->obj_id,
329 array(
330 'method' => 'GET',
331 'headers' => $header,
332 'timeout' => 70,
333 'body' => $request
334 )
335 );
336
337 if ( is_wp_error( $response ) || empty( $response[ 'body' ] ) ) {
338 return new \WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'better-payment' ) );
339 }
340
341 $response = json_decode( $response[ 'body' ] );
342 $transaction_id = ! empty( $results->transaction_id ) ? sanitize_text_field( $results->transaction_id ) : '';
343
344 if ( $is_payment_recurring && ! empty( $response->subscription->id ) ) {
345 $transaction_id = sanitize_text_field( $response->subscription->id );
346 $subscription_obj = $response->subscription;
347 $form_fields_info['subscription_id'] = sanitize_text_field( $transaction_id );
348 $form_fields_info['subscription_customer_id'] = ! empty( $response->customer ) ? sanitize_text_field( $response->customer ) : '';
349 $form_fields_info['subscription_plan_id'] = ! empty( $subscription_obj->items->data[0]->plan->id ) ? sanitize_text_field( $subscription_obj->items->data[0]->plan->id ) : '';
350 $form_fields_info['subscription_interval'] = ! empty( $subscription_obj->items->data[0]->plan->interval_count ) ? intval( $subscription_obj->items->data[0]->plan->interval_count ) : '';
351 $form_fields_info['subscription_interval'] .= ! empty( $subscription_obj->items->data[0]->plan->interval ) ? ' ' . sanitize_text_field( $subscription_obj->items->data[0]->plan->interval ) : $form_fields_info['subscription_interval'];
352 $form_fields_info['subscription_current_period_start'] = ! empty( $subscription_obj->current_period_start ) ? intval( $subscription_obj->current_period_start ) : 0;
353 $form_fields_info['subscription_current_period_end'] = ! empty( $subscription_obj->current_period_end ) ? intval( $subscription_obj->current_period_end ) : 0;
354 $form_fields_info['subscription_status'] = sanitize_text_field( $response->status );
355 $form_fields_info['subscription_created_date'] = sanitize_text_field( $subscription_obj->created );
356 }
357
358 if ( isset( $response->error->message ) ) {
359 return new \WP_Error( 'stripe_error', __( 'There was a problem connecting to the Stripe API endpoint.', 'better-payment' ) );
360 }
361
362 $customer_email = $is_payment_recurring && ( ! empty( $response->customer_email ) ) ? sanitize_email( $response->customer_email ) : '';
363 $customer_email_optional = '';
364 if (
365 isset( $response->payment_intent ) &&
366 isset( $response->payment_intent->charges ) &&
367 isset( $response->payment_intent->charges->data ) &&
368 ! empty( $response->payment_intent->charges->data )
369 ) {
370 $charge = current( $response->payment_intent->charges->data );
371
372 if (
373 isset( $charge->billing_details ) &&
374 isset( $charge->billing_details->email ) &&
375 ! empty( $charge->billing_details->email )
376 ) {
377 $customer_email_optional = sanitize_email( $charge->billing_details->email );
378 }
379 }
380
381 $form_fields_info['is_coupon_applied'] = 0;
382 $exact_paid_amount = ! empty( $response->amount_total ) ? floatval( $response->amount_total ) : $results->amount * 100;
383 $exact_paid_amount = $exact_paid_amount / 100;
384 $form_fields_info['exact_paid_amount'] = $exact_paid_amount;
385 if( (int)$exact_paid_amount != (int)$results->amount ) {
386 $form_fields_info['paid_amount_diff'] = $results->amount - $exact_paid_amount;
387 $form_fields_info['is_coupon_applied'] = 1;
388 }
389
390 $updated = $wpdb->update(
391 $table,
392 array(
393 'amount' => $exact_paid_amount,
394 'status' => sanitize_text_field( $response->payment_status ),
395 'email' => $is_payment_recurring ? $customer_email : $customer_email_optional,
396 'customer_info' => maybe_serialize( $response ),
397 'form_fields_info' => maybe_serialize( $form_fields_info ),
398 'transaction_id' => $transaction_id,
399 ),
400 array( 'ID' => $results->id )
401 );
402
403 do_action('better_payment/stripe_payment/success', $action_data);
404 do_action( 'better_payment/payment_confirmed', (int) $results->id );
405
406 $frontend_data = [
407 'amount' => $exact_paid_amount,
408 'email' => $is_payment_recurring ? $customer_email : $customer_email_optional,
409 'transaction_id' => $transaction_id,
410 'currency' => ! empty( $results->currency ) ? $results->currency : __( 'USD', 'better-payment' ),
411 'method' => 'stripe',
412 'is_payment_recurring' => $is_payment_recurring,
413 'is_payment_split_payment' => $is_payment_split_payment,
414 'is_payment_mixed' => ! empty( $form_fields_info['is_payment_mixed'] ) ? intval( $form_fields_info['is_payment_mixed'] ) : 0,
415 'mixed_payment_selected_type' => ! empty( $form_fields_info['mixed_payment_selected_type'] ) ? sanitize_text_field( $form_fields_info['mixed_payment_selected_type'] ) : '',
416 ];
417
418 if ( $is_payment_split_payment ) {
419 $total_amount = ! empty( $form_fields_info['split_payment_total_amount'] )
420 ? sanitize_text_field( $form_fields_info['split_payment_total_amount'] )
421 : 0;
422 $total_installment = ! empty( $form_fields_info['split_payment_installment_iteration'] )
423 ? sanitize_text_field( $form_fields_info['split_payment_installment_iteration'] )
424 : 1;
425
426 // $frontend_data['amount'] = floatval( $total_amount / $total_installment );
427 $frontend_data['total_amount'] = $total_amount;
428 }
429
430 if ( false !== $updated ) {
431 //Send email notification
432 $better_customer_email = $is_payment_recurring ? $customer_email : $customer_email_optional;
433
434 if (
435 (isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' )
436 || ( $results->referer === 'elementor-form' )
437 ) {
438 $is_elementor_form = ! empty( $results->referer ) && $results->referer === 'elementor-form' ? 1 : 0;
439 self::better_email_notification($transaction_id, $better_customer_email, $settings, 'Stripe', $results->form_fields_info, $is_elementor_form);
440 }
441
442 return $frontend_data;
443 }
444 }
445 }
446 return false;
447 }
448
449 /**
450 * Paystack payment success
451 *
452 * @since 0.0.1
453 */
454 public static function paystack_payment_success( $settings = [] ) {
455 $data = $_REQUEST;
456
457 if ( ! empty( $data[ 'better_payment_paystack_id' ] ) ) {
458 global $wpdb;
459 $table = "{$wpdb->prefix}better_payment";
460 $results = $wpdb->get_row(
461 $wpdb->prepare( "SELECT id,obj_id,transaction_id,form_fields_info,referer FROM $table WHERE order_id=%s and status = 'unpaid' limit 1", sanitize_text_field( $data[ 'better_payment_paystack_id' ] ) )
462 );
463
464 $header_info = array(
465 'Authorization' => 'Bearer ' . sanitize_text_field( $settings[ 'better_payment_paystack_secret_key' ] ),
466 "Cache-Control: no-cache",
467 );
468
469 $response = wp_safe_remote_get(
470 'https://api.paystack.co/transaction/verify/'. sanitize_text_field( $data[ 'reference' ] ),
471 array(
472 'headers' => $header_info,
473 'timeout' => 70,
474 )
475 );
476
477 $response = json_decode(wp_remote_retrieve_body($response));
478
479 if ( ! empty( $response->status ) ) {
480 $updated = $wpdb->update(
481 $table,
482 array(
483 'status' => ! empty( $response->data->status ) ? sanitize_text_field( $response->data->status ) : '',
484 'amount' => ! empty( $response->data->amount ) ? floatval( ( $response->data->amount ) / 100 ) : 0,
485 'obj_id' => ! empty( $response->data->id ) ? sanitize_text_field( $response->data->id ) : '',
486 'transaction_id' => ! empty( $response->data->reference ) ? sanitize_text_field( $response->data->reference ) : '',
487 'customer_info' => ! empty( $response->data->customer ) ? maybe_serialize( $response->data->customer ) : '',
488 'email' => ! empty( $response->data->customer->email ) ? sanitize_email( $response->data->customer->email ) : '',
489 ),
490 array( 'ID' => $results->id )
491 );
492 do_action( 'better_payment/payment_confirmed', (int) $results->id );
493 }
494
495 $better_customer_email = ! empty( $response->data->customer->email ) ? maybe_serialize( $response->data->customer->email ) : '';
496 $transaction_id = ! empty( $response->data->reference ) ? sanitize_text_field( $response->data->reference ) : '';
497
498 $frontend_data = [
499 'amount' => ! empty( $response->data->amount ) ? floatval( ( $response->data->amount ) / 100 ) : 0,
500 'email' => ! empty( $better_customer_email ) ? $better_customer_email : '',
501 'transaction_id' => $transaction_id,
502 'currency' => ! empty( $response->data->currency ) ? sanitize_text_field( $response->data->currency ) : __( 'USD', 'better-payment' ),
503 'method' => 'paystack',
504 ];
505
506 if ( ! empty( $updated ) && $better_customer_email ) {
507 //Send email notification
508 if (
509 (isset($settings[ 'better_payment_form_email_enable' ]) && $settings[ 'better_payment_form_email_enable' ] == 'yes' )
510 || ( $results->referer === 'elementor-form' )
511 ) {
512 $is_elementor_form = ! empty( $results->referer ) && $results->referer === 'elementor-form' ? 1 : 0;
513 self::better_email_notification($transaction_id, $better_customer_email, $settings, 'Paystack', $results->form_fields_info, $is_elementor_form);
514 }
515
516 do_action( 'better_payment/payment/success', sanitize_text_field( $data['better_payment_paystack_id'] ?? '' ), (int) $results->id, 'paystack' );
517
518 return $frontend_data;
519 }
520 }
521 return false;
522 }
523
524 /**
525 * Success message template
526 *
527 * @since 0.0.1
528 */
529 public static function success_message_template( $settings = [], $tr_id = '' ) {
530 if ( empty( $tr_id ) || is_wp_error($tr_id)) {
531 return false;
532 }
533 wp_enqueue_script('better-payment-admin-script');
534 $image_url = BETTER_PAYMENT_ASSETS . '/img/success.svg';
535 $show_icon = 0;
536 $default_icon = 1;
537 $helper_obj = new Helper();
538
539 $store_name = ( isset( $settings['better_payment_form_payment_source'] ) && $settings['better_payment_form_payment_source'] === 'manual' && !empty( $settings['better_payment_form_title'] ) )
540 ? esc_html($settings['better_payment_form_title'])
541 : esc_html( get_bloginfo('name') );
542
543 $payment_desc_text = !empty( $settings['better_payment_form_success_message_heading'] )
544 ? esc_html($settings['better_payment_form_success_message_heading'])
545 : esc_html( __('You paid', 'better-payment') . ' [currency_symbol][amount] ' . __('to', 'better-payment') . ' [store_name]');
546
547 $bp__currency_symbol = esc_html( ! empty( $tr_id['currency'] ) ? $helper_obj->get_currency_symbol( $tr_id['currency'] ) : '' );
548
549 $payment_desc_text = str_replace( '[currency_symbol]', '<span class="bp-bold">' . $bp__currency_symbol . '</span>', $payment_desc_text );
550
551 $payment_desc_text = str_replace( '[amount]', '<span class="bp-bold">' . esc_html( ! empty( $tr_id['amount'] ) ? $tr_id['amount'] : 0 ) . '</span>', $payment_desc_text );
552
553 $payment_desc_text = str_replace( '[store_name]', '<span class="bp-bold">' . esc_html( $store_name ) . '</span>', $payment_desc_text );
554
555 $payment_mail_text = !empty( $settings['better_payment_form_success_message_sub_heading'] ) ? esc_html($settings['better_payment_form_success_message_sub_heading']) : esc_html( __('Payment Confirmation email will be sent to ', 'better-payment') . '[customer_email]');
556
557 $payment_mail_text = str_replace( '[customer_email]', '<span class="bp-bold">' . esc_html( ! empty( $tr_id['email'] ) ? $tr_id['email'] : '' ) . '</span>', $payment_mail_text );
558
559 if ( !empty( $settings[ 'better_payment_form_success_message_icon' ][ 'library' ] ) ) {
560 if ( $settings[ 'better_payment_form_success_message_icon' ][ 'library' ] == 'svg' ) {
561 $image_url = $settings[ 'better_payment_form_success_message_icon' ][ 'value' ][ 'url' ];
562 $default_icon = 0;
563 } else {
564 $show_icon = 1;
565 $image_url = $settings[ 'better_payment_form_success_message_icon' ][ 'value' ];
566 $default_icon = 0;
567 }
568 }
569
570
571 $allowed_payment_methods = [
572 'paypal' => BETTER_PAYMENT_ASSETS . '/img/paypal-2.svg',
573 'stripe' => BETTER_PAYMENT_ASSETS . '/img/stripe-2.svg',
574 'paystack' => BETTER_PAYMENT_ASSETS . '/img/paystack-2.svg',
575 ];
576 $payment_method_logo = isset( $tr_id['method'] ) && isset( $allowed_payment_methods[ $tr_id['method'] ] ) ? $allowed_payment_methods[ $tr_id['method'] ] : '';
577
578 $better_payment_form_success_message_thanks = !empty( $settings['better_payment_form_success_message_thanks'] )
579 ? esc_html( $settings['better_payment_form_success_message_thanks'] )
580 : esc_html__('Thank You!', 'better-payment');
581 $better_payment_form_success_message_transaction = !empty( $settings['better_payment_form_success_message_transaction'] )
582 ? esc_html__( $settings['better_payment_form_success_message_transaction'], 'better-payment' )
583 : esc_html__('Transaction ID', 'better-payment');
584 $better_payment_form_success_message_amount_text = !empty( $settings['better_payment_form_success_message_amount_text'] )
585 ? esc_html( $settings['better_payment_form_success_message_amount_text'] )
586 : esc_html__( 'Amount', 'better-payment' );
587 $better_payment_form_success_message_currency_text = !empty( $settings['better_payment_form_success_message_currency_text'] )
588 ? esc_html( $settings['better_payment_form_success_message_currency_text'] )
589 : esc_html__( 'Currency', 'better-payment' );
590 $better_payment_form_success_message_pay_method_text = !empty( $settings['better_payment_form_success_message_pay_method_text'] ) ? esc_html( $settings['better_payment_form_success_message_pay_method_text'] ) : esc_html__( 'Payment Method', 'better-payment' );
591 $better_payment_form_success_message_pay_type_text = !empty( $settings['better_payment_form_success_message_pay_type_text'] )
592 ? esc_html( $settings['better_payment_form_success_message_pay_type_text'] )
593 : esc_html__( 'Payment Type', 'better-payment' );
594 $better_payment_form_payment_type = !empty( $settings['better_payment_form_payment_type'] )
595 ? esc_html( $settings['better_payment_form_payment_type'] )
596 : '';
597 if ( ! empty( $better_payment_form_payment_type ) ) {
598 if ( 'one-time' === $better_payment_form_payment_type ) {
599 $better_payment_form_payment_type_value = esc_html__( 'One Time Payment', 'better-payment' );
600 } elseif ( 'recurring' === $better_payment_form_payment_type ) {
601 $better_payment_form_payment_type_value = esc_html__( 'Recurring Payment', 'better-payment' );
602 } elseif ( 'mixed' === $better_payment_form_payment_type ) {
603 $mixed_payment_selected_type = ! empty( $tr_id['mixed_payment_selected_type'] ) ? sanitize_text_field( $tr_id['mixed_payment_selected_type'] ) : '';
604 $is_mixed_recurring = 'recurring' === $mixed_payment_selected_type;
605
606 if ( empty( $mixed_payment_selected_type ) ) {
607 $is_mixed_recurring = ! empty( $tr_id['is_payment_recurring'] ) && empty( $tr_id['is_payment_split_payment'] );
608 }
609
610 $better_payment_form_payment_type_value = $is_mixed_recurring
611 ? esc_html__( 'Recurring Payment', 'better-payment' )
612 : esc_html__( 'One Time Payment', 'better-payment' );
613 } else {
614 $better_payment_form_payment_type_value = esc_html__( 'Split Payment', 'better-payment' );
615 }
616 }
617 $better_payment_form_success_message_merchant_details_text = !empty( $settings['better_payment_form_success_message_merchant_details_text'] )
618 ? esc_html( $settings['better_payment_form_success_message_merchant_details_text'] )
619 : esc_html__( 'Merchant Details', 'better-payment' );
620 $better_payment_form_success_message_merchant_details_value = isset( $settings['better_payment_form_payment_source'] ) && $settings['better_payment_form_payment_source'] === 'manual' && ! empty( $settings['better_payment_form_title'] )
621 ? esc_html($settings['better_payment_form_title'])
622 : esc_html( get_bloginfo( 'name' ) );
623 $better_payment_form_success_message_paid_amount_text = !empty( $settings['better_payment_form_success_message_paid_amount_text'] )
624 ? esc_html( $settings['better_payment_form_success_message_paid_amount_text'] )
625 : esc_html__( 'Paid Amount', 'better-payment' );
626 $better_payment_form_success_message_purchase_details_text = !empty( $settings['better_payment_form_success_message_purchase_details_text'] )
627 ? esc_html( $settings['better_payment_form_success_message_purchase_details_text'] )
628 : esc_html__( 'Purchase Details', 'better-payment' );
629 $better_payment_form_success_message_print_text = !empty( $settings['better_payment_form_success_message_print_text'] )
630 ? esc_html( $settings['better_payment_form_success_message_print_text'] )
631 : esc_html__( 'Print', 'better-payment' );
632 $better_payment_form_success_message_view_details_btn_text = !empty( $settings['better_payment_form_success_message_view_details_btn_text'] )
633 ? esc_html( $settings['better_payment_form_success_message_view_details_btn_text'] )
634 : esc_html__( 'View Details', 'better-payment' );
635 $better_payment_form_success_page_view_details_url = !empty( $settings['better_payment_form_success_page_view_details_url']['url'] ) ? esc_url( $settings['better_payment_form_success_page_view_details_url']['url'] ) : 'javascript:void(0)';
636 ?>
637 <section class="bp-thank_page">
638 <div class="bp-thank_page-wrapper">
639 <div class="bp-thank_page-logo">
640 <?php if( $default_icon ): ?>
641 <span class="bp-thank_page-logo_wrapper">
642 <img src="<?php echo esc_url( BETTER_PAYMENT_ASSETS . '/img/success-2.svg' ); ?>" alt="Better Payment logo">
643 </span>
644 <?php endif; ?>
645 <?php if( ! $default_icon ): ?>
646 <?php if( $show_icon ): ?>
647 <?php
648 // Add 'pf-block' class if this is a Gutenberg block (not Elementor)
649 $success_wrapper_class = 'bp-thank_page-custom-logo_wrapper-success';
650 if ( ! empty( $settings['better_payment_form_source'] ) && 'block' === $settings['better_payment_form_source'] ) {
651 $success_wrapper_class .= ' pf-block';
652 }
653 ?>
654 <div class="<?php echo esc_attr( $success_wrapper_class ); ?>">
655 <?php
656 // Render icon safely (handles FontAwesome, Dashicons, SVG with or without Elementor)
657 if (!empty($settings['better_payment_form_success_message_icon'])) {
658 self::render_icon($settings['better_payment_form_success_message_icon'], ['aria-hidden' => 'true']);
659 } else {
660 // Fallback to default icons
661 echo '<i class="' . esc_attr($image_url) . '"></i>';
662 }
663 ?>
664 </div>
665 <?php endif; ?>
666 <?php if( ! $show_icon ): ?>
667 <span class="bp-thank_page-logo_wrapper">
668 <img src="<?php echo esc_url($image_url); ?>" alt="Success logo">
669 </span>
670 <?php endif; ?>
671 <?php endif; ?>
672 </div>
673 <div class="bp-thank_page-text">
674 <h2 class="bp-font_ibm bp-page_header">
675 <?php echo wp_kses_post( $better_payment_form_success_message_thanks ); ?>
676 <span> &#127881;</span>
677 </h2>
678 <p class="bp-font_ibm bp-reason_for-text">
679 <?php echo wp_kses_post( $payment_desc_text ); ?>
680 </p>
681 <?php if (isset( $settings['better_payment_form_email_enable'] ) && !empty( $tr_id['email'] )): ?>
682 <p class="bp-font_ibm bp-payment_info">
683 <?php echo wp_kses_post( $payment_mail_text ); ?>
684 </p>
685 <?php endif; ?>
686
687 <div class="bp-flex bp-transaction_info-wrapper">
688 <p class="bp-flex bp-font_ibm bp-transaction_info"> <span class="line-height-0">
689 <img src="<?php echo esc_url( BETTER_PAYMENT_ASSETS . '/img/wallet.svg' ); ?>" alt="Better Payment wallet">
690 </span>
691 <span>
692 <?php echo wp_kses_post( $better_payment_form_success_message_transaction ); ?>:
693 </span>
694 <span class="bp-bold bp-transaction_id"><?php echo esc_html( ! empty( $tr_id['transaction_id']) ? $tr_id['transaction_id'] : '' ); ?></span>
695 </p>
696
697 <button class="bp-transaction_data-copy_btn ">
698 <svg width="20" height="20" viewBox="0 0 20 20"
699 fill="none" xmlns="http://www.w3.org/2000/svg">
700 <path
701 d="M15.0002 15.601C16.3257 15.601 17.4002 14.5265 17.4002 13.201V8.40098C17.4002 5.38399 17.4002 3.87549 16.463 2.93823C15.5257 2.00098 14.0172 2.00098 11.0002 2.00098H7.80024C6.47476 2.00098 5.40024 3.07549 5.40024 4.40098M10.2002 18.001H7.80024C5.5375 18.001 4.40613 18.001 3.70319 17.298C3.00024 16.5951 3.00024 15.4637 3.00024 13.201V9.20098C3.00024 6.93823 3.00024 5.80686 3.70319 5.10392C4.40613 4.40098 5.5375 4.40098 7.80024 4.40098H10.2002C12.463 4.40098 13.5944 4.40098 14.2973 5.10392C15.0002 5.80686 15.0002 6.93824 15.0002 9.20098V13.201C15.0002 15.4637 15.0002 16.5951 14.2973 17.298C13.5944 18.001 12.463 18.001 10.2002 18.001Z"
702 stroke-width="1.152" />
703 </svg>
704 </button>
705 </div>
706 </div>
707
708 <div class="bp-thank_page-info">
709 <ul class="bp-page_info-list">
710 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
711 <span class="bp-info_content">
712 <?php
713 echo wp_kses_post( $better_payment_form_success_message_amount_text );
714 ?>
715 </span>
716 <span class="bp-info_content bp-bold"><?php echo $bp__currency_symbol . esc_html( ! empty( $tr_id['amount'] ) ? $tr_id['amount'] : 0 ); ?></span>
717 </li>
718 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
719 <span class=" bp-info_content">
720 <?php
721 echo wp_kses_post( $better_payment_form_success_message_currency_text );
722 ?>
723 </span>
724 <span class="bp-info_content bp-bold"><?php echo esc_html( ! empty( $tr_id['currency'] ) ? $tr_id['currency'] : '' ); ?></span>
725 </li>
726 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
727 <span class="bp-info_content">
728 <?php
729 echo wp_kses_post( $better_payment_form_success_message_pay_method_text );
730 ?>
731 </span>
732 <div class="bp-payment_method-logo-wrapper">
733 <?php if ( !empty( $payment_method_logo ) ) : ?>
734 <img src="<?php echo esc_url( $payment_method_logo ); ?>" alt="<?php echo esc_attr( $tr_id['method'] ); ?>" class="bp-payment_method-logo">
735 <?php endif; ?>
736 </div>
737 </li>
738 <?php if( !empty( $better_payment_form_payment_type ) ): ?>
739 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
740 <span class="bp-info_content">
741 <?php
742 echo wp_kses_post( $better_payment_form_success_message_pay_type_text );
743 ?>
744 </span>
745 <span class="bp-info_content bp-bold"><?php echo wp_kses_post( $better_payment_form_payment_type_value ); ?></span>
746 </li>
747 <?php endif; ?>
748 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
749 <span class="bp-info_content">
750 <?php
751 echo wp_kses_post( $better_payment_form_success_message_merchant_details_text );
752 ?>
753 </span>
754 <span class="bp-info_content bp-bold">
755 <?php echo wp_kses_post( $better_payment_form_success_message_merchant_details_value ); ?>
756 </span>
757 </li>
758 <?php if( isset( $tr_id['is_payment_split_payment'] ) && $tr_id['is_payment_split_payment'] ): ?>
759 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
760 <span class="bp-info_content">
761 <?php
762 echo wp_kses_post( $better_payment_form_success_message_paid_amount_text );
763 ?>
764 </span>
765 <span class="bp-info_content bp-bold">
766 <?php echo $bp__currency_symbol . esc_html($tr_id['amount']); ?> out of <?php echo $bp__currency_symbol . esc_html($tr_id['total_amount']); ?>
767 </span>
768 </li>
769 <?php endif; ?>
770 <?php
771 $has_woo_products = !empty($settings['better_payment_form_woocommerce_product_id']) || !empty($settings['better_payment_form_woocommerce_product_ids']);
772 $has_fluentcart_products = !empty($settings['better_payment_form_fluentcart_product_id']) || !empty($settings['better_payment_form_fluentcart_product_ids']);
773
774 if( $has_woo_products || $has_fluentcart_products ):
775 ?>
776 <li class="bp-flex bp-font_ibm bp-page_info-list_item">
777 <span class="bp-info_content">
778 <?php
779 echo wp_kses_post( $better_payment_form_success_message_purchase_details_text );
780 ?>
781 </span>
782 <?php
783 $product_names = [];
784
785 if( !empty( $settings['better_payment_form_woocommerce_product_id'] ) ):
786 $product_names[] = get_the_title( $settings['better_payment_form_woocommerce_product_id'] );
787 endif;
788
789 if( !empty( $settings['better_payment_form_woocommerce_product_ids'] ) ):
790 $product_ids = $settings['better_payment_form_woocommerce_product_ids'];
791 foreach( $product_ids as $product_id ):
792 $product_names[] = get_the_title( $product_id );
793 endforeach;
794 endif;
795
796 if( !empty( $settings['better_payment_form_fluentcart_product_id'] ) && function_exists('fluentCart') && class_exists( '\FluentCart\App\Models\Product' ) ):
797 try {
798 $fluentcart_product = \FluentCart\App\Models\Product::query()->find($settings['better_payment_form_fluentcart_product_id']);
799 if ($fluentcart_product) {
800 $product_names[] = sanitize_text_field( $fluentcart_product->post_title );
801 }
802 } catch ( \Exception $e ) {
803 //
804 }
805 endif;
806
807 if( !empty( $settings['better_payment_form_fluentcart_product_ids'] ) && function_exists('fluentCart') && class_exists( '\FluentCart\App\Models\Product' ) ):
808 $product_ids = $settings['better_payment_form_fluentcart_product_ids'];
809 foreach( $product_ids as $product_id ):
810 try {
811 $fluentcart_product = \FluentCart\App\Models\Product::query()->find($product_id);
812 if ($fluentcart_product) {
813 $product_names[] = sanitize_text_field( $fluentcart_product->post_title );
814 }
815 } catch ( \Exception $e ) {
816 //
817 }
818 endforeach;
819 endif;
820
821 if( !empty($product_names) ):
822 echo '<span class="bp-info_content bp-bold">' . implode( ', ', $product_names ) . '</span>';
823 endif;
824 ?>
825 </li>
826 <?php endif; ?>
827 </ul>
828 </div>
829
830 <div class="bp-flex bp-button_group">
831 <button class="bp-flex bp-font_ibm bp-print_btn">
832 <span style="line-height: 0;">
833 <img src="<?php echo esc_url( BETTER_PAYMENT_ASSETS . '/img/print.svg' ); ?>" alt="Better Payment print">
834 </span>
835 <span class="bp-font_ibm">
836 <?php echo wp_kses_post( $better_payment_form_success_message_print_text ); ?>
837 </span>
838 </button>
839
840 <div class="bp-flex bp-btn_wrapper">
841 <a href="<?php echo $better_payment_form_success_page_view_details_url; ?>" target="_blank" class="bp-font_ibm bp-details_btn">
842 <?php echo wp_kses_post( $better_payment_form_success_message_view_details_btn_text ); ?>
843 </a>
844 </div>
845 </div>
846 </div>
847 </section>
848 <?php
849 }
850
851 /**
852 * Error message template
853 *
854 * @since 0.0.1
855 */
856 public static function failed_message_template( $settings = [], $transaction_data = false ) {
857
858 $image_url = BETTER_PAYMENT_ASSETS . '/img/fail.svg';
859 $show_icon = 0;
860 $default_icon = 1;
861 $failed_heading = !empty( $settings['better_payment_form_error_message_heading'] ) ? esc_html( $settings['better_payment_form_error_message_heading'] ) : esc_html__( 'Payment Failed!', 'better-payment' );
862 $failed_sub_heading = !empty( $settings['better_payment_form_error_message_sub_heading'] ) ? esc_html( $settings['better_payment_form_error_message_sub_heading'] ) : esc_html__( 'Your payment has failed. Please check your payment details', 'better-payment' );
863 $transaction_id_text = !empty( $settings['better_payment_form_error_message_transaction_id_text'] ) ? esc_html( $settings['better_payment_form_error_message_transaction_id_text'] ) : esc_html__( 'Transaction ID', 'better-payment' );
864 $show_details_button = !empty( $settings['better_payment_form_error_details_button_switch'] ) && $settings['better_payment_form_error_details_button_switch'] == 'yes' ? true : false;
865 $details_button_text = !empty( $settings['better_payment_form_error_details_button_text'] ) ? esc_html( $settings['better_payment_form_error_details_button_text'] ) : esc_html__( 'View Details', 'better-payment' );
866 $better_payment_form_error_details_page_url = !empty( $settings['better_payment_form_error_details_page_url']['url'] ) ? esc_url( $settings['better_payment_form_error_details_page_url']['url'] ) : 'javascript:void(0)';
867 $store_name = ( isset( $settings['better_payment_form_payment_source'] ) && $settings['better_payment_form_payment_source'] === 'manual' && !empty( $settings['better_payment_form_title'] ) )
868 ? esc_html($settings['better_payment_form_title'])
869 : esc_html( get_bloginfo('name') );
870
871 // Get transaction details
872 $transaction_amount = '';
873 $transaction_id = '';
874 $currency_symbol = '';
875
876 if ( !empty( $transaction_data ) ) {
877 $transaction_amount = !empty( $transaction_data['amount'] ) ? floatval( $transaction_data['amount'] ) : '';
878 $currency_symbol = !empty( $transaction_data['currency_symbol'] ) ? esc_html( $transaction_data['currency_symbol'] ) : '';
879 $transaction_id = !empty( $transaction_data['transaction_id'] ) ? esc_html( $transaction_data['transaction_id'] ) : '';
880 }
881
882 if ( !empty( $settings[ 'better_payment_form_error_message_icon' ][ 'library' ] ) ) {
883 if ( $settings[ 'better_payment_form_error_message_icon' ][ 'library' ] == 'svg' ) {
884 $image_url = $settings[ 'better_payment_form_error_message_icon' ][ 'value' ][ 'url' ];
885 $default_icon = 0;
886 } else {
887 $show_icon = 1;
888 $image_url = $settings[ 'better_payment_form_error_message_icon' ][ 'value' ];
889 $default_icon = 0;
890 }
891 }
892 // dd($settings[ 'better_payment_form_error_message_icon' ]);
893 ?>
894 <section class="payment-failed-screen-section">
895 <div class="bp-thank_page-wrapper">
896 <div class="bp-thank_page-logo">
897 <?php if( $default_icon ): ?>
898 <span class="bp-thank_page-logo_wrapper">
899 <svg width="58" height="58" viewBox="0 0 58 58" fill="none" xmlns="http://www.w3.org/2000/svg">
900 <path d="M40.804 10.7998H16.8039C13.9409 10.8041 11.1964 11.9434 9.17192 13.9678C7.14746 15.9923 6.00822 18.7368 6.00391 21.5998H51.604C51.5997 18.7368 50.4604 15.9923 48.436 13.9678C46.4115 11.9434 43.667 10.8041 40.804 10.7998ZM6.00391 26.3998V35.9998C6.00822 38.8628 7.14746 41.6073 9.17192 43.6318C11.1964 45.6562 13.9409 46.7955 16.8039 46.7998H40.804C43.667 46.7955 46.4115 45.6562 48.436 43.6318C50.4604 41.6073 51.5997 38.8628 51.604 35.9998V26.3998H6.00391ZM24.0039 38.3998H16.8039C16.1674 38.3998 15.557 38.1469 15.1069 37.6968C14.6568 37.2468 14.4039 36.6363 14.4039 35.9998C14.4039 35.3633 14.6568 34.7529 15.1069 34.3028C15.557 33.8527 16.1674 33.5998 16.8039 33.5998H24.0039C24.6404 33.5998 25.2509 33.8527 25.7009 34.3028C26.151 34.7529 26.4039 35.3633 26.4039 35.9998C26.4039 36.6363 26.151 37.2468 25.7009 37.6968C25.2509 38.1469 24.6404 38.3998 24.0039 38.3998Z" fill="#F44336"></path>
901 <circle cx="45.5" cy="41.5" r="6.5" fill="white"></circle>
902 <foreignObject x="21.4686" y="17.3701" width="47.2066" height="47.3399">
903 <div xmlns="http://www.w3.org/1999/xhtml" style="backdrop-filter:blur(6.36px);clip-path:url(#bgblur_0_3595_8284_clip_path);height:100%;width:100%">
904 </div>
905 </foreignObject>
906 <g filter="url(#filter0_d_3595_8284)" data-figma-bg-blur-radius="12.71">
907 <path d="M55.765 38.782C55.3067 36.6386 54.2191 34.6825 52.6429 33.1664C50.6276 31.1788 47.9133 30.0699 45.0893 30.0804C42.1969 30.0848 39.4243 31.2411 37.3791 33.2958C35.334 35.3505 34.183 38.136 34.1786 41.0417V41.8849C34.2614 43.0459 34.5336 44.1853 34.9843 45.2576C36.0299 47.7766 37.9733 49.8131 40.4344 50.9688C42.8955 52.1245 45.6972 52.3162 48.2915 51.5064C50.8859 50.6967 53.0862 48.9437 54.4622 46.5904C55.8381 44.2371 56.2907 41.4528 55.7314 38.782H55.765ZM46.4154 44.7686L45.0893 43.4364L43.7632 44.7686C43.6072 44.9266 43.4215 45.0521 43.217 45.1377C43.0124 45.2233 42.793 45.2674 42.5714 45.2674C42.3498 45.2674 42.1304 45.2233 41.9259 45.1377C41.7213 45.0521 41.5357 44.9266 41.3796 44.7686C41.2223 44.6118 41.0974 44.4253 41.0122 44.2198C40.927 44.0143 40.8831 43.7939 40.8831 43.5713C40.8831 43.3486 40.927 43.1282 41.0122 42.9227C41.0974 42.7172 41.2223 42.5307 41.3796 42.374L41.8664 41.8849L42.7057 41.0417L41.3796 39.7095C41.0636 39.3919 40.886 38.9613 40.886 38.5122C40.886 38.0631 41.0636 37.6324 41.3796 37.3149C41.6957 36.9973 42.1244 36.8189 42.5714 36.8189C43.0184 36.8189 43.4471 36.9973 43.7632 37.3149L45.0893 38.6471L46.4154 37.3149C46.7314 36.9973 47.1601 36.8189 47.6071 36.8189C48.0541 36.8189 48.4828 36.9973 48.7989 37.3149C49.115 37.6324 49.2926 38.0631 49.2926 38.5122C49.2926 38.9613 49.115 39.3919 48.7989 39.7095L47.4729 41.0417L48.2618 41.8343L48.7989 42.374C48.9563 42.5307 49.0811 42.7172 49.1664 42.9227C49.2516 43.1282 49.2954 43.3486 49.2954 43.5713C49.2954 43.7939 49.2516 44.0143 49.1664 44.2198C49.0811 44.4253 48.9563 44.6118 48.7989 44.7686C48.6429 44.9266 48.4572 45.0521 48.2527 45.1377C48.0481 45.2233 47.8287 45.2674 47.6071 45.2674C47.3855 45.2674 47.1661 45.2233 46.9616 45.1377C46.7571 45.0521 46.5714 44.9266 46.4154 44.7686Z" fill="#F44336" fill-opacity="0.5" shape-rendering="crispEdges"></path>
908 </g>
909 <defs>
910 <filter id="filter0_d_3595_8284" x="21.4686" y="17.3701" width="47.2066" height="47.3399" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
911 <feFlood flood-opacity="0" result="BackgroundImageFix"></feFlood>
912 <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"></feColorMatrix>
913 <feOffset dx="-4"></feOffset>
914 <feGaussianBlur stdDeviation="2"></feGaussianBlur>
915 <feComposite in2="hardAlpha" operator="out"></feComposite>
916 <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0"></feColorMatrix>
917 <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_3595_8284"></feBlend>
918 <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_3595_8284" result="shape"></feBlend>
919 </filter>
920 <clipPath id="bgblur_0_3595_8284_clip_path" transform="translate(-21.4686 -17.3701)">
921 <path d="M55.765 38.782C55.3067 36.6386 54.2191 34.6825 52.6429 33.1664C50.6276 31.1788 47.9133 30.0699 45.0893 30.0804C42.1969 30.0848 39.4243 31.2411 37.3791 33.2958C35.334 35.3505 34.183 38.136 34.1786 41.0417V41.8849C34.2614 43.0459 34.5336 44.1853 34.9843 45.2576C36.0299 47.7766 37.9733 49.8131 40.4344 50.9688C42.8955 52.1245 45.6972 52.3162 48.2915 51.5064C50.8859 50.6967 53.0862 48.9437 54.4622 46.5904C55.8381 44.2371 56.2907 41.4528 55.7314 38.782H55.765ZM46.4154 44.7686L45.0893 43.4364L43.7632 44.7686C43.6072 44.9266 43.4215 45.0521 43.217 45.1377C43.0124 45.2233 42.793 45.2674 42.5714 45.2674C42.3498 45.2674 42.1304 45.2233 41.9259 45.1377C41.7213 45.0521 41.5357 44.9266 41.3796 44.7686C41.2223 44.6118 41.0974 44.4253 41.0122 44.2198C40.927 44.0143 40.8831 43.7939 40.8831 43.5713C40.8831 43.3486 40.927 43.1282 41.0122 42.9227C41.0974 42.7172 41.2223 42.5307 41.3796 42.374L41.8664 41.8849L42.7057 41.0417L41.3796 39.7095C41.0636 39.3919 40.886 38.9613 40.886 38.5122C40.886 38.0631 41.0636 37.6324 41.3796 37.3149C41.6957 36.9973 42.1244 36.8189 42.5714 36.8189C43.0184 36.8189 43.4471 36.9973 43.7632 37.3149L45.0893 38.6471L46.4154 37.3149C46.7314 36.9973 47.1601 36.8189 47.6071 36.8189C48.0541 36.8189 48.4828 36.9973 48.7989 37.3149C49.115 37.6324 49.2926 38.0631 49.2926 38.5122C49.2926 38.9613 49.115 39.3919 48.7989 39.7095L47.4729 41.0417L48.2618 41.8343L48.7989 42.374C48.9563 42.5307 49.0811 42.7172 49.1664 42.9227C49.2516 43.1282 49.2954 43.3486 49.2954 43.5713C49.2954 43.7939 49.2516 44.0143 49.1664 44.2198C49.0811 44.4253 48.9563 44.6118 48.7989 44.7686C48.6429 44.9266 48.4572 45.0521 48.2527 45.1377C48.0481 45.2233 47.8287 45.2674 47.6071 45.2674C47.3855 45.2674 47.1661 45.2233 46.9616 45.1377C46.7571 45.0521 46.5714 44.9266 46.4154 44.7686Z"></path>
922 </clipPath>
923 </defs>
924 </svg>
925 </span>
926 <?php else: ?>
927 <?php if( $show_icon ): ?>
928 <?php
929 // Add 'pf-block' class if this is a Gutenberg block (not Elementor)
930 $error_wrapper_class = 'bp-thank_page-custom-logo_wrapper-error';
931 if ( ! empty( $settings['better_payment_form_source'] ) && 'block' === $settings['better_payment_form_source'] ) {
932 $error_wrapper_class .= ' pf-block';
933 }
934 ?>
935 <div class="<?php echo esc_attr( $error_wrapper_class ); ?>">
936 <?php
937 // Render icon safely (handles FontAwesome, Dashicons, SVG with or without Elementor)
938 if (!empty($settings['better_payment_form_error_message_icon'])) {
939 self::render_icon($settings['better_payment_form_error_message_icon'], ['aria-hidden' => 'true']);
940 } else {
941 // Fallback to default icons
942 echo '<i class="' . esc_attr($image_url) . '"></i>';
943 }
944 ?>
945 </div>
946 <?php else: ?>
947 <span class="bp-thank_page-logo_wrapper">
948 <img src="<?php echo esc_url($image_url); ?>" alt="Error logo">
949 </span>
950 <?php endif; ?>
951 <?php endif; ?>
952 </div>
953 <div class="bp-thank_page-text">
954 <h2 class="bp-font_ibm bp-page_header"><?php echo wp_kses_post( $failed_heading ); ?></h2>
955 <p class="bp-font_ibm bp-reason_for-text">Payment of <?php echo $currency_symbol . $transaction_amount; ?> to <?php echo $store_name; ?> failed.</p>
956 <p class="bp-font_ibm bp-payment_info"><?php echo wp_kses_post( $failed_sub_heading ); ?></p>
957
958 <div class="bp-flex bp-transaction_info-wrapper">
959 <p class="bp-flex bp-font_ibm bp-transaction_info"> <span>
960 <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
961 <g clip-path="url(#clip0_2914_6421)">
962 <path d="M12.2002 12.825C11.8821 12.825 11.6242 13.0829 11.6242 13.401C11.6242 13.7191 11.8821 13.977 12.2002 13.977V12.825ZM17.0002 13.401L17.4075 13.8083C17.5156 13.7002 17.5762 13.5537 17.5762 13.401C17.5762 13.2482 17.5156 13.1017 17.4075 12.9937L17.0002 13.401ZM14.993 14.5937C14.768 14.8186 14.768 15.1833 14.993 15.4083C15.2179 15.6332 15.5826 15.6332 15.8075 15.4083L14.993 14.5937ZM15.8075 11.3937C15.5826 11.1687 15.2179 11.1687 14.993 11.3937C14.768 11.6186 14.768 11.9833 14.993 12.2083L15.8075 11.3937ZM10.6002 16.377C10.9184 16.377 11.1762 16.1191 11.1762 15.801C11.1762 15.4829 10.9184 15.225 10.6002 15.225V16.377ZM16.4242 9.40098C16.4242 9.71909 16.6821 9.97698 17.0002 9.97698C17.3184 9.97698 17.5762 9.71909 17.5762 9.40098H16.4242ZM7.40024 13.177C7.71836 13.177 7.97624 12.9191 7.97624 12.601C7.97624 12.2829 7.71836 12.025 7.40024 12.025V13.177ZM4.20024 12.025C3.88213 12.025 3.62424 12.2829 3.62424 12.601C3.62424 12.9191 3.88213 13.177 4.20024 13.177V12.025ZM9.80024 13.177C10.1184 13.177 10.3762 12.9191 10.3762 12.601C10.3762 12.2829 10.1184 12.025 9.80024 12.025V13.177ZM9.40024 12.025C9.08213 12.025 8.82424 12.2829 8.82424 12.601C8.82424 12.9191 9.08213 13.177 9.40024 13.177V12.025ZM1.00024 7.22498C0.682128 7.22498 0.424244 7.48286 0.424244 7.80098C0.424244 8.11909 0.682128 8.37698 1.00024 8.37698V7.22498ZM17.0002 8.37698C17.3184 8.37698 17.5762 8.11909 17.5762 7.80098C17.5762 7.48286 17.3184 7.22498 17.0002 7.22498V8.37698ZM12.2002 13.977H17.0002V12.825H12.2002V13.977ZM16.593 12.9937L14.993 14.5937L15.8075 15.4083L17.4075 13.8083L16.593 12.9937ZM17.4075 12.9937L15.8075 11.3937L14.993 12.2083L16.593 13.8083L17.4075 12.9937ZM7.40024 3.57698H10.6002V2.42498H7.40024V3.57698ZM10.6002 15.225H7.40024V16.377H10.6002V15.225ZM7.40024 15.225C5.87547 15.225 4.78983 15.2238 3.96572 15.113C3.15819 15.0044 2.68857 14.8002 2.3448 14.4564L1.53021 15.271C2.1237 15.8645 2.87695 16.1289 3.81222 16.2547C4.73093 16.3782 5.90803 16.377 7.40024 16.377V15.225ZM0.424244 9.40098C0.424244 10.8932 0.423021 12.0703 0.546538 12.989C0.672282 13.9243 0.936721 14.6775 1.53021 15.271L2.3448 14.4564C2.00103 14.1127 1.79684 13.643 1.68827 12.8355C1.57747 12.0114 1.57624 10.9258 1.57624 9.40098H0.424244ZM10.6002 3.57698C12.125 3.57698 13.2107 3.5782 14.0348 3.689C14.8423 3.79757 15.3119 4.00176 15.6557 4.34553L16.4703 3.53094C15.8768 2.93745 15.1235 2.67301 14.1883 2.54727C13.2696 2.42375 12.0925 2.42498 10.6002 2.42498V3.57698ZM17.5762 9.40098C17.5762 7.90876 17.5775 6.73166 17.4539 5.81296C17.3282 4.87768 17.0638 4.12443 16.4703 3.53094L15.6557 4.34553C15.9995 4.6893 16.2037 5.15892 16.3122 5.96646C16.423 6.79056 16.4242 7.8762 16.4242 9.40098H17.5762ZM7.40024 2.42498C5.90803 2.42498 4.73093 2.42375 3.81222 2.54727C2.87695 2.67301 2.1237 2.93745 1.53021 3.53094L2.3448 4.34553C2.68857 4.00176 3.15819 3.79757 3.96572 3.689C4.78983 3.5782 5.87547 3.57698 7.40024 3.57698V2.42498ZM1.57624 9.40098C1.57624 7.8762 1.57747 6.79056 1.68827 5.96646C1.79684 5.15892 2.00103 4.6893 2.3448 4.34553L1.53021 3.53094C0.936721 4.12443 0.672282 4.87768 0.546538 5.81296C0.423021 6.73166 0.424244 7.90876 0.424244 9.40098H1.57624ZM7.40024 12.025H4.20024V13.177H7.40024V12.025ZM9.80024 12.025H9.40024V13.177H9.80024V12.025ZM1.00024 8.37698H17.0002V7.22498H1.00024V8.37698Z" fill="#8F9AB0"></path>
963 </g>
964 <defs>
965 <clipPath id="clip0_2914_6421">
966 <rect width="18" height="18" fill="white"></rect>
967 </clipPath>
968 </defs>
969 </svg>
970 </span>
971 <span><?php echo wp_kses_post( $transaction_id_text ); ?>:</span>
972 <span class="bp-bolt bp-transaction_id"><?php echo $transaction_id; ?></span>
973 </p>
974
975 <button class="bp-transaction_data-copy_btn ">
976 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
977 <path d="M15.0002 15.601C16.3257 15.601 17.4002 14.5265 17.4002 13.201V8.40098C17.4002 5.38399 17.4002 3.87549 16.463 2.93823C15.5257 2.00098 14.0172 2.00098 11.0002 2.00098H7.80024C6.47476 2.00098 5.40024 3.07549 5.40024 4.40098M10.2002 18.001H7.80024C5.5375 18.001 4.40613 18.001 3.70319 17.298C3.00024 16.5951 3.00024 15.4637 3.00024 13.201V9.20098C3.00024 6.93823 3.00024 5.80686 3.70319 5.10392C4.40613 4.40098 5.5375 4.40098 7.80024 4.40098H10.2002C12.463 4.40098 13.5944 4.40098 14.2973 5.10392C15.0002 5.80686 15.0002 6.93824 15.0002 9.20098V13.201C15.0002 15.4637 15.0002 16.5951 14.2973 17.298C13.5944 18.001 12.463 18.001 10.2002 18.001Z" stroke-width="1.152"></path>
978 </svg>
979 </button>
980 </div>
981 </div>
982 <?php if( $show_details_button ): ?>
983 <div class="bp-btn_wrapper">
984 <a href="<?php echo $better_payment_form_error_details_page_url; ?>" target="_blank" class="bp-font_ibm bp-details_btn"><?php echo $details_button_text; ?></a>
985 </div>
986 <?php endif; ?>
987 </div>
988 </section>
989 <?php
990 }
991
992 /**
993 * Remove args from url
994 *
995 * @since 0.0.1
996 */
997 public static function remove_arg() {
998 ?>
999 <script>
1000
1001 if(typeof params === 'undefined'){
1002 let params = '';
1003 }
1004
1005 params = new URLSearchParams(location.search);
1006
1007 if (params.has('better_payment_paypal_status') || params.has('better_payment_stripe_status') || params.has('better_payment_paystack_status')) {
1008 params.delete('better_payment_paypal_status');
1009 params.delete('better_payment_stripe_status');
1010 params.delete('better_payment_paystack_status');
1011 params.delete('better_payment_widget_id');
1012 params.delete('better_payment_stripe_id');
1013 params.delete('better_payment_paystack_id');
1014 window.history.replaceState({}, '', `${location.pathname}?${params}`);
1015 }
1016 </script>
1017 <?php
1018 }
1019
1020 /**
1021 * Get failed transaction data
1022 *
1023 * @since 1.0.0
1024 */
1025 public static function get_failed_transaction_data( $order_id = '' ) {
1026 if ( empty( $order_id ) ) {
1027 return false;
1028 }
1029
1030 global $wpdb;
1031 $table = "{$wpdb->prefix}better_payment";
1032
1033 $result = $wpdb->get_row(
1034 $wpdb->prepare(
1035 "SELECT amount, currency, transaction_id, order_id, source FROM $table WHERE order_id=%s LIMIT 1",
1036 $order_id
1037 )
1038 );
1039
1040 if ( !empty( $result ) ) {
1041 $helper_obj = new Helper();
1042 return [
1043 'amount' => floatval( $result->amount ),
1044 'currency' => sanitize_text_field( $result->currency ),
1045 'currency_symbol' => $helper_obj->get_currency_symbol( $result->currency ),
1046 'transaction_id' => !empty( $result->transaction_id ) ? sanitize_text_field( $result->transaction_id ) : 'N/A',
1047 'method' => sanitize_text_field( $result->source ),
1048 ];
1049 }
1050
1051 return false;
1052 }
1053
1054 /**
1055 * Email template
1056 *
1057 * @since 0.0.1
1058 */
1059 public static function better_email_notification($transaction_id, $customer_email, $settings, $referrer='Stripe', $form_fields_info='', $is_elementor_form = 0){
1060 //Send Email: customer and admin
1061 $better_txn_id = sanitize_text_field( $transaction_id );
1062 $better_cus_email = sanitize_email( $customer_email );
1063 $default_subject = sprintf(__('Better Payment transaction on %s', 'better-payment'), esc_html(get_option('blogname')));
1064 $better_payment_global_settings = DB::get_settings();
1065
1066 $better_payment_email_to = !empty($better_payment_global_settings['better_payment_settings_general_email_to']) ? $better_payment_global_settings['better_payment_settings_general_email_to'] : get_option( 'admin_email' );
1067
1068 $better_payment_email_subject = !empty($better_payment_global_settings['better_payment_settings_general_email_subject']) ? $better_payment_global_settings['better_payment_settings_general_email_subject'] : $default_subject;
1069 $better_payment_email_content = !empty($better_payment_global_settings['better_payment_settings_general_email_message_admin']) ? $better_payment_global_settings['better_payment_settings_general_email_message_admin'] : 'Email Content';
1070 $better_payment_email_from = !empty($better_payment_global_settings['better_payment_settings_general_email_from_email']) ? $better_payment_global_settings['better_payment_settings_general_email_from_email'] : '';
1071 $better_payment_email_from_name = !empty($better_payment_global_settings['better_payment_settings_general_email_from_name']) ? $better_payment_global_settings['better_payment_settings_general_email_from_name'] : '';
1072 $better_payment_email_reply_to = !empty($better_payment_global_settings['better_payment_settings_general_email_reply_to']) ? $better_payment_global_settings['better_payment_settings_general_email_reply_to'] : '';
1073 $better_payment_email_cc = !empty($better_payment_global_settings['better_payment_settings_general_email_cc']) ? $better_payment_global_settings['better_payment_settings_general_email_cc'] : '';
1074 $better_payment_email_bcc = !empty($better_payment_global_settings['better_payment_settings_general_email_bcc']) ? $better_payment_global_settings['better_payment_settings_general_email_bcc'] : '';
1075 $better_payment_email_content_type = !empty($better_payment_global_settings['better_payment_settings_general_email_send_as']) ? $better_payment_global_settings['better_payment_settings_general_email_send_as'] : 'html';
1076
1077 $better_payment_email_subject_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_subject_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_subject_customer'] : $default_subject;
1078 $better_payment_email_content_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_message_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_message_customer'] : 'Email Content';
1079 $better_payment_email_from_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_from_email_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_from_email_customer'] : '';
1080 $better_payment_email_from_name_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_from_name_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_from_name_customer'] : '';
1081 $better_payment_email_reply_to_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_reply_to_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_reply_to_customer'] : '';
1082 $better_payment_email_cc_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_cc_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_cc_customer'] : '';
1083 $better_payment_email_bcc_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_bcc_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_bcc_customer'] : '';
1084 $better_payment_email_content_type_customer = !empty($better_payment_global_settings['better_payment_settings_general_email_send_as_customer']) ? $better_payment_global_settings['better_payment_settings_general_email_send_as_customer'] : 'html';
1085 $args = [];
1086
1087 $args['email_form_name'] = ! empty( $settings['better_payment_form_title'] ) ? sanitize_text_field( $settings['better_payment_form_title'] ) : 'N/A';
1088 $args['email_content_heading_show'] = ! empty( $settings['better_payment_email_content_heading'] ) && 'yes' === $settings['better_payment_email_content_heading'] ? 1 : 0;
1089 $args['email_content_from_section_show'] = ! empty( $settings['better_payment_email_content_from_section'] ) && 'yes' === $settings['better_payment_email_content_from_section'] ? 1 : 0;
1090 $args['email_content_to_section_show'] = ! empty( $settings['better_payment_email_content_to_section'] ) && 'yes' === $settings['better_payment_email_content_to_section'] ? 1 : 0;
1091 $args['email_content_transaction_summary_show'] = ! empty( $settings['better_payment_email_content_transaction_summary'] ) && 'yes' === $settings['better_payment_email_content_transaction_summary'] ? 1 : 0;
1092 $args['email_content_footer_text_show'] = ! empty( $settings['better_payment_email_content_footer_text'] ) && 'yes' === $settings['better_payment_email_content_footer_text'] ? 1 : 0;
1093 $args['email_content_customer'] = ! empty( $settings['better_payment_email_content_customer'] ) ? $settings['better_payment_email_content_customer'] : '';
1094 $args['email_content_admin'] = ! empty( $settings['better_payment_email_content'] ) ? $settings['better_payment_email_content'] : '';
1095 $args['is_elementor_form'] = $is_elementor_form;
1096
1097 if ( ! empty( $settings['better_payment_email_content_greeting'] ) ) {
1098 $args['email_content_greeting'] = $settings['better_payment_email_content_greeting'];
1099 }
1100
1101 if ( ! empty( $settings['better_payment_form_email_logo']['url'] ) ) {
1102 $args['email_logo_url'] = $settings['better_payment_form_email_logo']['url'];
1103 }
1104
1105 if ( ! empty( $settings['better_payment_form_email_attachment']['id'] ) ) {
1106 $args['email_attachment_id'] = intval( $settings['better_payment_form_email_attachment']['id'] );
1107 $args['email_attachment_path'] = get_attached_file( $args['email_attachment_id'] );
1108 }
1109
1110 if ( ! empty( $settings['better_payment_form_email_attachment_pdf_show'] ) && ! empty( $settings['better_payment_form_email_attachment_pdf']['id'] ) ) {
1111 $args['email_attachment_id'] = intval( $settings['better_payment_form_email_attachment_pdf']['id'] );
1112 $args['email_attachment_path'] = get_attached_file( $args['email_attachment_id'] );
1113 }
1114
1115 if(isset($settings['better_payment_email_to'])){
1116 $better_payment_email_to = sanitize_email($settings['better_payment_email_to']);
1117 }
1118
1119 if(isset($settings['better_payment_email_subject'])){
1120 $better_payment_email_subject = sanitize_text_field($settings['better_payment_email_subject']);
1121 }
1122
1123 if(isset($settings['better_payment_email_subject_customer'])){
1124 $better_payment_email_subject_customer = sanitize_text_field($settings['better_payment_email_subject_customer']);
1125 }
1126
1127 if(isset($settings['better_payment_email_content_type'])){
1128 $better_payment_email_content_type = sanitize_text_field($settings['better_payment_email_content_type']);
1129 }
1130
1131 if(isset($settings['better_payment_email_content_type_customer'])){
1132 $better_payment_email_content_type_customer = sanitize_text_field($settings['better_payment_email_content_type_customer']);
1133 }
1134
1135 $args['email_content_type'] = $better_payment_email_content_type;
1136 $args['email_content_type_customer'] = $better_payment_email_content_type_customer;
1137
1138 $line_break = $better_payment_email_content_type == 'html' ? '<br>' : "\n";
1139 $line_break_customer = $better_payment_email_content_type_customer == 'html' ? '<br>' : "\n";
1140
1141 global $wpdb;
1142 $table = "{$wpdb->prefix}better_payment";
1143 $transaction_obj = $wpdb->get_row(
1144 $wpdb->prepare( "SELECT * FROM $table WHERE transaction_id=%s limit 1", sanitize_text_field( $transaction_id ) )
1145 );
1146
1147 if(isset($settings['better_payment_email_content'])){
1148 $better_payment_email_content = sanitize_text_field($settings['better_payment_email_content']);
1149 $better_payment_email_content = self::better_render_email_body( $better_payment_email_content, $form_fields_info, $line_break, 'admin', $transaction_obj, $args );
1150 } else if ( !empty($better_payment_email_content) ){
1151 $better_payment_email_content = self::better_render_email_body( $better_payment_email_content, $form_fields_info, $line_break, 'admin', $transaction_obj, $args );
1152 }
1153
1154 if(isset($settings['better_payment_email_content_customer'])){
1155 $better_payment_email_content_customer = sanitize_text_field($settings['better_payment_email_content_customer']);
1156 $better_payment_email_content_customer = self::better_render_email_body( $better_payment_email_content_customer, $form_fields_info, $line_break_customer, 'customer', $transaction_obj, $args );
1157 } else if ( !empty($better_payment_email_content_customer) ){
1158 $better_payment_email_content_customer = self::better_render_email_body( $better_payment_email_content_customer, $form_fields_info, $line_break, 'customer', $transaction_obj, $args ); //$line_break_customer not used : need to check type on parent method and add headers accordingly.
1159 }
1160
1161 if(isset($settings['better_payment_email_from'])){
1162 $better_payment_email_from = sanitize_email($settings['better_payment_email_from']);
1163 }
1164
1165 if(isset($settings['better_payment_email_from_name'])){
1166 $better_payment_email_from_name = sanitize_text_field($settings['better_payment_email_from_name']);
1167 }
1168
1169 if(isset($settings['better_payment_email_reply_to'])){
1170 $better_payment_email_reply_to = sanitize_email($settings['better_payment_email_reply_to']);
1171 }
1172
1173 if(isset($settings['better_payment_email_cc'])){
1174 $better_payment_email_cc = sanitize_email($settings['better_payment_email_cc']);
1175 }
1176
1177 if(isset($settings['better_payment_email_bcc'])){
1178 $better_payment_email_bcc = sanitize_email($settings['better_payment_email_bcc']);
1179 }
1180
1181 //Customer Email
1182 if(isset($settings['better_payment_email_from_customer'])){
1183 $better_payment_email_from_customer = sanitize_email($settings['better_payment_email_from_customer']);
1184 }
1185
1186 if(isset($settings['better_payment_email_from_name_customer'])){
1187 $better_payment_email_from_name_customer = sanitize_text_field($settings['better_payment_email_from_name_customer']);
1188 }
1189
1190 if(isset($settings['better_payment_email_reply_to_customer'])){
1191 $better_payment_email_reply_to_customer = sanitize_email($settings['better_payment_email_reply_to_customer']);
1192 }
1193
1194 if(isset($settings['better_payment_email_cc_customer'])){
1195 $better_payment_email_cc_customer = sanitize_email($settings['better_payment_email_cc_customer']);
1196 }
1197
1198 if(isset($settings['better_payment_email_bcc_customer'])){
1199 $better_payment_email_bcc_customer = sanitize_email($settings['better_payment_email_bcc_customer']);
1200 }
1201
1202 if($better_payment_email_content == ''){
1203 $better_payment_email_content = __('New better payment transaction! ', 'better-payment');
1204 }
1205
1206 if($better_payment_email_content_customer == ''){
1207 $better_payment_email_content_customer = __('New better payment transaction! ', 'better-payment');
1208 }
1209
1210 $better_payment_email_headers = [];
1211 $better_payment_email_headers_customer = [];
1212
1213 if($better_payment_email_content_type == 'html'){
1214 $better_payment_email_headers[] = 'Content-Type: text/html; charset=UTF-8';
1215 }
1216
1217 if($better_payment_email_content_type_customer == 'html'){
1218 $better_payment_email_headers_customer[] = 'Content-Type: text/html; charset=UTF-8';
1219 }
1220
1221 if($better_payment_email_from != ''){
1222 $better_payment_email_headers[] = "From: $better_payment_email_from_name <$better_payment_email_from>";
1223 }
1224
1225 if($better_payment_email_cc != ''){
1226 $better_payment_email_headers[] = "Cc: <$better_payment_email_cc>";
1227 }
1228
1229 if($better_payment_email_bcc != ''){
1230 $better_payment_email_headers[] = "BCc: $better_payment_email_bcc";
1231 }
1232
1233 if($better_payment_email_reply_to != ''){
1234 $better_payment_email_headers[] = "Reply-To: $better_payment_email_reply_to";
1235 }
1236
1237 //Customer Email
1238 if($better_payment_email_from_customer != ''){
1239 $better_payment_email_headers_customer[] = "From: $better_payment_email_from_name_customer <$better_payment_email_from_customer>";
1240 }
1241
1242 $form_fields_info_array = [];
1243
1244 if( ! empty( $form_fields_info ) ){
1245 $form_fields_info_array = maybe_unserialize( $form_fields_info );
1246 }
1247
1248 $form_fields_info_cus_email = ! empty( $form_fields_info_array['primary_email'] ) ? sanitize_email( $form_fields_info_array['primary_email'] ) : '';
1249
1250 if($better_payment_email_cc_customer != '' || ! empty( $form_fields_info_cus_email ) ){
1251 $better_payment_email_cc_customer_multiple = implode(',', [$form_fields_info_cus_email, $better_payment_email_cc_customer]);
1252 $better_payment_email_headers_customer[] = "Cc: $better_payment_email_cc_customer_multiple";
1253 }
1254
1255 if($better_payment_email_bcc_customer != ''){
1256 $better_payment_email_headers_customer[] = "BCc: $better_payment_email_bcc_customer";
1257 }
1258
1259 if($better_payment_email_reply_to_customer != ''){
1260 $better_payment_email_headers_customer[] = "Reply-To: $better_payment_email_reply_to_customer";
1261 }
1262
1263 $email_attachments = ! empty( $args['email_attachment_path'] ) ? [ $args['email_attachment_path'] ] : [];
1264 $allowed_extensions = array('jpg', 'jpeg', 'png', 'pdf');
1265
1266 $file_info = count( $email_attachments ) ? pathinfo($email_attachments[0]) : [];
1267 $file_extension = count( $file_info ) ? strtolower($file_info['extension']) : '';
1268
1269 if ( ! in_array( $file_extension, $allowed_extensions ) ){
1270 $email_attachments = [];
1271 }
1272
1273 self::send_better_email($better_cus_email, $better_payment_email_subject_customer, $better_payment_email_content_customer, $better_payment_email_headers_customer, $email_attachments); //customer mail
1274 self::send_better_email($better_payment_email_to, $better_payment_email_subject, $better_payment_email_content, $better_payment_email_headers); //admin mail
1275 }
1276
1277 /**
1278 * Sends an HTML email.
1279 *
1280 * @since 0.0.2
1281 *
1282 * @param string $to
1283 * @param string $subject
1284 * @param array $message
1285 *
1286 * @return bool false indicates mail sending failed while true doesn't gurantee that mail sent.
1287 * true just indicate script processed successfully without any errors.
1288 * Ref: https://developer.wordpress.org/reference/functions/wp_mail/
1289 */
1290 public static function send_better_email( $to, $subject, $message, $headers=[], $attachments = [] ) {
1291 $response = false;
1292
1293 $mailValidated = filter_var($to, FILTER_VALIDATE_EMAIL);
1294
1295 if ($mailValidated) {
1296 $response = wp_mail( $to, $subject, $message, $headers, $attachments );
1297 }
1298
1299 return $response;
1300 }
1301
1302 /**
1303 * Email body
1304 *
1305 *
1306 * @return string
1307 * @since 0.0.1
1308 */
1309 public static function better_render_email_body( $email_body, $form_fields_info, $line_break, $type = 'admin', $transaction_obj = null, $args = [] ) {
1310 $transaction_id =
1311 $currency =
1312 $payment_date =
1313 $customer_name =
1314 $customer_first_name =
1315 $customer_last_name =
1316 $amount = '';
1317 $helper_obj = new Helper();
1318
1319 if(null !== $transaction_obj && is_object($transaction_obj)){
1320 $transaction_id = $transaction_obj->transaction_id;
1321 $amount = $transaction_obj->amount;
1322 $status = $transaction_obj->status;
1323 $source = $transaction_obj->source;
1324 $currency = $transaction_obj->currency;
1325 $currency_symbol = $helper_obj->get_currency_symbol( esc_html($currency) );
1326 $payment_date = wp_date(get_option('date_format').' '.get_option('time_format'), strtotime($transaction_obj->payment_date));
1327 }
1328
1329 $is_empty_email_body = empty($email_body);
1330
1331 $email_body = do_shortcode( $email_body );
1332 $bp_form_fields_html_content = $email_body;
1333
1334 $bp_all_fields_shortcode = 'bp-all-fields';
1335 $referer_content_page_link = '#';
1336
1337 $field_text = __('Field', 'better-payment');
1338 $value_text = __('Entry', 'better-payment');
1339
1340 $form_fields_info_arr = maybe_unserialize($form_fields_info);
1341
1342 $email_logo_url = ! empty( $args['email_logo_url'] ) ? $args['email_logo_url'] : '';
1343 $email_content_greeting = ! empty( $args['email_content_greeting'] ) ? 1 : 0;
1344 $email_form_name = ! empty( $args['email_form_name'] ) ? $args['email_form_name'] : 'N/A';
1345
1346 $bp_form_fields_html_header = '<table style="margin-bottom: 20px; font-size: 14px; border-collapse: collapse; width: 100%;">';
1347
1348 $bp_form_fields_html_footer = "</table>";
1349
1350 $content = ''. $line_break;
1351
1352 foreach ( $form_fields_info_arr as $key => $field ) {
1353 if ( $key === 'is_payment_split_payment' ) {
1354 $is_payment_split_payment = 1;
1355 }
1356 //Hide few fields
1357 if(
1358 $key === 'referer_page_id' || $key === 'referer_widget_id' || $key === 'source' || $key === 'el_form_fields'
1359 || $key === 'is_woo_layout'
1360 || $key === 'is_payment_split_payment'
1361 || $key === 'split_payment_total_amount'
1362 || $key === 'split_payment_total_amount_price_id'
1363 || $key === 'split_payment_installment_price_id'
1364 ) {
1365 if($key === 'referer_page_id'){
1366 $referer_content_page_link = !empty($field) ? get_permalink( $field ) : $referer_content_page_link;
1367 }
1368
1369 continue;
1370 }
1371
1372 if($key === 'primary_first_name'){
1373 $key = 'first_name';
1374 $customer_first_name = $field;
1375 }
1376 if($key === 'primary_last_name'){
1377 $key = 'last_name';
1378 $customer_last_name = $field;
1379 }
1380
1381 if($key === 'primary_email'){
1382 $key = 'email';
1383 }
1384
1385 if($key === 'primary_payment_amount'){
1386 $key = 'payment_amount';
1387 }
1388
1389 $key_formatted = self::better_title_case($key);
1390 if($key_formatted === 'Amount'){
1391 $key_formatted = __('Paid', 'better-payment');
1392
1393 if ( ! empty( $is_payment_split_payment ) ) {
1394 $key_formatted = __('Product Price: ', 'better-payment');
1395 }
1396 }
1397
1398 $content .= "<tr>
1399 <td style='padding: 7px; border: 1px solid #666;'> <strong>$key_formatted</strong> </td>
1400 <td style='padding: 7px; border: 1px solid #666;'> $field </td>
1401 </tr>";
1402 }
1403
1404 if($customer_first_name) {
1405 $customer_name = $customer_first_name . ' ';
1406 }
1407 if($customer_last_name) {
1408 $customer_name .= $customer_last_name . ' ';
1409 }
1410
1411 $allowed_sources = ['paypal', 'stripe', 'paystack'];
1412 $source_image_url = BETTER_PAYMENT_ASSETS . '/img/stripe.png';
1413 $source_image_alt = 'Stripe';
1414
1415 if( in_array( strtolower( $transaction_obj->source ), $allowed_sources ) ){
1416 $source_image_url = strtolower( $transaction_obj->source ) == 'paypal' ? BETTER_PAYMENT_ASSETS . '/img/paypal.png' : BETTER_PAYMENT_ASSETS . "/img/{$transaction_obj->source}.png";
1417 $source_image_alt = strtolower( $transaction_obj->source ) == 'paypal' ? 'PayPal' : ucfirst( strtolower( $transaction_obj->source ) );
1418 }
1419
1420 $amount_quantity = ! empty( $form_fields_info_arr['amount_quantity'] ) ? intval( $form_fields_info_arr['amount_quantity'] ) : 1;
1421 // #ToDo Product id or ids with comma
1422 $woo_product_id = ! empty( $form_fields_info_arr['woo_product_id'] ) ? intval( $form_fields_info_arr['woo_product_id'] ) : 0;
1423 $fluentcart_product_id = ! empty( $form_fields_info_arr['fluentcart_product_id'] ) ? intval( $form_fields_info_arr['fluentcart_product_id'] ) : 0;
1424 $woo_product_ids = ! empty( $form_fields_info_arr['woo_product_ids'] ) ? maybe_unserialize( $form_fields_info_arr['woo_product_ids'] ) : [0];
1425 $fluentcart_product_ids = ! empty( $form_fields_info_arr['fluentcart_product_ids'] ) ? maybe_unserialize( $form_fields_info_arr['fluentcart_product_ids'] ) : [0];
1426 $product_name = '';
1427 $product_permalink = '';
1428 $product_image_src = '';
1429
1430 // Handle WooCommerce products
1431 if (function_exists('wc_get_product') && $woo_product_id ) {
1432 $bp_woocommerce_product = wc_get_product($woo_product_id);
1433 $product = $bp_woocommerce_product;
1434
1435 if ($product) {
1436 $product_name = $product->get_name();
1437 $product_permalink = get_permalink($product->get_id());
1438 $product_price = $product->get_price();
1439 $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' );
1440 $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : '';
1441 }
1442 }
1443
1444 if (function_exists('fluentCart') && $fluentcart_product_id ) {
1445 try {
1446 $fluentcart_product = \FluentCart\App\Models\Product::query()
1447 ->with(['detail', 'variants'])
1448 ->find($fluentcart_product_id);
1449
1450 if ($fluentcart_product) {
1451 $product_name = $fluentcart_product->post_title;
1452 $product_permalink = get_permalink($fluentcart_product->ID);
1453
1454 // Get price from the first variant or detail
1455 $product_price = 0;
1456 if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) {
1457 $product_price = $fluentcart_product->variants[0]->item_price;
1458 } elseif (!empty($fluentcart_product->detail)) {
1459 $product_price = $fluentcart_product->detail->min_price;
1460 }
1461
1462 $product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' );
1463 $product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : '';
1464 }
1465 } catch ( \Exception $e ) {
1466 // Handle error silently
1467 }
1468 }
1469
1470 $detailed_product_info = isset( $form_fields_info_arr['detailed_product_info'] ) ? maybe_unserialize( $form_fields_info_arr['detailed_product_info'] ) : [];
1471
1472 $all_data = [
1473 'amount' => $amount,
1474 'amount_quantity' => $amount_quantity,
1475 'woo_product_id' => $woo_product_id,
1476 'woo_product_ids' => $woo_product_ids,
1477 'fluentcart_product_id' => $fluentcart_product_id,
1478 'fluentcart_product_ids' => $fluentcart_product_ids,
1479 'product_name' => $product_name,
1480 'product_permalink' => $product_permalink,
1481 'product_image_src' => $product_image_src,
1482 'detailed_product_info' => $detailed_product_info,
1483 'amount_single' => $amount_quantity > 0 ? floatval( $amount / $amount_quantity ) : $amount,
1484 'currency' => ! empty( $currency ) ? $currency : '',
1485 'currency_symbol' => ! empty( $currency_symbol ) ? $currency_symbol : '',
1486 'payment_date_time' => ! empty( $payment_date ) ? $payment_date : '',
1487 'transaction_id' => ! empty( $transaction_id ) ? $transaction_id : '',
1488 'payment_date_only' => wp_date(get_option('date_format'), strtotime($transaction_obj->payment_date)),
1489 'status' => ucfirst( $status ),
1490 'form_fields_info_arr' => $form_fields_info_arr,
1491 // 'admin_name' => $admin_name,
1492 'customer_name' => $customer_name,
1493 'site_title' => get_bloginfo( 'name' ),
1494 'site_admin_email' => get_bloginfo( 'admin_email' ),
1495 'form_name' => $email_form_name,
1496 'payment_method' => ucfirst( $source ),
1497 'email_logo_url' => $email_logo_url,
1498 'source_image_url' => $source_image_url,
1499 'source_image_alt' => $source_image_alt,
1500 'view_transaction_link' => admin_url("admin.php?page=better-payment-transactions&action=view&id={$transaction_obj->id}"),
1501 'email_content_heading_show' => intval( $args['email_content_heading_show'] ),
1502 'email_content_from_section_show' => intval( $args['email_content_from_section_show'] ),
1503 'email_content_to_section_show' => intval( $args['email_content_to_section_show'] ),
1504 'email_content_transaction_summary_show' => intval( $args['email_content_transaction_summary_show'] ),
1505 'email_content_footer_text_show' => intval( $args['email_content_footer_text_show'] ),
1506 'email_content_customer' => wp_kses_post( $args['email_content_customer'] ),
1507 'email_content_admin' => wp_kses_post( $args['email_content_admin'] ),
1508 'is_elementor_form' => intval( $args['is_elementor_form'] ),
1509 'email_content_type' => $args['email_content_type'] ?? 'html',
1510 'email_content_type_customer' => $args['email_content_type_customer'] ?? 'html',
1511 ];
1512
1513 $bp_form_fields_html_body = $content;
1514 $bp_form_fields_html_content = $bp_form_fields_html_header . $bp_form_fields_html_body . $bp_form_fields_html_footer ;
1515
1516 //Replace shortcode with form fields info
1517 $email_body = str_replace( "[$bp_all_fields_shortcode]", $bp_form_fields_html_content, $email_body );
1518
1519 // Email V2
1520 // General content
1521 $form_name =
1522
1523 ob_start();
1524
1525 include BETTER_PAYMENT_ADMIN_VIEWS_PATH . "/template-email-notification.php";
1526
1527 $email_body = ob_get_contents();
1528 ob_end_clean();
1529
1530 return $email_body;
1531 }
1532
1533 /**
1534 * String helper method
1535 * helps to convert string to title case
1536 *
1537 * @return string
1538 * @since 0.0.1
1539 */
1540 public static function better_title_case($string){
1541 $string = str_replace('_',' ', $string);
1542 $string = ucwords($string);
1543 return $string;
1544 }
1545
1546 /**
1547 * Safe icon rendering for payment form messages
1548 *
1549 * Handles multiple icon types: FontAwesome, Dashicons, SVG from media library
1550 * Works with or without Elementor being active
1551 *
1552 * @param array $icon_settings Icon settings from block/widget controls
1553 * @param array $html_attributes Optional HTML attributes for the icon element
1554 *
1555 * @return void (outputs HTML directly)
1556 * @since 2.0.4
1557 */
1558 public static function render_icon( $icon_settings = [], $html_attributes = [] ) {
1559 // Bail if no settings provided
1560 if ( empty( $icon_settings ) || ! is_array( $icon_settings ) ) {
1561 return;
1562 }
1563
1564 // If value is empty, nothing to render
1565 if ( empty( $icon_settings['value'] ) ) {
1566 return;
1567 }
1568
1569 $library = ! empty( $icon_settings['library'] ) ? $icon_settings['library'] : '';
1570 $value = $icon_settings['value'];
1571
1572 // Try to use Elementor's Icons_Manager if it's available and loaded
1573 if ( did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Icons_Manager' ) ) {
1574 try {
1575 \Elementor\Icons_Manager::render_icon( $icon_settings, $html_attributes );
1576 return;
1577 } catch ( \Exception $e ) {
1578 // If Elementor rendering fails, fall back to manual rendering
1579 }
1580 }
1581
1582 // Handle SVG (uploaded via media library)
1583 if ( $library === 'svg' ) {
1584 if ( is_array( $value ) && ! empty( $value['url'] ) ) {
1585 $svg_url = esc_url( $value['url'] );
1586 echo '<img src="' . $svg_url . '" alt="Icon" class="bp-icon-svg" />';
1587 return;
1588 }
1589 }
1590
1591 // Handle FontAwesome icons (all variants: fa, fas, far, fab, fal, fad, etc.)
1592 if ( in_array( $library, [ 'fa', 'fas', 'far', 'fab', 'fal', 'fad', 'fontawesome', 'font-awesome' ], true ) ) {
1593 if ( is_string( $value ) && ! empty( $value ) ) {
1594 // Build complete FontAwesome class
1595 $icon_class = 'fa';
1596
1597 // Add variant if specified (fas, far, fab, fal)
1598 if ( ! empty( $library ) && $library !== 'fa' && $library !== 'fontawesome' && $library !== 'font-awesome' ) {
1599 $icon_class = esc_attr( $library );
1600 } else {
1601 // Default to 'fas' if no variant specified
1602 $icon_class = 'fas';
1603 }
1604
1605 // Add the specific icon class
1606 $icon_class .= ' ' . esc_attr( $value );
1607
1608 $html_class = ! empty( $html_attributes['class'] ) ? ' ' . $html_attributes['class'] : '';
1609 $aria_hidden = isset( $html_attributes['aria-hidden'] ) ? ' aria-hidden="' . esc_attr( $html_attributes['aria-hidden'] ) . '"' : ' aria-hidden="true"';
1610
1611 echo '<i class="' . $icon_class . $html_class . '"' . $aria_hidden . '></i>';
1612 return;
1613 }
1614 }
1615
1616 // Handle Dashicons
1617 if ( in_array( $library, [ 'dashicons' ], true ) ) {
1618 if ( is_string( $value ) && ! empty( $value ) ) {
1619 $icon_class = 'dashicons dashicons-' . esc_attr( $value );
1620
1621 $html_class = ! empty( $html_attributes['class'] ) ? ' ' . $html_attributes['class'] : '';
1622 $aria_hidden = isset( $html_attributes['aria-hidden'] ) ? ' aria-hidden="' . esc_attr( $html_attributes['aria-hidden'] ) . '"' : ' aria-hidden="true"';
1623
1624 echo '<span class="' . $icon_class . $html_class . '"' . $aria_hidden . '></span>';
1625 return;
1626 }
1627 }
1628
1629 // Handle custom CSS classes (like 'bp-icon bp-check-circle')
1630 // These are custom icon fonts or CSS-based icons defined by the theme/plugin
1631 if ( 'custom' === $library ) {
1632 if ( is_string( $value ) && ! empty( $value ) ) {
1633 $html_class = ! empty( $html_attributes['class'] ) ? ' ' . $html_attributes['class'] : '';
1634 $aria_hidden = isset( $html_attributes['aria-hidden'] ) ? ' aria-hidden="' . esc_attr( $html_attributes['aria-hidden'] ) . '"' : ' aria-hidden="true"';
1635
1636 echo '<i class="' . esc_attr( $value ) . $html_class . '"' . $aria_hidden . '></i>';
1637 return;
1638 }
1639 }
1640
1641 // If value is a plain string (might be a FontAwesome class without library specified)
1642 if ( is_string( $value ) && ! empty( $value ) && empty( $library ) ) {
1643 // Check if it looks like a FontAwesome class
1644 if ( strpos( $value, 'fa' ) !== false || strpos( $value, 'fa-' ) !== false ) {
1645 $icon_class = 'fas ' . esc_attr( $value );
1646
1647 $html_class = ! empty( $html_attributes['class'] ) ? ' ' . $html_attributes['class'] : '';
1648 $aria_hidden = isset( $html_attributes['aria-hidden'] ) ? ' aria-hidden="' . esc_attr( $html_attributes['aria-hidden'] ) . '"' : ' aria-hidden="true"';
1649
1650 echo '<i class="' . $icon_class . $html_class . '"' . $aria_hidden . '></i>';
1651 return;
1652 }
1653
1654 // Check if it looks like a dashicon
1655 if ( strpos( $value, 'dashicon' ) !== false || strpos( $value, 'dashicons-' ) !== false ) {
1656 $icon_class = 'dashicons ' . esc_attr( $value );
1657
1658 $html_class = ! empty( $html_attributes['class'] ) ? ' ' . $html_attributes['class'] : '';
1659 $aria_hidden = isset( $html_attributes['aria-hidden'] ) ? ' aria-hidden="' . esc_attr( $html_attributes['aria-hidden'] ) . '"' : ' aria-hidden="true"';
1660
1661 echo '<span class="' . $icon_class . $html_class . '"' . $aria_hidden . '></span>';
1662 return;
1663 }
1664 }
1665 }
1666 }
1667