PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.7
11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 10.11.4 All 201 releases
booking / includes / _capacity / confirmation.php

confirmation.php in Booking Calendar 10.15.7, at includes/_capacity/confirmation.php

403 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // FixIn: 9.8.0.4.
4
5 // ---------------------------------------------------------------------------------------------------------------------
6 // == Get Booking Confirmation Data
7 // ---------------------------------------------------------------------------------------------------------------------
8
9 /**
10 * Get confirmation parameters for booking confimration window
11 *
12 * @param array $params_arr = [
13 * 'booking_id' => 0, // 16102023
14 * 'resource_id' => 1,
15 * 'form_data' => '', // 'text^selected_short_dates_hint11^Sun...',
16 * 'dates_ymd_arr' => array(), // [ '2023-10-20', '2023-10-25' ]
17 * 'times_his_arr' => array(), // [ '16:00:01', '18:00:02' ]
18 *
19 * 'total_cost' => 0, Optional.
20 * 'deposit_cost' => 0, Optional.
21 *
22 * 'booking_summary' => '', Optional.
23 * 'gateway_rows' => '' Optional.
24 * ]
25 *
26 * @return array
27 */
28 function wpbc_booking_confirmation( $params_arr ){
29
30 $defaults = array(
31 'booking_id' => 0, // 16102023
32 'resource_id' => 1,
33 'form_data' => '', // 'text^selected_short_dates_hint11^Sun...',
34 'dates_ymd_arr' => array(), // [ '2023-10-20', '2023-10-25' ]
35 'times_his_arr' => array(), // [ '16:00:01', '18:00:02' ]
36
37 'total_cost' => 0, // 143.991
38 'deposit_cost' => 0, // 14.3991
39
40 'booking_summary' => '', // '<p>Dear John, please make payment for your booking...'
41 'gateway_rows' => '', // [ [ gateway_id = "stripe_v3", payment_params = [...] , is_for_deposit = 0, output = '<div class="stripe_v3_div...' ], .... ]
42
43 // Optional !
44 'is_show_coupon_discount_text' => true,
45 'ty_is_redirect' => esc_js( get_bk_option( 'booking_type_of_thank_you_message' ) ) // 'message' | 'page'
46 );
47 $params_arr = wp_parse_args( $params_arr, $defaults );
48
49
50 $str_dates__dd_mm_yyyy = wpbc_convert_dates_arr__yyyy_mm_dd__to__dd_mm_yyyy( $params_arr['dates_ymd_arr'] ); // ['2023-10-20','2023-10-25'] => ['20.10.2023','25.10.2023']
51 $params_arr['str_dates__dd_mm_yyyy'] = implode( ',', $str_dates__dd_mm_yyyy ); // REQUIRED -- '14.11.2023, 15.11.2023, 16.11.2023, 17.11.2023'
52 $params_arr['times_array'] = array(
53 explode( ':', $params_arr['times_his_arr'][0] ), // ["10","00","00"]
54 explode( ':', $params_arr['times_his_arr'][1] ) // ["12","00","00"]
55 );
56
57
58 // -- Booking Hash -------------------------------------------------------------------------------------------------
59 $booking_hash = '';
60 $hash__arr = wpbc_hash__get_booking_hash__resource_id( $params_arr['booking_id'] ); // Get booking hash
61 if ( ! empty( $hash__arr ) ) {
62 list( $booking_hash, $resource_id ) = $hash__arr;
63 }
64
65
66 $confirmation = array();
67 // $confirmation['hash'] = $booking_hash;
68 $confirmation['ty_is_redirect'] = $params_arr['ty_is_redirect'];
69
70
71 if ( 0 ) {
72 // TODO: Probably all this info, we already had? (2023-10-06 18:10). Optimize and refactor this function, which used in page-gateways.php file in wpbc_get_gateway_forms( $blank, $params ) during generating payment forms.
73 // $replace_params = wpbc_get_booking_different_params_arr( $params_arr['booking_id'], $params_arr['form_data'], $params_arr['resource_id'] );
74 // TODO: make this function universal for all emails and for other purpose
75 // $booking_params_like_in_email = wpbc__get_replace_shortcodes__email_new_admin( $params_arr['booking_id'] , $params_arr['resource_id'] , $params_arr['form_data'] );
76 /**
77 * [ booking_id = {int} 3945
78 id = {int} 3945
79 dates = "Wed, Nov 1, 2023 10:00 - Wed, Nov 1, 2023 12:00"
80 ...
81 is_new = "1"
82 status = ""
83 sort_date = "2023-11-01 10:00:01"
84 creation_date = "2023-10-06 17:51:49"
85 pay_status = "169660391431.09"
86 pay_request = "0"
87 booking_featured_image = {int} 0
88 * ]
89 */
90 }
91
92
93 // =================================================================================================================
94 // == Confirmation data == / TY - Thank you /
95 // =================================================================================================================
96
97 $replace_arr = wpbc__get_replace_shortcodes__email_new_visitor( $params_arr['booking_id'], $params_arr['resource_id'], $params_arr['form_data'] );
98
99
100 $replace_arr['readable_dates'] = '<div class="wpbc_ty__section_text_dates">'. wpbc_get_redable_dates( $params_arr['dates_ymd_arr'] ) . '</div>';
101 $replace_arr['readable_times'] = '';
102 if (
103 ( wpbc_transform__24_hours_his__in__seconds( $params_arr['times_his_arr'][0] ) > 0 )
104 && ( wpbc_transform__24_hours_his__in__seconds( $params_arr['times_his_arr'][0] ) < 86400 )
105 ) {
106 // -- Times text --
107 $replace_arr['readable_times'] = '<div class="wpbc_ty__section_text_times">' . wpbc_get_redable_times( $params_arr['dates_ymd_arr'], $params_arr['times_his_arr'] ) . '</div>';
108 }
109
110 $is_no_date = apply_filters( 'wpbc_maybe_no_booking_date', false, $params_arr['dates_ymd_arr'] );
111 if ( $is_no_date ) {
112 $replace_arr['readable_dates'] = '<div class="wpbc_ty__section_text_dates">---</div>';
113 $replace_arr['readable_times'] = '';
114 }
115
116 // Top - Thank you
117 $title_after_reservation = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_title_after_reservation' ) ) ) );
118 $title_after_reservation = wpbc_replace_booking_shortcodes( $title_after_reservation, $replace_arr, ' --- ' );
119 $title_after_reservation = stripslashes( $title_after_reservation );
120 $title_after_reservation = wp_kses_post( $title_after_reservation ); // FixIn: 10.6.4.2.
121 $confirmation['ty_message'] = $title_after_reservation; // 'Thank you for booking!'
122
123 // -----------------------------------------------------------------------------------------------------------------
124 // Booking ID
125 // -----------------------------------------------------------------------------------------------------------------
126 $confirmation['ty_message_booking_id'] = '';
127 if ( 'Off' !== get_bk_option( 'booking_confirmation_header_enabled' ) ) {
128 $confirmation['ty_message_booking_id'] .= ( false !== get_bk_option( 'booking_confirmation_header' ) )
129 ? html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation_header' ) ) ) )
130 /* translators: 1: ... */
131 : sprintf( __( 'Your booking id: %s', 'booking' ), '<strong>[booking_id]</strong>' );
132 }
133 $confirmation['ty_message_booking_id'] = wpbc_replace_booking_shortcodes( $confirmation['ty_message_booking_id'], $replace_arr, ' --- ' );
134 $confirmation['ty_message_booking_id'] = stripslashes( $confirmation['ty_message_booking_id'] );
135 $confirmation['ty_message_booking_id'] = wp_kses_post( $confirmation['ty_message_booking_id'] ); // FixIn: 10.6.4.2.
136 //$confirmation['ty_message_booking_id'] = str_replace( '[booking_id]', $params_arr['booking_id'], $confirmation['ty_message_booking_id'] );
137
138 // -----------------------------------------------------------------------------------------------------------------
139 // -- Customer details --
140 // -----------------------------------------------------------------------------------------------------------------
141 //$plain_form_data_show = wpbc_get__booking_form_data__show( $params_arr['form_data'], $params_arr['resource_id'], array( 'unknown_shortcodes_replace_by' => ' ... ' ) );
142
143 $confirmation['ty_customer_details'] = '';
144 if ( 'Off' !== get_bk_option( 'booking_confirmation__personal_info__header_enabled' ) ) {
145 // Title
146 $section_title = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__personal_info__title' ) ) ) );
147 $confirmation['ty_customer_details'] .= '<div class="wpbc_ty__section_header">' . $section_title . '</div>';
148
149 // Content
150 $confirmation['ty_customer_details'] .= html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__personal_info__content' ) ) ) );
151 $confirmation['ty_customer_details'] = str_replace( array( "\\n", "\n" ), '<br>', $confirmation['ty_customer_details'] );
152 $confirmation['ty_customer_details'] = wpbc_replace_booking_shortcodes( $confirmation['ty_customer_details'], $replace_arr, ' --- ' );
153 }
154 $confirmation['ty_customer_details'] = wp_kses_post( $confirmation['ty_customer_details'] ); // FixIn: 10.6.4.2.
155
156 // -----------------------------------------------------------------------------------------------------------------
157 // -- Booking details --
158 // -----------------------------------------------------------------------------------------------------------------
159 $confirmation['ty_booking_details'] = '';
160 if ( 'Off' !== get_bk_option( 'booking_confirmation__booking_details__header_enabled' ) ) {
161 // Title
162 $section_title = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__booking_details__title' ) ) ) );
163 $confirmation['ty_booking_details'] .= '<div class="wpbc_ty__section_header">' . $section_title . '</div>';
164
165 // Content
166 $confirmation['ty_booking_details'] .= html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__booking_details__content' ) ) ) );
167 $confirmation['ty_booking_details'] = str_replace( array( "\\n", "\n" ), '<br>', $confirmation['ty_booking_details'] );
168 $confirmation['ty_booking_details'] = wpbc_replace_booking_shortcodes( $confirmation['ty_booking_details'], $replace_arr, ' --- ' );
169 }
170
171 $confirmation['ty_booking_details'] = wp_kses_post( $confirmation['ty_booking_details'] ); // FixIn: 10.6.4.2.
172
173 // -----------------------------------------------------------------------------------------------------------------
174 // -- Costs text --
175 // -----------------------------------------------------------------------------------------------------------------
176 $confirmation['ty_booking_costs'] = '';
177 $confirmation['payment_cost'] = '';
178
179 if ( class_exists('wpdev_bk_biz_s')) {
180
181 $is_deposit = ( $params_arr['total_cost'] != $params_arr['deposit_cost'] );
182
183 if ($is_deposit){
184 $confirmation['payment_cost'] = $params_arr['deposit_cost'];
185 } else {
186 $confirmation['payment_cost'] = $params_arr['total_cost'];
187 }
188
189
190 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs">';
191
192 // -------------------------------------------------------------------------------------------------------------
193 // -- Coupon Code Discounts --
194 // -------------------------------------------------------------------------------------------------------------
195 $coupon_discount_value = false;
196 if (
197 ( class_exists( 'wpdev_bk_biz_l' ) )
198 && ( $params_arr['is_show_coupon_discount_text'] )
199 ){
200
201 // Get al fields (again?) ? -> $payment_params['structured_booking_data_arr'] <- Use this or get the info again ?
202 $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $params_arr['form_data'], $params_arr['resource_id'] );
203 // Find filled coupon code field - if not found then we get [] otherwise [ 'discount' => ['value' => 'test', ... ] ]
204 $filtered_booking_data_arr = array_filter( $structured_booking_data_arr
205 , function ( $v ) {
206 return ( ( ! empty( $v['value'] ) ) && ( 'coupon' == $v['type'] ) );
207 } );
208
209 if ( ! empty( $filtered_booking_data_arr ) ) {
210
211 // Get total cost without discount.
212 $total_cost_without_discount = wpbc_calc__booking_cost( array(
213 'resource_id' => $params_arr['resource_id'] // '2'
214 , 'str_dates__dd_mm_yyyy' => $params_arr['str_dates__dd_mm_yyyy'] // '14.11.2023, 15.11.2023, 16.11.2023, 17.11.2023'
215 , 'times_array' => $params_arr['times_array'] // [ ["10","00","00"], ["12","00","00"] ]
216 , 'form_data' => $params_arr['form_data'] // 'text^selected_short_timedates_hint4^06/11/2018 14:00...'
217 , 'is_discount_calculate' => false // FixIn: 10.11.5.7. // Default true
218 , 'is_only_original_cost' => false // Default false
219 ) );
220 $total_cost_without_discount = floatval( $total_cost_without_discount ); // from double > float
221
222
223 $coupon_text_info = apply_bk_filter( 'wpdev_get_additional_description_about_coupons', ''
224 , $params_arr['resource_id'], $params_arr['str_dates__dd_mm_yyyy'], $params_arr['times_his_arr'], $params_arr['form_data'] );
225 $coupon_discount_value = apply_bk_filter( 'wpbc_get_coupon_code_discount_value', ''
226 , $params_arr['resource_id'], $params_arr['str_dates__dd_mm_yyyy'], $params_arr['times_his_arr'], $params_arr['form_data'] );
227
228 $coupon_text_info = str_replace( array( '[', ']' ), '', $coupon_text_info );
229
230 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs_header">';
231 $confirmation['ty_booking_costs'] .= __( 'Total Cost', 'booking' ) . ': ';
232 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $total_cost_without_discount
233 , $params_arr['resource_id']
234 );
235 // $confirmation['ty_booking_costs'] .= '<br/>';
236 // $confirmation['ty_booking_costs'] .= __( 'Discount', 'booking' ) . ': ';
237 // $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $coupon_discount_value
238 // , $params_arr['resource_id']
239 // );
240 $confirmation['ty_booking_costs'] .= '<br/>';
241 $confirmation['ty_booking_costs'] .= $coupon_text_info;
242 $confirmation['ty_booking_costs'] .= '<br/>';
243 $confirmation['ty_booking_costs'] .= '</div>';
244 }
245 }
246
247 // -- Deposit | Balance | Total --
248 if ( $is_deposit ){
249 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs_header">';
250 $confirmation['ty_booking_costs'] .= ( empty( $coupon_discount_value ) ) ? __( 'Total cost', 'booking' ) . ': ' : __( 'Subtotal cost', 'booking' ) . ': ';
251 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $params_arr['total_cost']
252 , $params_arr['resource_id']
253 );
254 $confirmation['ty_booking_costs'] .= '<br/>';
255 $confirmation['ty_booking_costs'] .= __( 'Deposit Due', 'booking' ). ': ';
256 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $params_arr['deposit_cost']
257 , $params_arr['resource_id']
258 );
259 $confirmation['ty_booking_costs'] .= '<br/>';
260 $confirmation['ty_booking_costs'] .= __( 'Balance Remaining', 'booking' ). ': ';
261 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( ($params_arr['total_cost'] - $params_arr['deposit_cost'] )
262 , $params_arr['resource_id']
263 );
264 $confirmation['ty_booking_costs'] .= '<br/>';
265 $confirmation['ty_booking_costs'] .= '</div>';
266 }
267
268
269 $confirmation['ty_booking_costs'] .= '</div>';
270
271
272 // ---------------------------------------------------------------------------------------------------------
273 // "Update Note" in booking with all datails. Again ?
274 // ---------------------------------------------------------------------------------------------------------
275 $cost_booking_note = preg_replace( "@(&lt;|<)br\s*/?(&gt;|>)(\r\n)?@", "\n", $confirmation['ty_booking_costs'] );
276 $cost_booking_note = wp_strip_all_tags( $cost_booking_note );
277 $cost_booking_note = str_replace( array( ' ', "\n " ), array( ' ', "\n" ), $cost_booking_note );
278
279 if ( ! empty( $params_arr['gateway_rows'] ) ) {
280
281 $is_add_timezone_offset = true;
282 $booking_note = wpbc_date_localized( gmdate( 'Y-m-d H:i:s' ), '[Y-m-d H:i]', $is_add_timezone_offset ) . ' ';
283
284 $booking_note .= ' ' . __( 'Payment section displayed', 'booking' );
285 if ( empty( $cost_booking_note ) ) {
286 foreach ( $params_arr['gateway_rows'] as $row_num => $gateway_row ) {
287 $booking_note .= ' | ' . wp_strip_all_tags( html_entity_decode( $gateway_row['header'] ) );
288 }
289 }
290 $booking_note .= "\n";
291
292 if ( false !== strpos( $cost_booking_note, "\n" ) ) { $booking_note .= '-----------------------------------------' . "\n"; }
293 $booking_note .= $cost_booking_note;
294 if ( false !== strpos( $cost_booking_note, "\n" ) ) { $booking_note .= "\n" . '-----------------------------------------' . "\n"; }
295
296 make_bk_action( 'wpdev_make_update_of_remark', $params_arr['booking_id'], $booking_note, true );
297 }
298 // TODO: 2. what about additional calendars payment forms ?. It has to be returned from wpbc_get_gateway_forms() with -> 'payment_form_target': ' target="_blank" '
299
300
301 // -------------------------------------------------------------------------------------------------------------
302 // -- Payment gateways
303 // -------------------------------------------------------------------------------------------------------------
304 $confirmation['ty_payment_gateways'] = '';
305 $confirmation['ty_payment_payment_description'] = '';
306 if ( ! empty( $params_arr['booking_summary'] ) ) {
307 $confirmation['ty_payment_payment_description'] = $params_arr['booking_summary'];
308 }
309
310 if (
311 (
312 ( 'On' !== get_bk_option( 'booking_payment_form_in_request_only' ) )
313 || ( ! empty( $params_arr['booking_payment_form_in_request_only'] ) )
314 )
315 && ( ! empty( $params_arr['gateway_rows'] ) )
316 ){
317
318 $is_show_both_deposit_and_total = ( ( 'On' == get_bk_option( 'booking_show_deposit_and_total_payment' ) ) && ( $is_deposit ) );
319
320 foreach ( $params_arr['gateway_rows'] as $row_num => $gateway_row ) {
321
322 $ty_payment_gateways_before = '';
323 $ty_payment_gateways_after = '';
324
325 // Cost Header
326 $ty_payment_gateways_before .= '<div class="wpbc_ty__gateway ">';
327 $ty_payment_gateways_before .= '<h4 class="wpbc_ty__section_text_costs_header" style="margin-left: auto;margin-right: 1.5em;">';
328 $ty_payment_gateways_before .= $params_arr['gateway_rows'][ $row_num ]['header'];
329 $ty_payment_gateways_before .= '</h4>';
330 $ty_payment_gateways_before .= '</div>';
331
332 // Gateways Buttons
333 foreach ( $params_arr['gateway_rows'][ $row_num ]['gateways_arr'] as $payment_gateway ) {
334
335 /**
336 * $payment_gateway['payment_params'] = [ booking_id = "3842"
337 id = "3842"
338 days_input_format = "10.12.2023"
339 days_only_sql = "2023-12-10"
340 ...
341 visitorbookingediturl = "http://beta/wpbc-my-booking/?booking_hash=65410858c2dcab4298ad7494d65b8ab0"
342 ]
343 * $payment_gateway['gateway_id'] = stripe_v3
344 */
345
346 if ( ! in_array( $payment_gateway['gateway_id'], array( 'bank_transfer', 'pay_cash' ) ) ) {
347
348 if ( ( $is_show_both_deposit_and_total )
349 && ( $params_arr['gateway_rows'][ $row_num ]['is_for_deposit'] )
350 && ( in_array( $payment_gateway['gateway_id'], array( 'stripe_v3' ) ) ) ) {
351
352 // Skip 'Stripe' for showing total cost, if activated both "Total | Deposit", because we can show only 1 button
353
354 } else {
355 $ty_payment_gateways_before .= '<div class="wpbc_ty__gateway wpbc_col_auto_width">'
356 . $payment_gateway['output']
357 . '</div>';
358 }
359 } else {
360
361 $ty_payment_gateways_after .= '<div class="wpbc_ty__gateway">'
362 . $payment_gateway['output']
363 . '</div>';
364 }
365 }
366
367 $confirmation['ty_payment_gateways'] .= $ty_payment_gateways_before . $ty_payment_gateways_after;
368 }
369 }
370 }
371
372
373 // FixIn: 10.10.3.3.
374 // // If showing payment form, that we do not make redirection and show Message only.
375 // if ( ! empty( $confirmation['ty_payment_gateways'] ) ) {
376 // $confirmation['ty_is_redirect'] = 'message';
377 // }
378
379 if ( 'page' == $confirmation['ty_is_redirect'] ) {
380
381 // FixIn: 9.9.0.3.
382 if ( ! empty( $params_arr['ty_url'] ) ) {
383
384 $confirmation['ty_url'] = $params_arr['ty_url'];
385
386 } else {
387
388 $confirmation['ty_url'] = wpbc_make_link_absolute( wpbc_lang( get_bk_option( 'booking_thank_you_page_URL' ) ) ); // '/thank-you'
389
390 $confirmation['ty_url'] .= ( ( false === strpos( $confirmation['ty_url'], '?' ) ) ? '?' : '&' ) . 'booking_hash=' . $booking_hash;
391
392 // FixIn: 10.10.3.3.
393 if ( ! empty( $confirmation['ty_payment_gateways'] ) ) {
394 $confirmation['ty_url'] .= ( ( false === strpos( $confirmation['ty_url'], '?' ) ) ? '?' : '&' ) . 'booking_pay=1';
395 }
396 }
397
398 } else {
399 $confirmation['ty_url'] = '';
400 }
401
402 return $confirmation;
403 }