PluginProbe
Booking Calendar / 10.11
Booking Calendar v10.11
11.8.3 11.8.2 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 All 203 releases
booking / includes / _capacity / confirmation.php

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

396 lines 21.4 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 $replace_arr['readable_dates'] = '<div class="wpbc_ty__section_text_dates">'. wpbc_get_redable_dates( $params_arr['dates_ymd_arr'] ) . '</div>';
100 $replace_arr['readable_times'] = '';
101 if (
102 ( wpbc_transform__24_hours_his__in__seconds( $params_arr['times_his_arr'][0] ) > 0 )
103 && ( wpbc_transform__24_hours_his__in__seconds( $params_arr['times_his_arr'][0] ) < 86400 )
104 ) {
105 // -- Times text --
106 $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>';
107 }
108
109 // Top - Thank you
110 $title_after_reservation = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_title_after_reservation' ) ) ) );
111 $title_after_reservation = wpbc_replace_booking_shortcodes( $title_after_reservation, $replace_arr, ' --- ' );
112 $title_after_reservation = stripslashes( $title_after_reservation );
113 $title_after_reservation = wp_kses_post( $title_after_reservation ); // FixIn: 10.6.4.2.
114 $confirmation['ty_message'] = $title_after_reservation; // 'Thank you for booking!'
115
116 // -----------------------------------------------------------------------------------------------------------------
117 // Booking ID
118 // -----------------------------------------------------------------------------------------------------------------
119 $confirmation['ty_message_booking_id'] = '';
120 if ( 'Off' !== get_bk_option( 'booking_confirmation_header_enabled' ) ) {
121 $confirmation['ty_message_booking_id'] .= ( false !== get_bk_option( 'booking_confirmation_header' ) )
122 ? html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation_header' ) ) ) )
123 /* translators: 1: ... */
124 : sprintf( __( 'Your booking id: %s', 'booking' ), '<strong>[booking_id]</strong>' );
125 }
126 $confirmation['ty_message_booking_id'] = wpbc_replace_booking_shortcodes( $confirmation['ty_message_booking_id'], $replace_arr, ' --- ' );
127 $confirmation['ty_message_booking_id'] = stripslashes( $confirmation['ty_message_booking_id'] );
128 $confirmation['ty_message_booking_id'] = wp_kses_post( $confirmation['ty_message_booking_id'] ); // FixIn: 10.6.4.2.
129 //$confirmation['ty_message_booking_id'] = str_replace( '[booking_id]', $params_arr['booking_id'], $confirmation['ty_message_booking_id'] );
130
131 // -----------------------------------------------------------------------------------------------------------------
132 // -- Customer details --
133 // -----------------------------------------------------------------------------------------------------------------
134 //$plain_form_data_show = wpbc_get__booking_form_data__show( $params_arr['form_data'], $params_arr['resource_id'], array( 'unknown_shortcodes_replace_by' => ' ... ' ) );
135
136 $confirmation['ty_customer_details'] = '';
137 if ( 'Off' !== get_bk_option( 'booking_confirmation__personal_info__header_enabled' ) ) {
138 // Title
139 $section_title = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__personal_info__title' ) ) ) );
140 $confirmation['ty_customer_details'] .= '<div class="wpbc_ty__section_header">' . $section_title . '</div>';
141
142 // Content
143 $confirmation['ty_customer_details'] .= html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__personal_info__content' ) ) ) );
144 $confirmation['ty_customer_details'] = str_replace( array( "\\n", "\n" ), '<br>', $confirmation['ty_customer_details'] );
145 $confirmation['ty_customer_details'] = wpbc_replace_booking_shortcodes( $confirmation['ty_customer_details'], $replace_arr, ' --- ' );
146 }
147 $confirmation['ty_customer_details'] = wp_kses_post( $confirmation['ty_customer_details'] ); // FixIn: 10.6.4.2.
148
149 // -----------------------------------------------------------------------------------------------------------------
150 // -- Booking details --
151 // -----------------------------------------------------------------------------------------------------------------
152 $confirmation['ty_booking_details'] = '';
153 if ( 'Off' !== get_bk_option( 'booking_confirmation__booking_details__header_enabled' ) ) {
154 // Title
155 $section_title = html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__booking_details__title' ) ) ) );
156 $confirmation['ty_booking_details'] .= '<div class="wpbc_ty__section_header">' . $section_title . '</div>';
157
158 // Content
159 $confirmation['ty_booking_details'] .= html_entity_decode( esc_js( wpbc_lang( get_bk_option( 'booking_confirmation__booking_details__content' ) ) ) );
160 $confirmation['ty_booking_details'] = str_replace( array( "\\n", "\n" ), '<br>', $confirmation['ty_booking_details'] );
161 $confirmation['ty_booking_details'] = wpbc_replace_booking_shortcodes( $confirmation['ty_booking_details'], $replace_arr, ' --- ' );
162 }
163
164 $confirmation['ty_booking_details'] = wp_kses_post( $confirmation['ty_booking_details'] ); // FixIn: 10.6.4.2.
165
166 // -----------------------------------------------------------------------------------------------------------------
167 // -- Costs text --
168 // -----------------------------------------------------------------------------------------------------------------
169 $confirmation['ty_booking_costs'] = '';
170 $confirmation['payment_cost'] = '';
171
172 if ( class_exists('wpdev_bk_biz_s')) {
173
174 $is_deposit = ( $params_arr['total_cost'] != $params_arr['deposit_cost'] );
175
176 if ($is_deposit){
177 $confirmation['payment_cost'] = $params_arr['deposit_cost'];
178 } else {
179 $confirmation['payment_cost'] = $params_arr['total_cost'];
180 }
181
182
183 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs">';
184
185 // -------------------------------------------------------------------------------------------------------------
186 // -- Coupon Code Discounts --
187 // -------------------------------------------------------------------------------------------------------------
188 $coupon_discount_value = false;
189 if (
190 ( class_exists( 'wpdev_bk_biz_l' ) )
191 && ( $params_arr['is_show_coupon_discount_text'] )
192 ){
193
194 // Get al fields (again?) ? -> $payment_params['structured_booking_data_arr'] <- Use this or get the info again ?
195 $structured_booking_data_arr = wpbc_get_parsed_booking_data_arr( $params_arr['form_data'], $params_arr['resource_id'] );
196 // Find filled coupon code field - if not found then we get [] otherwise [ 'discount' => ['value' => 'test', ... ] ]
197 $filtered_booking_data_arr = array_filter( $structured_booking_data_arr
198 , function ( $v ) {
199 return ( ( ! empty( $v['value'] ) ) && ( 'coupon' == $v['type'] ) );
200 } );
201
202 if ( ! empty( $filtered_booking_data_arr ) ) {
203
204 // Get total cost without discount.
205 $total_cost_without_discount = wpbc_calc__booking_cost( array(
206 'resource_id' => $params_arr['resource_id'] // '2'
207 , 'str_dates__dd_mm_yyyy' => $params_arr['str_dates__dd_mm_yyyy'] // '14.11.2023, 15.11.2023, 16.11.2023, 17.11.2023'
208 , 'times_array' => $params_arr['times_array'] // [ ["10","00","00"], ["12","00","00"] ]
209 , 'form_data' => $params_arr['form_data'] // 'text^selected_short_timedates_hint4^06/11/2018 14:00...'
210 , 'is_discount_calculate' => ! true // Default true
211 , 'is_only_original_cost' => false // Default false
212 ) );
213 $total_cost_without_discount = floatval( $total_cost_without_discount ); // from double > float
214
215
216 $coupon_text_info = apply_bk_filter( 'wpdev_get_additional_description_about_coupons', ''
217 , $params_arr['resource_id'], $params_arr['str_dates__dd_mm_yyyy'], $params_arr['times_his_arr'], $params_arr['form_data'] );
218 $coupon_discount_value = apply_bk_filter( 'wpbc_get_coupon_code_discount_value', ''
219 , $params_arr['resource_id'], $params_arr['str_dates__dd_mm_yyyy'], $params_arr['times_his_arr'], $params_arr['form_data'] );
220
221 $coupon_text_info = str_replace( array( '[', ']' ), '', $coupon_text_info );
222
223 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs_header">';
224 $confirmation['ty_booking_costs'] .= __( 'Total Cost', 'booking' ) . ': ';
225 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $total_cost_without_discount
226 , $params_arr['resource_id']
227 );
228 // $confirmation['ty_booking_costs'] .= '<br/>';
229 // $confirmation['ty_booking_costs'] .= __( 'Discount', 'booking' ) . ': ';
230 // $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $coupon_discount_value
231 // , $params_arr['resource_id']
232 // );
233 $confirmation['ty_booking_costs'] .= '<br/>';
234 $confirmation['ty_booking_costs'] .= $coupon_text_info;
235 $confirmation['ty_booking_costs'] .= '<br/>';
236 $confirmation['ty_booking_costs'] .= '</div>';
237 }
238 }
239
240 // -- Deposit | Balance | Total --
241 if ( $is_deposit ){
242 $confirmation['ty_booking_costs'] .= '<div class="wpbc_ty__section_text_costs_header">';
243 $confirmation['ty_booking_costs'] .= ( empty( $coupon_discount_value ) ) ? __( 'Total cost', 'booking' ) . ': ' : __( 'Subtotal cost', 'booking' ) . ': ';
244 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $params_arr['total_cost']
245 , $params_arr['resource_id']
246 );
247 $confirmation['ty_booking_costs'] .= '<br/>';
248 $confirmation['ty_booking_costs'] .= __( 'Deposit Due', 'booking' ). ': ';
249 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( $params_arr['deposit_cost']
250 , $params_arr['resource_id']
251 );
252 $confirmation['ty_booking_costs'] .= '<br/>';
253 $confirmation['ty_booking_costs'] .= __( 'Balance Remaining', 'booking' ). ': ';
254 $confirmation['ty_booking_costs'] .= wpbc_get_cost_with_currency_for_user( ($params_arr['total_cost'] - $params_arr['deposit_cost'] )
255 , $params_arr['resource_id']
256 );
257 $confirmation['ty_booking_costs'] .= '<br/>';
258 $confirmation['ty_booking_costs'] .= '</div>';
259 }
260
261
262 $confirmation['ty_booking_costs'] .= '</div>';
263
264
265 // ---------------------------------------------------------------------------------------------------------
266 // "Update Note" in booking with all datails. Again ?
267 // ---------------------------------------------------------------------------------------------------------
268 $cost_booking_note = preg_replace( "@(&lt;|<)br\s*/?(&gt;|>)(\r\n)?@", "\n", $confirmation['ty_booking_costs'] );
269 $cost_booking_note = wp_strip_all_tags( $cost_booking_note );
270 $cost_booking_note = str_replace( array( ' ', "\n " ), array( ' ', "\n" ), $cost_booking_note );
271
272 if ( ! empty( $params_arr['gateway_rows'] ) ) {
273
274 $is_add_timezone_offset = true;
275 $booking_note = wpbc_date_localized( gmdate( 'Y-m-d H:i:s' ), '[Y-m-d H:i]', $is_add_timezone_offset ) . ' ';
276
277 $booking_note .= ' ' . __( 'Payment section displayed', 'booking' );
278 if ( empty( $cost_booking_note ) ) {
279 foreach ( $params_arr['gateway_rows'] as $row_num => $gateway_row ) {
280 $booking_note .= ' | ' . wp_strip_all_tags( html_entity_decode( $gateway_row['header'] ) );
281 }
282 }
283 $booking_note .= "\n";
284
285 if ( false !== strpos( $cost_booking_note, "\n" ) ) { $booking_note .= '-----------------------------------------' . "\n"; }
286 $booking_note .= $cost_booking_note;
287 if ( false !== strpos( $cost_booking_note, "\n" ) ) { $booking_note .= "\n" . '-----------------------------------------' . "\n"; }
288
289 make_bk_action( 'wpdev_make_update_of_remark', $params_arr['booking_id'], $booking_note, true );
290 }
291 // TODO: 2. what about additional calendars payment forms ?. It has to be returned from wpbc_get_gateway_forms() with -> 'payment_form_target': ' target="_blank" '
292
293
294 // -------------------------------------------------------------------------------------------------------------
295 // -- Payment gateways
296 // -------------------------------------------------------------------------------------------------------------
297 $confirmation['ty_payment_gateways'] = '';
298 $confirmation['ty_payment_payment_description'] = '';
299 if ( ! empty( $params_arr['booking_summary'] ) ) {
300 $confirmation['ty_payment_payment_description'] = $params_arr['booking_summary'];
301 }
302
303 if (
304 (
305 ( 'On' !== get_bk_option( 'booking_payment_form_in_request_only' ) )
306 || ( ! empty( $params_arr['booking_payment_form_in_request_only'] ) )
307 )
308 && ( ! empty( $params_arr['gateway_rows'] ) )
309 ){
310
311 $is_show_both_deposit_and_total = ( ( 'On' == get_bk_option( 'booking_show_deposit_and_total_payment' ) ) && ( $is_deposit ) );
312
313 foreach ( $params_arr['gateway_rows'] as $row_num => $gateway_row ) {
314
315 $ty_payment_gateways_before = '';
316 $ty_payment_gateways_after = '';
317
318 // Cost Header
319 $ty_payment_gateways_before .= '<div class="wpbc_ty__gateway ">';
320 $ty_payment_gateways_before .= '<h4 class="wpbc_ty__section_text_costs_header" style="margin-left: auto;margin-right: 1.5em;">';
321 $ty_payment_gateways_before .= $params_arr['gateway_rows'][ $row_num ]['header'];
322 $ty_payment_gateways_before .= '</h4>';
323 $ty_payment_gateways_before .= '</div>';
324
325 // Gateways Buttons
326 foreach ( $params_arr['gateway_rows'][ $row_num ]['gateways_arr'] as $payment_gateway ) {
327
328 /**
329 * $payment_gateway['payment_params'] = [ booking_id = "3842"
330 id = "3842"
331 days_input_format = "10.12.2023"
332 days_only_sql = "2023-12-10"
333 ...
334 visitorbookingediturl = "http://beta/wpbc-my-booking/?booking_hash=65410858c2dcab4298ad7494d65b8ab0"
335 ]
336 * $payment_gateway['gateway_id'] = stripe_v3
337 */
338
339 if ( ! in_array( $payment_gateway['gateway_id'], array( 'bank_transfer', 'pay_cash' ) ) ) {
340
341 if ( ( $is_show_both_deposit_and_total )
342 && ( $params_arr['gateway_rows'][ $row_num ]['is_for_deposit'] )
343 && ( in_array( $payment_gateway['gateway_id'], array( 'stripe_v3' ) ) ) ) {
344
345 // Skip 'Stripe' for showing total cost, if activated both "Total | Deposit", because we can show only 1 button
346
347 } else {
348 $ty_payment_gateways_before .= '<div class="wpbc_ty__gateway wpbc_col_auto_width">'
349 . $payment_gateway['output']
350 . '</div>';
351 }
352 } else {
353
354 $ty_payment_gateways_after .= '<div class="wpbc_ty__gateway">'
355 . $payment_gateway['output']
356 . '</div>';
357 }
358 }
359
360 $confirmation['ty_payment_gateways'] .= $ty_payment_gateways_before . $ty_payment_gateways_after;
361 }
362 }
363 }
364
365
366 // FixIn: 10.10.3.3.
367 // // If showing payment form, that we do not make redirection and show Message only.
368 // if ( ! empty( $confirmation['ty_payment_gateways'] ) ) {
369 // $confirmation['ty_is_redirect'] = 'message';
370 // }
371
372 if ( 'page' == $confirmation['ty_is_redirect'] ) {
373
374 // FixIn: 9.9.0.3.
375 if ( ! empty( $params_arr['ty_url'] ) ) {
376
377 $confirmation['ty_url'] = $params_arr['ty_url'];
378
379 } else {
380
381 $confirmation['ty_url'] = wpbc_make_link_absolute( wpbc_lang( get_bk_option( 'booking_thank_you_page_URL' ) ) ); // '/thank-you'
382
383 $confirmation['ty_url'] .= ( ( false === strpos( $confirmation['ty_url'], '?' ) ) ? '?' : '&' ) . 'booking_hash=' . $booking_hash;
384
385 // FixIn: 10.10.3.3.
386 if ( ! empty( $confirmation['ty_payment_gateways'] ) ) {
387 $confirmation['ty_url'] .= ( ( false === strpos( $confirmation['ty_url'], '?' ) ) ? '?' : '&' ) . 'booking_pay=1';
388 }
389 }
390
391 } else {
392 $confirmation['ty_url'] = '';
393 }
394
395 return $confirmation;
396 }