| 1 |
<?php |
| 2 |
$bp_helper_obj = new Better_Payment\Lite\Classes\Helper(); |
| 3 |
$layout_action = !empty($extraDatas['action']) ? $extraDatas['action'] : ''; |
| 4 |
$layout_setting_meta = !empty($extraDatas['setting_meta']) ? $extraDatas['setting_meta'] : ''; |
| 5 |
$layout_dynamic_payment_hide_show = !empty($settings["better_payment_form_payment_source"]) && !in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? 'is-hidden' : ''; |
| 6 |
$layout_put_amount_field_hide_show = !empty($settings["better_payment_form_payment_source"]) && in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? 'is-hidden' : ''; |
| 7 |
$layout_form_content_offset_class = !empty($settings["better_payment_form_payment_source"]) && !in_array($settings["better_payment_form_payment_source"], ['woocommerce', 'fluentcart']) ? '' : ''; //is-offset-2 |
| 8 |
|
| 9 |
$layout_form_transaction_details_heading = !empty($settings["better_payment_form_transaction_details_heading"]) ? $settings["better_payment_form_transaction_details_heading"] : ''; |
| 10 |
$layout_form_transaction_details_sub_heading = !empty($settings["better_payment_form_transaction_details_sub_heading"]) ? $settings["better_payment_form_transaction_details_sub_heading"] : ''; |
| 11 |
$layout_form_transaction_details_product_title = !empty($settings["better_payment_form_transaction_details_product_title"]) ? $settings["better_payment_form_transaction_details_product_title"] : ''; |
| 12 |
$layout_form_transaction_details_amount_text = !empty($settings["better_payment_form_transaction_details_amount_text"]) ? $settings["better_payment_form_transaction_details_amount_text"] : ''; |
| 13 |
$is_payment_type_woocommerce = !empty($settings["better_payment_form_payment_source"]) && 'woocommerce' === $settings["better_payment_form_payment_source"] ? true : false; |
| 14 |
$is_payment_type_fluentcart = !empty($settings["better_payment_form_payment_source"]) && 'fluentcart' === $settings["better_payment_form_payment_source"] ? true : false; |
| 15 |
$is_payment_type_stripe = !empty($settings["better_payment_form_payment_source"]) && 'stripe' === $settings["better_payment_form_payment_source"] ? true : false; |
| 16 |
$is_payment_recurring = ! empty( $settings["better_payment_form_payment_type"] ) && 'recurring' === $settings["better_payment_form_payment_type"] ? 1 : 0; |
| 17 |
$is_payment_split_payment = ! empty( $settings["better_payment_form_payment_type"] ) && 'split-payment' === $settings["better_payment_form_payment_type"] ? 1 : 0; |
| 18 |
$payment_type_text = ! empty( $settings["better_payment_form_payment_type"] ) ? sanitize_text_field( $settings["better_payment_form_payment_type"] ) : 'One Time'; |
| 19 |
$layout_put_amount_field_hide_show = ( $is_payment_recurring || $is_payment_split_payment ) ? 'is-hidden' : $layout_put_amount_field_hide_show; |
| 20 |
$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; |
| 21 |
$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; |
| 22 |
|
| 23 |
if( !empty($_GET[ 'campaign_currency' ]) ) { |
| 24 |
$layout_form_currency = sanitize_text_field( $_GET[ 'campaign_currency' ] ); |
| 25 |
} else { |
| 26 |
$layout_form_currency = !empty($settings["better_payment_form_currency"]) ? sanitize_text_field( $settings["better_payment_form_currency"] ) : ''; |
| 27 |
} |
| 28 |
|
| 29 |
$layout_form_currency_symbol = $layout_form_currency ? $bp_helper_obj->get_currency_symbol(esc_html($layout_form_currency)) : '<i class="bp-icon bp-logo-2"></i>'; |
| 30 |
|
| 31 |
$currency_alignment = ! empty ( $settings['better_payment_form_currency_alignment'] ) ? $settings['better_payment_form_currency_alignment'] : 'left'; |
| 32 |
|
| 33 |
$product_details = []; |
| 34 |
$product_name = ''; |
| 35 |
$product_permalink = ''; |
| 36 |
$product_price = ''; |
| 37 |
$payment_amount_field_exists = 0; |
| 38 |
$is_payment_amount_field_hidden = 0; |
| 39 |
$valid_html_tags = wp_kses_allowed_html( 'post' ); |
| 40 |
$sidebar_show = ! empty( $settings['better_payment_form_sidebar_show'] ) && 'yes' === $settings['better_payment_form_sidebar_show']; |
| 41 |
if ( $is_payment_type_woocommerce || $is_layout_for_woocommerce ) { |
| 42 |
if( |
| 43 |
!empty($settings['better_payment_form_currency_use_woocommerce']) && 'yes' === $settings['better_payment_form_currency_use_woocommerce'] && |
| 44 |
!empty($settings['better_payment_form_currency_woocommerce']) |
| 45 |
) { |
| 46 |
$layout_form_currency_symbol = $bp_helper_obj->get_currency_symbol( esc_html($settings['better_payment_form_currency_woocommerce']) ); |
| 47 |
} |
| 48 |
|
| 49 |
//Fetch product data using product ID |
| 50 |
$layout_form_woocommerce_product_id = !empty($settings["better_payment_form_woocommerce_product_id"]) ? intval($settings["better_payment_form_woocommerce_product_id"]) : 0; |
| 51 |
$layout_form_woocommerce_product_ids = !empty($settings["better_payment_form_woocommerce_product_ids"]) ? $settings["better_payment_form_woocommerce_product_ids"] : [0]; |
| 52 |
$product_price_total = 0; |
| 53 |
|
| 54 |
if (function_exists('wc_get_product')) { |
| 55 |
if ( $is_layout_for_woocommerce ) { |
| 56 |
$product_details = []; |
| 57 |
|
| 58 |
foreach( $layout_form_woocommerce_product_ids as $single_product_id ){ |
| 59 |
$bp_woocommerce_product = wc_get_product($single_product_id); |
| 60 |
$product = $bp_woocommerce_product; |
| 61 |
|
| 62 |
if ($product) { |
| 63 |
$product_details[$single_product_id]['product_name'] = $product->get_name(); |
| 64 |
$product_details[$single_product_id]['product_permalink'] = get_permalink($product->get_id()); |
| 65 |
$product_details[$single_product_id]['product_price'] = $product->get_price(); |
| 66 |
$product_details[$single_product_id]['product_image_src_array'] = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' ); |
| 67 |
|
| 68 |
$product_image_src_array = $product_details[$single_product_id]['product_image_src_array']; |
| 69 |
$product_details[$single_product_id]['product_image_src'] = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; |
| 70 |
|
| 71 |
$product_price_total += floatval( $product_details[$single_product_id]['product_price'] ); |
| 72 |
} |
| 73 |
} |
| 74 |
} else { |
| 75 |
$bp_woocommerce_product = wc_get_product($layout_form_woocommerce_product_id); |
| 76 |
$product = $bp_woocommerce_product; |
| 77 |
|
| 78 |
if ($product) { |
| 79 |
$product_name = $product->get_name(); |
| 80 |
$product_permalink = get_permalink($product->get_id()); |
| 81 |
$product_price = $product->get_price(); |
| 82 |
$product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $product->get_id() ), 'single-post-thumbnail' ); |
| 83 |
$product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
if ( $is_payment_type_fluentcart || $is_layout_for_fluentcart ) { |
| 90 |
$layout_form_fluentcart_product_id = !empty($settings["better_payment_form_fluentcart_product_id"]) ? intval($settings["better_payment_form_fluentcart_product_id"]) : 0; |
| 91 |
$layout_form_fluentcart_product_ids = !empty($settings["better_payment_form_fluentcart_product_ids"]) ? $settings["better_payment_form_fluentcart_product_ids"] : [0]; |
| 92 |
$product_price_total = 0; |
| 93 |
|
| 94 |
if (function_exists('fluentCart') && class_exists( '\FluentCart\App\Models\Product' ) ) { |
| 95 |
if ( $is_layout_for_fluentcart ) { |
| 96 |
$product_details = []; |
| 97 |
|
| 98 |
foreach( $layout_form_fluentcart_product_ids as $single_product_id ){ |
| 99 |
try { |
| 100 |
$fluentcart_product = \FluentCart\App\Models\Product::query() |
| 101 |
->with(['detail', 'variants']) |
| 102 |
->find($single_product_id); |
| 103 |
|
| 104 |
if ($fluentcart_product) { |
| 105 |
$product_details[$single_product_id]['product_name'] = $fluentcart_product->post_title; |
| 106 |
$product_details[$single_product_id]['product_permalink'] = get_permalink($fluentcart_product->ID); |
| 107 |
|
| 108 |
$fluentcart_price = 0; |
| 109 |
if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) { |
| 110 |
$fluentcart_price = $fluentcart_product->variants[0]->item_price; |
| 111 |
} elseif (!empty($fluentcart_product->detail)) { |
| 112 |
$fluentcart_price = $fluentcart_product->detail->min_price; |
| 113 |
} |
| 114 |
|
| 115 |
if ( ! empty( $fluentcart_price ) ) { |
| 116 |
$fluentcart_price = floatval( $fluentcart_price / 100 ); |
| 117 |
} |
| 118 |
|
| 119 |
$product_details[$single_product_id]['product_price'] = $fluentcart_price; |
| 120 |
$product_details[$single_product_id]['product_image_src_array'] = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' ); |
| 121 |
|
| 122 |
$product_image_src_array = $product_details[$single_product_id]['product_image_src_array']; |
| 123 |
$product_details[$single_product_id]['product_image_src'] = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; |
| 124 |
|
| 125 |
$product_price_total += floatval( $product_details[$single_product_id]['product_price'] ); |
| 126 |
} |
| 127 |
} catch (Exception $e) { |
| 128 |
// Handle exception silently |
| 129 |
} |
| 130 |
} |
| 131 |
} else { |
| 132 |
try { |
| 133 |
$fluentcart_product = \FluentCart\App\Models\Product::query() |
| 134 |
->with(['detail', 'variants']) |
| 135 |
->find($layout_form_fluentcart_product_id); |
| 136 |
|
| 137 |
if ($fluentcart_product) { |
| 138 |
$product_name = $fluentcart_product->post_title; |
| 139 |
$product_permalink = get_permalink($fluentcart_product->ID); |
| 140 |
|
| 141 |
$fluentcart_price = 0; |
| 142 |
if (!empty($fluentcart_product->variants) && count($fluentcart_product->variants) > 0) { |
| 143 |
$fluentcart_price = $fluentcart_product->variants[0]->item_price; |
| 144 |
} elseif (!empty($fluentcart_product->detail)) { |
| 145 |
$fluentcart_price = $fluentcart_product->detail->min_price; |
| 146 |
} |
| 147 |
|
| 148 |
if ( ! empty( $fluentcart_price ) ) { |
| 149 |
$fluentcart_price = floatval( $fluentcart_price / 100 ); |
| 150 |
} |
| 151 |
|
| 152 |
$product_price = $fluentcart_price; |
| 153 |
$product_image_src_array = wp_get_attachment_image_src( get_post_thumbnail_id( $fluentcart_product->ID ), 'single-post-thumbnail' ); |
| 154 |
$product_image_src = is_array( $product_image_src_array ) && count( $product_image_src_array ) ? $product_image_src_array[0] : ''; |
| 155 |
} |
| 156 |
} catch (Exception $e) { |
| 157 |
// Handle exception silently |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
$layout_form_currency_left = 'left' === $currency_alignment ? $layout_form_currency_symbol : ''; |
| 164 |
$layout_form_currency_right = 'right' === $currency_alignment ? $layout_form_currency_symbol : '' ; |
| 165 |
|
| 166 |
$stripe_public_key = 'yes' === sanitize_text_field( $settings[ 'better_payment_stripe_live_mode' ] ) ? sanitize_text_field( $settings[ 'better_payment_stripe_public_key_live' ] ) : sanitize_text_field( $settings[ 'better_payment_stripe_public_key' ] ); |
| 167 |
$stripe_secret_key = 'yes' === sanitize_text_field( $settings[ 'better_payment_stripe_live_mode' ] ) ? sanitize_text_field( $settings[ 'better_payment_stripe_secret_key_live' ] ) : sanitize_text_field( $settings[ 'better_payment_stripe_secret_key' ] ); |
| 168 |
$amount_quantity_text = ! empty( $settings['better_payment_show_amount_quantity_text'] ) ? $settings['better_payment_show_amount_quantity_text'] : 'Amount Quantity'; |
| 169 |
|
| 170 |
if ( $is_payment_type_stripe ) { |
| 171 |
$payment_source_stripe_price_id = ! empty( $settings['better_payment_form_payment_source_stripe_price_id'] ) ? sanitize_text_field( $settings['better_payment_form_payment_source_stripe_price_id'] ) : ''; |
| 172 |
|
| 173 |
$stripe_price_details = $bp_helper_obj->get_stripe_price_details( $payment_source_stripe_price_id, $stripe_secret_key ); |
| 174 |
|
| 175 |
if ( ! empty( $stripe_price_details ) ) { |
| 176 |
$product_price = ! empty( $stripe_price_details['unit_amount'] ) ? floatval( $stripe_price_details['unit_amount'] ) / 100 : ''; |
| 177 |
} |
| 178 |
} |
| 179 |
|