| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Transitional copy for Better Payment Pro <= 1.4.3; delete when ProCompatibility::MIN_PRO_VERSION >= 1.4.4. |
| 11 |
* Pro copy: better-payment-pro/includes/Admin/Elementor/LayoutRenderer.php. Slug: elementor_pro_layout_rendering. |
| 12 |
* |
| 13 |
* How the Payment Form widget renders Pro layouts 4, 5 and 6 for a Pro that does not |
| 14 |
* render them itself: |
| 15 |
* |
| 16 |
* - template_file(): Pro's layout template (the widget used to read Pro's |
| 17 |
* BETTER_PAYMENT_PRO_ADMIN_VIEWS_PATH constant itself); |
| 18 |
* - layout_vars(): the payment type and layout-6 platform `partials/layout-vars.php` |
| 19 |
* hands the template; |
| 20 |
* - default_text_items(): the form-field repeater `render_attribute_default_text()` |
| 21 |
* reads for a Pro layout; |
| 22 |
* - render_amount_element(): the amount list layouts 4 and 5 print (`'version' => 'v2'`). |
| 23 |
* |
| 24 |
* Every caller gates on lite_copy_applies(). A free install never renders a Pro layout (it |
| 25 |
* shows the upgrade banner), and a current Pro declares the slug and does all of this |
| 26 |
* in its own LayoutRenderer. Pro's LayoutRendererParityTest keeps the copies identical. |
| 27 |
* |
| 28 |
* @since 2.4.0 |
| 29 |
*/ |
| 30 |
final class ProPaymentFormLayouts { |
| 31 |
|
| 32 |
/** |
| 33 |
* Feature slug Pro declares once it renders its layouts itself. |
| 34 |
*/ |
| 35 |
const FEATURE = 'elementor_pro_layout_rendering'; |
| 36 |
|
| 37 |
/** |
| 38 |
* Whether Lite renders the Pro-layout pieces: an active Pro that does not declare the slug. |
| 39 |
* |
| 40 |
* @return bool |
| 41 |
*/ |
| 42 |
public static function lite_copy_applies(): bool { |
| 43 |
return ProCompatibility::lite_copy_applies( self::FEATURE ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Where an older Pro keeps a layout template, or '' when Pro is not loaded. |
| 48 |
* |
| 49 |
* @param string $layout A `-pro` layout key the widget already whitelisted. |
| 50 |
* @return string |
| 51 |
*/ |
| 52 |
public static function template_file( $layout ): string { |
| 53 |
if ( ! defined( 'BETTER_PAYMENT_PRO_ADMIN_VIEWS_PATH' ) ) { |
| 54 |
return ''; |
| 55 |
} |
| 56 |
|
| 57 |
return (string) constant( 'BETTER_PAYMENT_PRO_ADMIN_VIEWS_PATH' ) . '/elementor/layouts/' . $layout . '.php'; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* The payment type (layouts 4 and 5) and eCommerce platform (layout 6) a Pro layout renders with. |
| 62 |
* |
| 63 |
* @param array $settings Payment Form widget settings. |
| 64 |
* @return array{is_payment_recurring: int, is_payment_split_payment: int, payment_type_text: string, is_layout_for_woocommerce: int, is_layout_for_fluentcart: int} |
| 65 |
*/ |
| 66 |
public static function layout_vars( $settings ): array { |
| 67 |
return [ |
| 68 |
'is_payment_recurring' => ! empty( $settings["better_payment_form_payment_type"] ) && 'recurring' === $settings["better_payment_form_payment_type"] ? 1 : 0, |
| 69 |
'is_payment_split_payment' => ! empty( $settings["better_payment_form_payment_type"] ) && 'split-payment' === $settings["better_payment_form_payment_type"] ? 1 : 0, |
| 70 |
'payment_type_text' => ! empty( $settings["better_payment_form_payment_type"] ) ? sanitize_text_field( $settings["better_payment_form_payment_type"] ) : 'One Time', |
| 71 |
'is_layout_for_woocommerce' => ! empty( $settings["better_payment_form_layout"] ) && in_array( $settings["better_payment_form_layout"], ['layout-6-pro'] ) && ( empty( $settings["better_payment_form_layout_6_ecommerce_platform"] ) || 'woocommerce' === $settings["better_payment_form_layout_6_ecommerce_platform"] ) ? 1 : 0, |
| 72 |
'is_layout_for_fluentcart' => ! empty( $settings["better_payment_form_layout"] ) && 'layout-6-pro' === $settings["better_payment_form_layout"] && ! empty( $settings["better_payment_form_layout_6_ecommerce_platform"] ) && 'fluentcart' === $settings["better_payment_form_layout_6_ecommerce_platform"] ? 1 : 0, |
| 73 |
]; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* The form-field repeater a Pro layout reads its dynamic default amount from. |
| 78 |
* |
| 79 |
* @param array $settings Payment Form widget settings. |
| 80 |
* @return mixed The repeater rows, or an empty array. |
| 81 |
*/ |
| 82 |
public static function default_text_items( $settings ) { |
| 83 |
$items = []; |
| 84 |
$layout = ! empty( $settings["better_payment_form_layout"] ) ? $settings["better_payment_form_layout"] : ''; |
| 85 |
|
| 86 |
switch( $layout ) { |
| 87 |
case 'layout-4-pro': |
| 88 |
$items = ! empty( $settings['better_payment_form_fields_layout_4_5_6'] ) ? $settings['better_payment_form_fields_layout_4_5_6'] : []; |
| 89 |
break; |
| 90 |
case 'layout-5-pro': |
| 91 |
$items = ! empty( $settings['better_payment_form_fields_layout_4_5_6_desc'] ) ? $settings['better_payment_form_fields_layout_4_5_6_desc'] : []; |
| 92 |
break; |
| 93 |
case 'layout-6-pro': |
| 94 |
$items = ! empty( $settings['better_payment_form_fields_layout_4_5_6_woo'] ) ? $settings['better_payment_form_fields_layout_4_5_6_woo'] : []; |
| 95 |
break; |
| 96 |
|
| 97 |
default: |
| 98 |
break; |
| 99 |
} |
| 100 |
|
| 101 |
return $items; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Print the amount list of layouts 4 and 5 (`better_payment_amount_layout_4_5_6`). |
| 106 |
* |
| 107 |
* @param \Elementor\Widget_Base $widget The Payment Form widget. |
| 108 |
* @param array $settings Payment Form widget settings. |
| 109 |
* @return void |
| 110 |
*/ |
| 111 |
public static function render_amount_element( $widget, $settings ) { |
| 112 |
$items = ! empty( $settings['better_payment_amount_layout_4_5_6'] ) && is_array( $settings['better_payment_amount_layout_4_5_6'] ) ? $settings['better_payment_amount_layout_4_5_6'] : []; |
| 113 |
|
| 114 |
$layout_form_currency_symbol = $widget->get_currency_symbol( esc_html( ! empty( $settings[ 'better_payment_form_currency' ] ) ? $settings[ 'better_payment_form_currency' ] : '' ) ); |
| 115 |
$currency_alignment = ! empty ( $settings['better_payment_form_currency_alignment'] ) ? $settings['better_payment_form_currency_alignment'] : 'left'; |
| 116 |
$layout_form_currency_left = 'left' === $currency_alignment ? $layout_form_currency_symbol : ''; |
| 117 |
$layout_form_currency_right = 'right' === $currency_alignment ? $layout_form_currency_symbol : '' ; |
| 118 |
|
| 119 |
foreach ( $items as $item ) { |
| 120 |
$uid = uniqid(); |
| 121 |
?> |
| 122 |
<label class="payment-amount"> |
| 123 |
<input type="radio" value="<?php echo floatval( $item[ 'better_payment_amount_val' ] ); ?>" |
| 124 |
id="bp_payment_amount-<?php echo esc_attr($uid); ?>" class="bp-form__control bp-form_pay-radio " |
| 125 |
name="primary_payment_amount_radio"> |
| 126 |
<span class="text"><?php printf( "%s%s%s", esc_html( $layout_form_currency_left ), floatval( $item[ 'better_payment_amount_val' ] ), esc_html( $layout_form_currency_right ) ); ?></span> |
| 127 |
</label> |
| 128 |
|
| 129 |
<?php |
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|