PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
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.1.3, at includes/_capacity/confirmation.php

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