· 5 years ago · Mar 12, 2020, 10:26 PM
1<?php
2add_action( 'wp_ajax_nopriv_homey_add_hourly_reservation', 'homey_add_hourly_reservation' );
3add_action( 'wp_ajax_homey_add_hourly_reservation', 'homey_add_hourly_reservation' );
4if( !function_exists('homey_add_hourly_reservation') ) {
5 function homey_add_hourly_reservation() {
6 global $current_user;
7 $current_user = wp_get_current_user();
8 $userID = $current_user->ID;
9 $local = homey_get_localization();
10 $allowded_html = array();
11 $reservation_meta = array();
12
13 $listing_id = intval($_POST['listing_id']);
14 $listing_owner_id = get_post_field( 'post_author', $listing_id );
15 $check_in_date = wp_kses ( $_POST['check_in_date'], $allowded_html );
16 $start_hour = wp_kses ( $_POST['start_hour'], $allowded_html );
17 $end_hour = wp_kses ( $_POST['end_hour'], $allowded_html );
18 $guests = intval($_POST['guests']);
19 $extra_options = $_POST['extra_options'];
20 $guest_message = stripslashes ( $_POST['guest_message'] );
21 $title = $local['reservation_text'];
22
23 $check_in_hour = $check_in_date.' '.$start_hour;
24 $check_out_hour = $check_in_date.' '.$end_hour;
25
26 $owner = homey_usermeta($listing_owner_id);
27 $owner_email = $owner['email'];
28
29 if ( !is_user_logged_in() || $userID === 0 ) {
30 echo json_encode(
31 array(
32 'success' => false,
33 'message' => $local['login_for_reservation']
34 )
35 );
36 wp_die();
37 }
38
39 if($userID == $listing_owner_id) {
40 echo json_encode(
41 array(
42 'success' => false,
43 'message' => $local['own_listing_error']
44 )
45 );
46 wp_die();
47 }
48
49 /*if(!homey_is_renter()) {
50 echo json_encode(
51 array(
52 'success' => false,
53 'message' => $local['host_user_cannot_book']
54 )
55 );
56 wp_die();
57 }*/
58
59 //check security
60 $nonce = $_REQUEST['security'];
61 if ( ! wp_verify_nonce( $nonce, 'reservation-security-nonce' ) ) {
62
63 echo json_encode(
64 array(
65 'success' => false,
66 'message' => $local['security_check_text']
67 )
68 );
69 wp_die();
70 }
71
72 $check_availability = check_hourly_booking_availability($check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $listing_id, $guests);
73 $is_available = $check_availability['success'];
74 $check_message = $check_availability['message'];
75
76 if($is_available) {
77 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
78
79 $reservation_meta['no_of_hours'] = $prices_array['hours_count'];
80 $reservation_meta['additional_guests'] = $prices_array['additional_guests'];
81
82 $upfront_payment = $prices_array['upfront_payment'];
83 $balance = $prices_array['balance'];
84 $total_price = $prices_array['total_price'];
85
86 $reservation_meta['check_in_date'] = $check_in_date;
87 $reservation_meta['check_in_hour'] = $check_in_hour;
88 $reservation_meta['check_out_hour'] = $check_out_hour;
89 $reservation_meta['start_hour'] = $start_hour;
90 $reservation_meta['end_hour'] = $end_hour;
91 $reservation_meta['guests'] = $guests;
92 $reservation_meta['listing_id'] = $listing_id;
93
94 $reservation_meta['price_per_hour'] = $prices_array['price_per_hour'];
95 $reservation_meta['hours_total_price'] = $prices_array['hours_total_price']; //$hours_total_price;
96
97 $reservation_meta['cleaning_fee'] = $prices_array['cleaning_fee'];
98 $reservation_meta['city_fee'] = $prices_array['city_fee'];
99 $reservation_meta['services_fee'] = $prices_array['services_fee'];
100
101 $reservation_meta['taxes'] = $prices_array['taxes'];
102 $reservation_meta['taxes_percent'] = $prices_array['taxes_percent'];
103 $reservation_meta['security_deposit'] = $prices_array['security_deposit'];
104
105 $reservation_meta['additional_guests_price'] = $prices_array['additional_guests_price'];
106 $reservation_meta['additional_guests_total_price'] = $prices_array['additional_guests_total_price'];
107 $reservation_meta['booking_has_weekend'] = $prices_array['booking_has_weekend'];
108 $reservation_meta['booking_has_custom_pricing'] = $prices_array['booking_has_custom_pricing'];
109 $reservation_meta['upfront'] = $upfront_payment;
110 $reservation_meta['balance'] = $balance;
111 $reservation_meta['total'] = $total_price;
112
113 $reservation = array(
114 'post_title' => $title,
115 'post_status' => 'publish',
116 'post_type' => 'homey_reservation' ,
117 'post_author' => $userID
118 );
119 $reservation_id = wp_insert_post($reservation );
120
121 $reservation_update = array(
122 'ID' => $reservation_id,
123 'post_title' => $title.' '.$reservation_id
124 );
125 wp_update_post( $reservation_update );
126
127 update_post_meta($reservation_id, 'reservation_listing_id', $listing_id);
128 update_post_meta($reservation_id, 'listing_owner', $listing_owner_id);
129 update_post_meta($reservation_id, 'listing_renter', $userID);
130 update_post_meta($reservation_id, 'reservation_checkin_hour', $check_in_hour);
131 update_post_meta($reservation_id, 'reservation_checkout_hour', $check_out_hour);
132 update_post_meta($reservation_id, 'reservation_guests', $guests);
133 update_post_meta($reservation_id, 'reservation_meta', $reservation_meta);
134 update_post_meta($reservation_id, 'reservation_status', 'under_review');
135 update_post_meta($reservation_id, 'is_hourly', 'yes');
136 update_post_meta($reservation_id, 'extra_options', $extra_options);
137
138 update_post_meta($reservation_id, 'reservation_upfront', $upfront_payment);
139 update_post_meta($reservation_id, 'reservation_balance', $balance);
140 update_post_meta($reservation_id, 'reservation_total', $total_price);
141
142 $pending_dates_array = homey_get_booking_pending_hours($listing_id);
143 update_post_meta($listing_id, 'reservation_pending_hours', $pending_dates_array);
144
145 echo json_encode(
146 array(
147 'success' => true,
148 'message' => $local['request_sent']
149 )
150 );
151
152 $email_args = array('reservation_detail_url' => reservation_detail_link($reservation_id) );
153 homey_email_composer( $owner_email, 'new_reservation', $email_args );
154
155 do_action('homey_create_messages_thread', $guest_message, $reservation_id);
156 wp_die();
157
158 } else { // end $check_availability
159 echo json_encode(
160 array(
161 'success' => false,
162 'message' => $check_message
163 )
164 );
165 wp_die();
166 }
167
168 }
169}
170
171if( !function_exists('homey_add_hourly_instance_booking') ) {
172 function homey_add_hourly_instance_booking($listing_id, $check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $guests, $renter_message, $extra_options, $user_id) {
173 global $current_user;
174 $current_user = wp_get_current_user();
175 $userID = $current_user->ID;
176
177 if(!empty($user_id)) {
178 $userID = $user_id;
179 }
180
181 $local = homey_get_localization();
182 $allowded_html = array();
183 $reservation_meta = array();
184
185 $listing_owner_id = get_post_field( 'post_author', $listing_id );
186 $title = $local['reservation_text'];
187
188 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
189
190 $reservation_meta['no_of_hours'] = $prices_array['hours_count'];
191 $reservation_meta['additional_guests'] = $prices_array['additional_guests'];
192
193 $upfront_payment = $prices_array['upfront_payment'];
194 $balance = $prices_array['balance'];
195 $total_price = $prices_array['total_price'];
196
197 $reservation_meta['check_in_date'] = $check_in_date;
198 $reservation_meta['check_in_hour'] = $check_in_hour;
199 $reservation_meta['check_out_hour'] = $check_out_hour;
200 $reservation_meta['start_hour'] = $start_hour;
201 $reservation_meta['end_hour'] = $end_hour;
202 $reservation_meta['guests'] = $guests;
203 $reservation_meta['listing_id'] = $listing_id;
204
205 $reservation_meta['price_per_hour'] = $prices_array['price_per_hour'];
206 $reservation_meta['hours_total_price'] = $prices_array['hours_total_price']; //$hours_total_price;
207
208 $reservation_meta['cleaning_fee'] = $prices_array['cleaning_fee'];
209 $reservation_meta['city_fee'] = $prices_array['city_fee'];
210 $reservation_meta['services_fee'] = $prices_array['services_fee'];
211
212 $reservation_meta['taxes'] = $prices_array['taxes'];
213 $reservation_meta['taxes_percent'] = $prices_array['taxes_percent'];
214 $reservation_meta['security_deposit'] = $prices_array['security_deposit'];
215
216 $reservation_meta['additional_guests_price'] = $prices_array['additional_guests_price'];
217 $reservation_meta['additional_guests_total_price'] = $prices_array['additional_guests_total_price'];
218 $reservation_meta['booking_has_weekend'] = $prices_array['booking_has_weekend'];
219 $reservation_meta['booking_has_custom_pricing'] = $prices_array['booking_has_custom_pricing'];
220 $reservation_meta['upfront'] = $upfront_payment;
221 $reservation_meta['balance'] = $balance;
222 $reservation_meta['total'] = $total_price;
223
224 $reservation = array(
225 'post_title' => $title,
226 'post_status' => 'publish',
227 'post_type' => 'homey_reservation' ,
228 'post_author' => $userID
229 );
230 $reservation_id = wp_insert_post($reservation );
231
232 $reservation_update = array(
233 'ID' => $reservation_id,
234 'post_title' => $title.' '.$reservation_id
235 );
236 wp_update_post( $reservation_update );
237
238 update_post_meta($reservation_id, 'reservation_listing_id', $listing_id);
239 update_post_meta($reservation_id, 'listing_owner', $listing_owner_id);
240 update_post_meta($reservation_id, 'listing_renter', $userID);
241 update_post_meta($reservation_id, 'reservation_checkin_hour', $check_in_hour);
242 update_post_meta($reservation_id, 'reservation_checkout_hour', $check_out_hour);
243 update_post_meta($reservation_id, 'reservation_guests', $guests);
244 update_post_meta($reservation_id, 'reservation_meta', $reservation_meta);
245 update_post_meta($reservation_id, 'reservation_status', 'booked');
246 update_post_meta($reservation_id, 'is_hourly', 'yes');
247
248 update_post_meta($reservation_id, 'extra_options', $extra_options);
249
250 update_post_meta($reservation_id, 'reservation_upfront', $upfront_payment);
251 update_post_meta($reservation_id, 'reservation_balance', $balance);
252 update_post_meta($reservation_id, 'reservation_total', $total_price);
253
254 //Book dates
255 $booked_days_array = homey_make_hours_booked($listing_id, $reservation_id);
256 update_post_meta($listing_id, 'reservation_booked_hours', $booked_days_array);
257
258 return $reservation_id;
259
260 }
261}
262
263if(!function_exists('check_hourly_booking_availability')) {
264 function check_hourly_booking_availability($check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $listing_id, $guests) {
265 $return_array = array();
266 $local = homey_get_localization();
267 $booking_proceed = true;
268
269 $min_book_hours = get_post_meta($listing_id, 'homey_min_book_hours', true);
270
271 $booking_hide_fields = homey_option('booking_hide_fields');
272
273 $homey_allow_additional_guests = get_post_meta($listing_id, 'homey_allow_additional_guests', true);
274 $allowed_guests = get_post_meta($listing_id, 'homey_guests', true);
275
276 if( ($homey_allow_additional_guests != 'yes') && ($guests > $allowed_guests) ) {
277 $return_array['success'] = false;
278 $return_array['message'] = $local['guest_allowed'].' '.$allowed_guests;
279 return $return_array;
280 }
281
282 if(strtotime($check_out_hour) <= strtotime($check_in_hour)) {
283 $booking_proceed = false;
284 }
285
286 if(empty($check_in_date) && empty($check_in_hour) && empty($check_out_hour)) {
287 $return_array['success'] = false;
288 $return_array['message'] = $local['fill_all_fields'];
289 return $return_array;
290
291 }
292
293 if(empty($check_in_date)) {
294 $return_array['success'] = false;
295 $return_array['message'] = $local['choose_checkin'];
296 return $return_array;
297
298 }
299
300 if(empty($check_in_hour) || empty($start_hour)) {
301 $return_array['success'] = false;
302 $return_array['message'] = $local['choose_start_hour'];
303 return $return_array;
304
305 }
306
307 if(empty($check_out_hour) || empty($end_hour)) {
308 $return_array['success'] = false;
309 $return_array['message'] = $local['choose_end_hour'];
310 return $return_array;
311
312 }
313
314
315 $time_difference = abs( strtotime($check_in_hour) - strtotime($check_out_hour) );
316 $hours_count = $time_difference/3600;
317 $hours_count = floatval($hours_count);
318
319 if($hours_count < $min_book_hours) {
320 $return_array['success'] = false;
321 $return_array['message'] = $local['min_book_hours_error'].' '.$min_book_hours;
322 return $return_array;
323 }
324
325 if(empty($guests) && $booking_hide_fields['guests'] != 1) {
326 $return_array['success'] = false;
327 $return_array['message'] = $local['choose_guests'];
328 return $return_array;
329
330 }
331
332 if(!$booking_proceed) {
333 $return_array['success'] = false;
334 $return_array['message'] = $local['ins_hourly_book_proceed'];
335 return $return_array;
336 }
337
338 $reservation_booked_array = get_post_meta($listing_id, 'reservation_booked_hours', true);
339 if(empty($reservation_booked_array)) {
340 $reservation_booked_array = homey_get_booked_hours($listing_id);
341 }
342
343 $reservation_pending_array = get_post_meta($listing_id, 'reservation_pending_hours', true);
344 if(empty($reservation_pending_array)) {
345 $reservation_pending_array = homey_get_booking_pending_hours($listing_id);
346 }
347
348 $check_in_hour = new DateTime($check_in_hour);
349 $check_in_hour_unix = $check_in_hour->getTimestamp();
350
351 $check_out_hour = new DateTime($check_out_hour);
352 $check_out_hour->modify('-30 minutes');
353 $check_out_hour_unix = $check_out_hour->getTimestamp();
354
355 while ($check_in_hour_unix <= $check_out_hour_unix) {
356
357 //echo $start_hour_unix.' ===== <br/>';
358 if( array_key_exists($check_in_hour_unix, $reservation_booked_array) || array_key_exists($check_in_hour_unix, $reservation_pending_array) ) {
359
360 $return_array['success'] = false;
361 $return_array['message'] = $local['hours_not_available'];
362 if(homey_is_instance_page()) {
363 $return_array['message'] = $local['hour_ins_unavailable'];
364 }
365 return $return_array;
366
367 }
368 $check_in_hour->modify('+30 minutes');
369 $check_in_hour_unix = $check_in_hour->getTimestamp();
370 }
371
372 //dates are available
373 $return_array['success'] = true;
374 $return_array['message'] = $local['hours_available'];
375 return $return_array;
376
377 }
378}
379
380add_action( 'wp_ajax_nopriv_check_booking_availability_on_hour_change', 'check_booking_availability_on_hour_change' );
381add_action( 'wp_ajax_check_booking_availability_on_hour_change', 'check_booking_availability_on_hour_change' );
382if(!function_exists('check_booking_availability_on_hour_change')) {
383 function check_booking_availability_on_hour_change() {
384 $local = homey_get_localization();
385 $allowded_html = array();
386 $booking_proceed = true;
387
388 $listing_id = intval($_POST['listing_id']);
389 $check_in_date = wp_kses ( $_POST['check_in_date'], $allowded_html );
390 $start_hour = wp_kses ( $_POST['start_hour'], $allowded_html );
391 $end_hour = wp_kses ( $_POST['end_hour'], $allowded_html );
392
393 $check_in_hour = $check_in_date.' '.$start_hour;
394 $check_out_hour = $check_in_date.' '.$end_hour;
395
396 $min_book_hours = get_post_meta($listing_id, 'homey_min_book_hours', true);
397
398
399 if(empty($check_in_date)) {
400 echo json_encode(
401 array(
402 'success' => false,
403 'message' => $local['choose_checkin']
404 )
405 );
406 wp_die();
407
408 }
409 if(empty($start_hour)) {
410 echo json_encode(
411 array(
412 'success' => false,
413 'message' => $local['choose_start_hour']
414 )
415 );
416 wp_die();
417 }
418
419 if(empty($end_hour)) {
420 echo json_encode(
421 array(
422 'success' => false,
423 'message' => $local['choose_end_hour']
424 )
425 );
426 wp_die();
427 }
428
429 if(strtotime($check_out_hour) <= strtotime($check_in_hour)) {
430 echo json_encode(
431 array(
432 'success' => false,
433 'message' => $local['ins_hourly_book_proceed']
434 )
435 );
436 wp_die();
437 }
438
439 $time_difference = abs( strtotime($check_in_hour) - strtotime($check_out_hour) );
440 $hours_count = $time_difference/3600;
441 $hours_count = floatval($hours_count);
442
443 if($hours_count < $min_book_hours) {
444 echo json_encode(
445 array(
446 'success' => false,
447 'message' => $local['min_book_hours_error'].' '.$min_book_hours
448 )
449 );
450 wp_die();
451 }
452
453
454 $reservation_booked_array = get_post_meta($listing_id, 'reservation_booked_hours', true);
455 if(empty($reservation_booked_array)) {
456 $reservation_booked_array = homey_get_booked_hours($listing_id);
457 }
458
459 $reservation_pending_array = get_post_meta($listing_id, 'reservation_pending_hours', true);
460 if(empty($reservation_pending_array)) {
461 $reservation_pending_array = homey_get_booking_pending_hours($listing_id);
462 }
463
464 $check_in_hour = new DateTime($check_in_hour);
465 $check_in_hour_unix = $check_in_hour->getTimestamp();
466
467 $check_out_hour = new DateTime($check_out_hour);
468 $check_out_hour->modify('-30 minutes');
469 $check_out_hour_unix = $check_out_hour->getTimestamp();
470
471 while ($check_in_hour_unix <= $check_out_hour_unix) {
472
473 //echo $start_hour_unix.' ===== <br/>';
474 if( array_key_exists($check_in_hour_unix, $reservation_booked_array) || array_key_exists($check_in_hour_unix, $reservation_pending_array) ) {
475
476 echo json_encode(
477 array(
478 'success' => false,
479 'message' => $local['hours_not_available']
480 )
481 );
482 wp_die();
483
484 }
485 $check_in_hour->modify('+30 minutes');
486 $check_in_hour_unix = $check_in_hour->getTimestamp();
487 }
488 echo json_encode(
489 array(
490 'success' => true,
491 'message' => $local['hours_available']
492 )
493 );
494 wp_die();
495 }
496}
497
498
499if(!function_exists('homey_get_booked_hours')) {
500 function homey_get_booked_hours($listing_id) {
501 $now = time();
502 //$daysAgo = $now-3*24*60*60;
503 $daysAgo = $now-1*24*60*60;
504
505 $args = array(
506 'post_type' => 'homey_reservation',
507 'post_status' => 'any',
508 'posts_per_page' => -1,
509 'meta_query' => array(
510 'relation' => 'AND',
511 array(
512 'key' => 'reservation_listing_id',
513 'value' => $listing_id,
514 'type' => 'NUMERIC',
515 'compare' => '='
516 ),
517 array(
518 'key' => 'reservation_status',
519 'value' => 'booked',
520 'type' => 'CHAR',
521 'compare' => '='
522 )
523 )
524 );
525
526 $booked_hours_array = get_post_meta($listing_id, 'reservation_booked_hours', true );
527
528 if( !is_array($booked_hours_array) || empty($booked_hours_array) ) {
529 $booked_hours_array = array();
530 }
531
532 $wpQry = new WP_Query($args);
533
534 if ($wpQry->have_posts()) {
535
536 while ($wpQry->have_posts()): $wpQry->the_post();
537
538 $resID = get_the_ID();
539
540 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
541 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
542
543 $unix_time_start = strtotime ($check_in_date);
544
545 if ($unix_time_start > $daysAgo) {
546
547 $check_in = new DateTime($check_in_date);
548 $check_in_unix = $check_in->getTimestamp();
549 $check_out = new DateTime($check_out_date);
550 $check_out_unix = $check_out->getTimestamp();
551
552
553 $booked_hours_array[$check_in_unix] = $resID;
554
555 $check_in_unix = $check_in->getTimestamp();
556
557 while ($check_in_unix < $check_out_unix){
558
559 $booked_hours_array[$check_in_unix] = $resID;
560
561 //$check_in->modify('+1 hour');
562 $check_in->modify('+30 minutes');
563 $check_in_unix = $check_in->getTimestamp();
564 }
565
566 }
567 endwhile;
568 wp_reset_postdata();
569 }
570
571 return $booked_hours_array;
572
573 }
574}
575
576
577if(!function_exists('homey_get_booking_pending_hours')) {
578 function homey_get_booking_pending_hours($listing_id) {
579 $now = time();
580 //$daysAgo = $now-3*24*60*60;
581 $daysAgo = $now-1*24*60*60;
582
583 $args = array(
584 'post_type' => 'homey_reservation',
585 'post_status' => 'any',
586 'posts_per_page' => -1,
587 'meta_query' => array(
588 'relation' => 'AND',
589 array(
590 'key' => 'reservation_listing_id',
591 'value' => $listing_id,
592 'type' => 'NUMERIC',
593 'compare' => '='
594 ),
595 array(
596 'key' => 'reservation_status',
597 'value' => 'declined',
598 'type' => 'CHAR',
599 'compare' => '!='
600 ),
601 array(
602 'key' => 'reservation_status',
603 'value' => 'cancelled',
604 'type' => 'CHAR',
605 'compare' => '!='
606 )
607 )
608 );
609
610 $pending_dates_array = get_post_meta($listing_id, 'reservation_pending_hours', true );
611
612 if( !is_array($pending_dates_array) || empty($pending_dates_array) ) {
613 $pending_dates_array = array();
614 }
615
616 $wpQry = new WP_Query($args);
617
618 if ($wpQry->have_posts()) {
619
620 while ($wpQry->have_posts()): $wpQry->the_post();
621
622 $resID = get_the_ID();
623
624 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
625 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
626
627 $unix_time_start = strtotime ($check_in_date);
628
629 if ($unix_time_start > $daysAgo) {
630
631 $check_in = new DateTime($check_in_date);
632 $check_in_unix = $check_in->getTimestamp();
633 $check_out = new DateTime($check_out_date);
634 $check_out_unix = $check_out->getTimestamp();
635
636
637 $pending_dates_array[$check_in_unix] = $resID;
638
639 $check_in_unix = $check_in->getTimestamp();
640
641 while ($check_in_unix < $check_out_unix){
642
643 $pending_dates_array[$check_in_unix] = $resID;
644
645 //$check_in->modify('+1 hour');
646 $check_in->modify('+30 minutes');
647 $check_in_unix = $check_in->getTimestamp();
648 }
649
650 }
651 endwhile;
652 wp_reset_postdata();
653 }
654
655 return $pending_dates_array;
656
657 }
658}
659
660if(!function_exists('homey_get_hourly_prices')) {
661 function homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options = null) {
662 $prefix = 'homey_';
663
664 $enable_services_fee = homey_option('enable_services_fee');
665 $enable_taxes = homey_option('enable_taxes');
666 $offsite_payment = homey_option('off-site-payment');
667 $reservation_payment_type = homey_option('reservation_payment');
668 $booking_percent = homey_option('booking_percent');
669 $tax_type = homey_option('tax_type');
670 $apply_taxes_on_service_fee = homey_option('apply_taxes_on_service_fee');
671 $taxes_percent_global = homey_option('taxes_percent');
672 $single_listing_tax = get_post_meta($listing_id, 'homey_tax_rate', true);
673
674 $period_price = get_post_meta($listing_id, 'homey_hourly_custom_period', true);
675 if(empty($period_price)) {
676 $period_price = array();
677 }
678
679 $total_extra_services = 0;
680 $extra_prices_html = '';
681 $taxes_final = 0;
682 $taxes_percent = 0;
683 $total_price = 0;
684 $total_guests_price = 0;
685 $upfront_payment = 0;
686 $hours_total_price = 0;
687 $booking_has_weekend = 0;
688 $booking_has_custom_pricing = 0;
689 $balance = 0;
690 $period_hours = 0;
691 $security_deposit = '';
692 $additional_guests = '';
693 $additional_guests_total_price = '';
694 $services_fee_final = '';
695 $taxes_fee_final = '';
696 $prices_array = array();
697
698 $listing_guests = floatval( get_post_meta($listing_id, $prefix.'guests', true) );
699 $hourly_price = floatval( get_post_meta($listing_id, $prefix.'hour_price', true));
700 $price_per_hour = $hourly_price;
701
702 $weekends_price = floatval( get_post_meta($listing_id, $prefix.'hourly_weekends_price', true) );
703 $weekends_days = get_post_meta($listing_id, $prefix.'weekends_days', true);
704 //$priceWeek = floatval( get_post_meta($listing_id, $prefix.'priceWeek', true) ); // 7 hours
705 //$priceMonthly = floatval( get_post_meta($listing_id, $prefix.'priceMonthly', true) ); // 30 hours
706 $security_deposit = floatval( get_post_meta($listing_id, $prefix.'security_deposit', true) );
707
708 $cleaning_fee = floatval( get_post_meta($listing_id, $prefix.'cleaning_fee', true) );
709 $cleaning_fee_type = get_post_meta($listing_id, $prefix.'cleaning_fee_type', true);
710
711 $city_fee = floatval( get_post_meta($listing_id, $prefix.'city_fee', true) );
712 $city_fee_type = get_post_meta($listing_id, $prefix.'city_fee_type', true);
713
714 $extra_guests_price = floatval( get_post_meta($listing_id, $prefix.'additional_guests_price', true) );
715 $additional_guests_price = $extra_guests_price;
716
717 $allow_additional_guests = get_post_meta($listing_id, $prefix.'allow_additional_guests', true);
718
719 $check_in = new DateTime($check_in_hour);
720 $check_in_unix = $check_in->getTimestamp();
721 $check_in_unix_first_day = $check_in->getTimestamp();
722 $check_out = new DateTime($check_out_hour);
723 $check_out_unix = $check_out->getTimestamp();
724
725 $time_difference = abs( strtotime($check_in_hour) - strtotime($check_out_hour) );
726 $hours_count = $time_difference/3600;
727 $hours_count = floatval($hours_count);
728
729 $total_price = $price_per_hour * $hours_count;
730
731 if( isset($period_price[$check_in_unix]) && isset( $period_price[$check_in_unix]['hour_price'] ) && $period_price[$check_in_unix]['hour_price']!=0 ){
732 $price_per_hour = $period_price[$check_in_unix]['hour_price'];
733
734 $booking_has_custom_pricing = 1;
735 $period_hours = $period_hours + 1;
736 }
737
738 /*if( $hours_count > 7 && $priceWeek != 0 ) {
739 $price_per_hour = $priceWeek;
740 }
741
742 if( $hours_count > 30 && $priceMonthly != 0 ) {
743 $price_per_hour = $priceMonthly;
744 }*/
745
746
747 // Check additional guests price
748 if( $allow_additional_guests == 'yes' && $guests > 0 && !empty($guests) ) {
749 if( $guests > $listing_guests) {
750 $additional_guests = $guests - $listing_guests;
751
752 $guests_price_return = homey_calculate_guests_price($period_price, $check_in_unix, $additional_guests, $additional_guests_price);
753
754 $total_guests_price = $total_guests_price + $guests_price_return;
755 }
756 }
757
758 $check_in_unix = $check_in->getTimestamp();
759
760 $weekday = date('N', $check_in_unix);
761 if(homey_check_weekend($weekday, $weekends_days, $weekends_price)) {
762 $booking_has_weekend = 1;
763 $price_per_hour = $weekends_price;
764 $total_price = $weekends_price * $hours_count;
765 }
766
767
768 if( $cleaning_fee_type == 'daily' ) {
769 $cleaning_fee = $cleaning_fee * $hours_count;
770 $total_price = $total_price + $cleaning_fee;
771 } else {
772 $total_price = $total_price + $cleaning_fee;
773 }
774
775 //Extra prices =======================================
776 if($extra_options != '') {
777
778 $extra_prices_output = '';
779 foreach ($extra_options as $extra_price) {
780 $ex_single_price = explode('|', $extra_price);
781
782 $ex_name = $ex_single_price[0];
783 $ex_price = $ex_single_price[1];
784 $ex_type = $ex_single_price[2];
785
786 if($ex_type == 'single_fee') {
787 $ex_price = $ex_price;
788
789 } elseif($ex_type == 'per_night') {
790 $ex_price = $ex_price*$hours_count;
791 } elseif($ex_type == 'per_guest') {
792 $ex_price = $ex_price*$guests;
793 } elseif($ex_type == 'per_night_per_guest') {
794 $ex_price = $ex_price* $hours_count*$guests;
795 }
796
797 $total_extra_services = $total_extra_services + $ex_price;
798
799 $extra_prices_output .= '<li>'.esc_attr($ex_name).'<span>'.homey_formatted_price($ex_price).'</span></li>';
800 }
801
802 $total_price = $total_price + $total_extra_services;
803 $extra_prices_html = $extra_prices_output;
804 }
805
806
807 //Calculate taxes based of original price (Excluding city, security deposit etc)
808 if($enable_taxes == 1) {
809
810 if($tax_type == 'global_tax') {
811 $taxes_percent = $taxes_percent_global;
812 } else {
813 if(!empty($single_listing_tax)) {
814 $taxes_percent = $single_listing_tax;
815 }
816 }
817
818 $taxes_final = homey_calculate_taxes($taxes_percent, $total_price);
819 $total_price = $total_price + $taxes_final;
820 }
821
822
823 //Calculate sevices fee based of original price (Excluding cleaning, city, sevices fee etc)
824 if($enable_services_fee == 1 && $offsite_payment != 1) {
825 $services_fee_type = homey_option('services_fee_type');
826 $services_fee = homey_option('services_fee');
827 $price_for_services_fee = $total_price + $total_guests_price;
828 $services_fee_final = homey_calculate_services_fee($services_fee_type, $services_fee, $price_for_services_fee);
829 $total_price = $total_price + $services_fee_final;
830 }
831
832
833 if( $city_fee_type == 'daily' ) {
834 $city_fee = $city_fee * $hours_count;
835 $total_price = $total_price + $city_fee;
836 } else {
837 $total_price = $total_price + $city_fee;
838 }
839
840 if(!empty($security_deposit) && $security_deposit != 0) {
841 $total_price = $total_price + $security_deposit;
842 }
843
844 if($total_guests_price !=0) {
845 $total_price = $total_price + $total_guests_price;
846 }
847
848 $offsite_payment = homey_option('off-site-payment');
849 $listing_host_id = get_post_field( 'post_author', $listing_id );
850 $host_reservation_payment_type = get_user_meta($listing_host_id, 'host_reservation_payment', true);
851 $host_booking_percent = get_user_meta($listing_host_id, 'host_booking_percent', true);
852
853 if($offsite_payment == 1 && !empty($host_reservation_payment_type)) {
854
855 if($host_reservation_payment_type == 'percent') {
856 if(!empty($host_booking_percent) && $host_booking_percent != 0) {
857 $upfront_payment = round($host_booking_percent*$total_price/100,2);
858 }
859
860 } elseif($host_reservation_payment_type == 'full') {
861 $upfront_payment = $total_price;
862
863 } elseif($host_reservation_payment_type == 'only_security') {
864 $upfront_payment = $security_deposit;
865
866 } elseif($host_reservation_payment_type == 'only_services') {
867 $upfront_payment = $services_fee_final;
868
869 } elseif($host_reservation_payment_type == 'services_security') {
870 $upfront_payment = $security_deposit+$services_fee_final;
871 }
872
873 } else {
874
875 if($reservation_payment_type == 'percent') {
876 if(!empty($booking_percent) && $booking_percent != 0) {
877 $upfront_payment = round($booking_percent*$total_price/100,2);
878 }
879
880 } elseif($reservation_payment_type == 'full') {
881 $upfront_payment = $total_price;
882
883 } elseif($reservation_payment_type == 'only_security') {
884 $upfront_payment = $security_deposit;
885
886 } elseif($reservation_payment_type == 'only_services') {
887 $upfront_payment = $services_fee_final;
888
889 } elseif($reservation_payment_type == 'services_security') {
890 $upfront_payment = $security_deposit+$services_fee_final;
891 }
892 }
893
894 $balance = $total_price - $upfront_payment;
895
896 $prices_array['price_per_hour'] = $price_per_hour;
897 $prices_array['hours_total_price'] = $price_per_hour * $hours_count; //$hours_total_price;
898 $prices_array['total_price'] = $total_price;
899 $prices_array['check_in_hour'] = $check_in_hour;
900 $prices_array['check_out_hour'] = $check_out_hour;
901 $prices_array['cleaning_fee'] = $cleaning_fee;
902 $prices_array['city_fee'] = $city_fee;
903 $prices_array['services_fee'] = $services_fee_final;
904 $prices_array['hours_count'] = $hours_count;
905 //$prices_array['period_hours'] = $period_hours;
906 $prices_array['taxes'] = $taxes_final;
907 $prices_array['taxes_percent'] = $taxes_percent;
908 $prices_array['security_deposit'] = $security_deposit;
909 $prices_array['additional_guests'] = $additional_guests;
910 $prices_array['additional_guests_price'] = $additional_guests_price;
911 $prices_array['additional_guests_total_price'] = $total_guests_price;
912 $prices_array['booking_has_weekend'] = $booking_has_weekend;
913 $prices_array['extra_prices_html'] = $extra_prices_html;
914 $prices_array['booking_has_custom_pricing'] = $booking_has_custom_pricing;
915 $prices_array['balance'] = $balance;
916 $prices_array['upfront_payment'] = $upfront_payment;
917
918 return $prices_array;
919
920 }
921}
922
923
924
925if(!function_exists('homey_check_hourly_weekend')) {
926 function homey_check_hourly_weekend($weekday, $weekends_days, $weekends_price) {
927
928 if(empty($weekends_price) && $weekends_price == 0 ) {
929 return false;
930
931 } else {
932
933 if($weekends_days == 'sat_sun' && ($weekday ==6 || $weekday==7)) {
934 return true;
935
936 } elseif($weekends_days == 'fri_sat' && ($weekday ==5 || $weekday==6)) {
937 return true;
938
939 } elseif($weekends_days == 'fri_sat_sun' && ($weekday ==5 || $weekday ==6 || $weekday==7)) {
940 return true;
941
942 } else {
943 return false;
944 }
945 }
946 return false;
947
948 }
949}
950
951if(!function_exists('homey_cal_hourly_weekend_price') ) {
952 function homey_cal_hourly_weekend_price($check_in_unix, $weekends_price, $price_per_hour, $weekends_days, $period_price){
953 $weekday = date('N', $check_in_unix);
954
955 $return_array = array();
956
957 if($weekends_days == 'sat_sun' && ($weekday ==6 || $weekday==7)) {
958 $return_price = homey_get_hourly_weekend_price($check_in_unix, $weekends_price, $price_per_hour, $weekends_days, $period_price);
959
960 $return_array['weekend'] = 'yes';
961 $return_array['weekend_price'] = $return_price;
962
963 } elseif($weekends_days == 'fri_sat' && ($weekday ==5 || $weekday==6)) {
964 $return_price = homey_get_hourly_weekend_price($check_in_unix, $weekends_price, $price_per_hour, $weekends_days, $period_price);
965
966 $return_array['weekend'] = 'yes';
967 $return_array['weekend_price'] = $return_price;
968
969 } elseif($weekends_days == 'fri_sat_sun' && ($weekday ==5 || $weekday ==6 || $weekday==7)) {
970 $return_price = homey_get_hourly_weekend_price($check_in_unix, $weekends_price, $price_per_hour, $weekends_days, $period_price);
971
972 $return_array['weekend'] = 'yes';
973 $return_array['weekend_price'] = $return_price;
974
975 } else {
976 $return_array['weekend'] = 'no';
977 $return_array['weekend_price'] = '';
978 }
979
980 return $return_array;
981
982 }
983}
984
985
986if(!function_exists('homey_get_hourly_weekend_price')) {
987 function homey_get_hourly_weekend_price($check_in_unix, $weekends_price, $price_per_hour, $weekends_days, $period_price) {
988 if( isset($period_price[$check_in_unix]) && isset( $period_price[$check_in_unix]['weekend_price'] ) && $period_price[$check_in_unix]['weekend_price']!=0 ){
989
990 $return_price = $period_price[$check_in_unix]['weekend_price'];
991
992 } elseif(!empty($weekends_price) && $weekends_price != 0) {
993 $return_price = $weekends_price;
994 } else {
995 $return_price = $price_per_hour;
996 }
997
998 return $return_price;
999 }
1000}
1001
1002add_action( 'wp_ajax_nopriv_homey_calculate_hourly_booking_cost', 'homey_calculate_hourly_booking_cost_ajax' );
1003add_action( 'wp_ajax_homey_calculate_hourly_booking_cost', 'homey_calculate_hourly_booking_cost_ajax' );
1004
1005if( !function_exists('homey_calculate_hourly_booking_cost_ajax') ) {
1006 function homey_calculate_hourly_booking_cost_ajax() {
1007 $prefix = 'homey_';
1008 $local = homey_get_localization();
1009 $allowded_html = array();
1010 $output = '';
1011
1012 $listing_id = intval($_POST['listing_id']);
1013 $check_in_date = wp_kses ( $_POST['check_in_date'], $allowded_html );
1014 $start_hour = wp_kses ( $_POST['start_hour'], $allowded_html );
1015 $end_hour = wp_kses ( $_POST['end_hour'], $allowded_html );
1016 $guests = intval($_POST['guests']);
1017 $extra_options = $_POST['extra_options'];
1018
1019 $check_in_hour = $check_in_date.' '.$start_hour;
1020 $check_out_hour = $check_in_date.' '.$end_hour;
1021
1022 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
1023
1024 $price_per_hour = homey_formatted_price($prices_array['price_per_hour'], true);
1025 $no_of_hours = $prices_array['hours_count'];
1026
1027 $hours_total_price = homey_formatted_price($prices_array['hours_total_price'], false);
1028
1029 $cleaning_fee = homey_formatted_price($prices_array['cleaning_fee']);
1030 $services_fee = $prices_array['services_fee'];
1031 $taxes = $prices_array['taxes'];
1032 $taxes_percent = $prices_array['taxes_percent'];
1033 $city_fee = homey_formatted_price($prices_array['city_fee']);
1034 $security_deposit = $prices_array['security_deposit'];
1035 $additional_guests = $prices_array['additional_guests'];
1036 $additional_guests_price = $prices_array['additional_guests_price'];
1037 $additional_guests_total_price = $prices_array['additional_guests_total_price'];
1038
1039 $booking_has_weekend = $prices_array['booking_has_weekend'];
1040 $booking_has_custom_pricing = $prices_array['booking_has_custom_pricing'];
1041 $with_weekend_label = $local['with_weekend_label'];
1042
1043 $upfront_payment = $prices_array['upfront_payment'];
1044 $balance = $prices_array['balance'];
1045 $total_price = $prices_array['total_price'];
1046 $extra_prices_html = $prices_array['extra_prices_html'];
1047
1048 if($no_of_hours > 1) {
1049 $hour_label = $local['hours_label'];
1050 } else {
1051 $hour_label = $local['hour_label'];
1052 }
1053
1054 if($additional_guests > 1) {
1055 $add_guest_label = $local['cs_add_guests'];
1056 } else {
1057 $add_guest_label = $local['cs_add_guest'];
1058 }
1059
1060 $output = '<div class="payment-list-price-detail clearfix">';
1061 $output .= '<div class="pull-left">';
1062 $output .= '<div class="payment-list-price-detail-total-price">'.esc_attr($local['cs_total']).'</div>';
1063 $output .= '<div class="payment-list-price-detail-note">'.esc_attr($local['cs_tax_fees']).'</div>';
1064 $output .= '</div>';
1065
1066 $output .= '<div class="pull-right text-right">';
1067 $output .= '<div class="payment-list-price-detail-total-price">'.homey_formatted_price($total_price).'</div>';
1068 $output .= '<a class="payment-list-detail-btn" data-toggle="collapse" data-target=".collapseExample" href="javascript:void(0);" aria-expanded="false" aria-controls="collapseExample">'.esc_attr($local['cs_view_details']).'</a>';
1069 $output .= '</div>';
1070 $output .= '</div>';
1071
1072 $output .= '<div class="collapse collapseExample" id="collapseExample">';
1073 $output .= '<ul>';
1074
1075 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1076 $output .= '<li>'.esc_attr($no_of_hours).' '.esc_attr($hour_label).' ('.esc_attr($local['with_custom_period_and_weekend_label']).') <span>'.esc_attr($hours_total_price).'</span></li>';
1077
1078 } elseif($booking_has_weekend == 1) {
1079 $output .= '<li>'.esc_attr($price_per_hour).' x '.esc_attr($no_of_hours).' '.esc_attr($hour_label).' ('.esc_attr($with_weekend_label).') <span>'.$hours_total_price.'</span></li>';
1080
1081 } elseif($booking_has_custom_pricing == 1) {
1082 $output .= '<li>'.esc_attr($no_of_hours).' '.esc_attr($hour_label).' ('.esc_attr($local['with_custom_period_label']).') <span>'.esc_attr($hours_total_price).'</span></li>';
1083
1084 } else {
1085 $output .= '<li>'.esc_attr($price_per_hour).' x '.esc_attr($no_of_hours).' '.esc_attr($hour_label).' <span>'.$hours_total_price.'</span></li>';
1086 }
1087
1088 if(!empty($additional_guests)) {
1089 $output .= '<li>'.esc_attr($additional_guests).' '.esc_attr($add_guest_label).' <span>'.homey_formatted_price($additional_guests_total_price).'</span></li>';
1090 }
1091
1092 if(!empty($prices_array['cleaning_fee']) && $prices_array['cleaning_fee'] != 0) {
1093 $output .= '<li>'.esc_attr($local['cs_cleaning_fee']).' <span>'.esc_attr($cleaning_fee).'</span></li>';
1094 }
1095
1096 if(!empty($extra_prices_html)) {
1097 $output .= $extra_prices_html;
1098 }
1099
1100 if(!empty($prices_array['city_fee']) && $prices_array['city_fee'] != 0) {
1101 $output .= '<li>'.esc_attr($local['cs_city_fee']).' <span>'.esc_attr($city_fee).'</span></li>';
1102 }
1103
1104 if(!empty($security_deposit) && $security_deposit != 0) {
1105 $output .= '<li>'.esc_attr($local['cs_sec_deposit']).' <span>'.homey_formatted_price($security_deposit).'</span></li>';
1106 }
1107
1108 if(!empty($services_fee) && $services_fee != 0 ) {
1109 $output .= '<li>'.esc_attr($local['cs_services_fee']).' <span>'.homey_formatted_price($services_fee).'</span></li>';
1110 }
1111
1112 if(!empty($taxes) && $taxes != 0 ) {
1113 $output .= '<li>'.esc_attr($local['cs_taxes']).' '.esc_attr($taxes_percent).'% <span>'.homey_formatted_price($taxes).'</span></li>';
1114 }
1115
1116 if(!empty($upfront_payment) && $upfront_payment != 0) {
1117 $output .= '<li class="payment-due">'.esc_attr($local['cs_payment_due']).' <span>'.homey_formatted_price($upfront_payment).'</span></li>';
1118 }
1119
1120 $output .= '</ul>';
1121 $output .= '</div>';
1122
1123 // This variable has been safely escaped in same file: Line: 1071 - 1128
1124 $output_escaped = $output;
1125 print $output_escaped;
1126
1127 wp_die();
1128
1129 }
1130}
1131
1132if( !function_exists('homey_calculate_hourly_booking_cost') ) {
1133 function homey_calculate_hourly_booking_cost($reservation_id, $collapse = false) {
1134 $prefix = 'homey_';
1135 $local = homey_get_localization();
1136 $allowded_html = array();
1137 $output = '';
1138
1139 if(empty($reservation_id)) {
1140 return;
1141 }
1142 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1143
1144 $listing_id = intval($reservation_meta['listing_id']);
1145 $check_in_date = wp_kses ( $reservation_meta['check_in_date'], $allowded_html );
1146 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1147 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1148 $guests = intval($reservation_meta['guests']);
1149
1150 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests);
1151
1152 $price_per_hour = homey_formatted_price($prices_array['price_per_hour'], true);
1153 $no_of_hours = $prices_array['hours_count'];
1154
1155 $hours_total_price = homey_formatted_price($prices_array['hours_total_price'], false);
1156
1157 $cleaning_fee = homey_formatted_price($prices_array['cleaning_fee']);
1158 $services_fee = $prices_array['services_fee'];
1159 $taxes = $prices_array['taxes'];
1160 $taxes_percent = $prices_array['taxes_percent'];
1161 $city_fee = homey_formatted_price($prices_array['city_fee']);
1162 $security_deposit = $prices_array['security_deposit'];
1163 $additional_guests = $prices_array['additional_guests'];
1164 $additional_guests_price = $prices_array['additional_guests_price'];
1165 $additional_guests_total_price = $prices_array['additional_guests_total_price'];
1166
1167 $upfront_payment = $prices_array['upfront_payment'];
1168 $balance = $prices_array['balance'];
1169 $total_price = $prices_array['total_price'];
1170
1171 $booking_has_weekend = $prices_array['booking_has_weekend'];
1172 $booking_has_custom_pricing = $prices_array['booking_has_custom_pricing'];
1173 $with_weekend_label = $local['with_weekend_label'];
1174
1175 if($no_of_hours > 1) {
1176 $hour_label = $local['hours_label'];
1177 } else {
1178 $hour_label = $local['hour_label'];
1179 }
1180
1181 if($additional_guests > 1) {
1182 $add_guest_label = $local['cs_add_guests'];
1183 } else {
1184 $add_guest_label = $local['cs_add_guest'];
1185 }
1186
1187 $start_div = '<div class="payment-list">';
1188
1189 if($collapse) {
1190 $output = '<div class="payment-list-price-detail clearfix">';
1191 $output .= '<div class="pull-left">';
1192 $output .= '<div class="payment-list-price-detail-total-price">'.$local['cs_total'].'</div>';
1193 $output .= '<div class="payment-list-price-detail-note">'.$local['cs_tax_fees'].'</div>';
1194 $output .= '</div>';
1195
1196 $output .= '<div class="pull-right text-right">';
1197 $output .= '<div class="payment-list-price-detail-total-price">'.homey_formatted_price($total_price).'</div>';
1198 $output .= '<a class="payment-list-detail-btn" data-toggle="collapse" data-target=".collapseExample" href="javascript:void(0);" aria-expanded="false" aria-controls="collapseExample">'.$local['cs_view_details'].'</a>';
1199 $output .= '</div>';
1200 $output .= '</div>';
1201
1202 $start_div = '<div class="collapse collapseExample" id="collapseExample">';
1203 }
1204
1205
1206 $output .= $start_div;
1207 $output .= '<ul>';
1208
1209 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1210 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_and_weekend_label'].') <span>'.$hours_total_price.'</span></li>';
1211
1212 } elseif($booking_has_weekend == 1) {
1213 $output .= '<li>'.esc_attr($price_per_hour).' x '.$no_of_hours.' '.$hour_label.' ('.$with_weekend_label.') <span>'.$hours_total_price.'</span></li>';
1214
1215 } elseif($booking_has_custom_pricing == 1) {
1216 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_label'].') <span>'.$hours_total_price.'</span></li>';
1217
1218 } else {
1219 $output .= '<li>'.$price_per_hour.' x '.$no_of_hours.' '.$hour_label.' <span>'.$hours_total_price.'</span></li>';
1220 }
1221
1222 if(!empty($additional_guests)) {
1223 $output .= '<li>'.$additional_guests.' '.$add_guest_label.' <span>'.homey_formatted_price($additional_guests_total_price).'</span></li>';
1224 }
1225
1226 if(!empty($prices_array['cleaning_fee']) && $prices_array['cleaning_fee'] != 0) {
1227 $output .= '<li>'.$local['cs_cleaning_fee'].' <span>'.$cleaning_fee.'</span></li>';
1228 }
1229
1230 if(!empty($prices_array['city_fee']) && $prices_array['city_fee'] != 0) {
1231 $output .= '<li>'.$local['cs_city_fee'].' <span>'.$city_fee.'</span></li>';
1232 }
1233
1234 if(!empty($security_deposit) && $security_deposit != 0) {
1235 $output .= '<li>'.$local['cs_sec_deposit'].' <span>'.homey_formatted_price($security_deposit).'</span></li>';
1236 }
1237
1238 if(!empty($services_fee) && $services_fee != 0 ) {
1239 $output .= '<li>'.$local['cs_services_fee'].' <span>'.homey_formatted_price($services_fee).'</span></li>';
1240 }
1241
1242 if(!empty($taxes) && $taxes != 0 ) {
1243 $output .= '<li>'.$local['cs_taxes'].' '.$taxes_percent.'% <span>'.homey_formatted_price($taxes).'</span></li>';
1244 }
1245
1246 if(!empty($upfront_payment) && $upfront_payment != 0) {
1247 $output .= '<li class="payment-due">'.$local['cs_payment_due'].' <span>'.homey_formatted_price($upfront_payment).'</span></li>';
1248 }
1249
1250 if(!empty($balance) && $balance != 0) {
1251 $output .= '<li><i class="fa fa-info-circle"></i> '.$local['cs_pay_rest_1'].' '.homey_formatted_price($balance).' '.$local['cs_pay_rest_2'].'</li>';
1252 }
1253
1254 $output .= '</ul>';
1255 $output .= '</div>';
1256
1257 return $output;
1258 }
1259}
1260
1261if( !function_exists('homey_calculate_hourly_reservation_cost') ) {
1262 function homey_calculate_hourly_reservation_cost($reservation_id, $collapse = false) {
1263 $prefix = 'homey_';
1264 $local = homey_get_localization();
1265 $allowded_html = array();
1266 $output = '';
1267
1268 if(empty($reservation_id)) {
1269 return;
1270 }
1271 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1272 $extra_options = get_post_meta($reservation_id, 'extra_options', true);
1273
1274 $listing_id = intval($reservation_meta['listing_id']);
1275 $check_in_date = wp_kses ( $reservation_meta['check_in_date'], $allowded_html );
1276 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1277 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1278 $guests = intval($reservation_meta['guests']);
1279
1280
1281 $price_per_hour = homey_formatted_price($reservation_meta['price_per_hour'], true);
1282 $no_of_hours = $reservation_meta['no_of_hours'];
1283
1284 $hours_total_price = homey_formatted_price($reservation_meta['hours_total_price'], false);
1285
1286 $cleaning_fee = homey_formatted_price($reservation_meta['cleaning_fee']);
1287 $services_fee = $reservation_meta['services_fee'];
1288 $taxes = $reservation_meta['taxes'];
1289 $taxes_percent = $reservation_meta['taxes_percent'];
1290 $city_fee = homey_formatted_price($reservation_meta['city_fee']);
1291 $security_deposit = $reservation_meta['security_deposit'];
1292 $additional_guests = $reservation_meta['additional_guests'];
1293 $additional_guests_price = $reservation_meta['additional_guests_price'];
1294 $additional_guests_total_price = $reservation_meta['additional_guests_total_price'];
1295
1296 $upfront_payment = $reservation_meta['upfront'];
1297 $balance = $reservation_meta['balance'];
1298 $total_price = $reservation_meta['total'];
1299
1300 $booking_has_weekend = $reservation_meta['booking_has_weekend'];
1301 $booking_has_custom_pricing = $reservation_meta['booking_has_custom_pricing'];
1302 $with_weekend_label = $local['with_weekend_label'];
1303
1304 if($no_of_hours > 1) {
1305 $hour_label = $local['hours_label'];
1306 } else {
1307 $hour_label = $local['hour_label'];
1308 }
1309
1310 if($additional_guests > 1) {
1311 $add_guest_label = $local['cs_add_guests'];
1312 } else {
1313 $add_guest_label = $local['cs_add_guest'];
1314 }
1315
1316 $invoice_id = isset($_GET['invoice_id']) ? $_GET['invoice_id'] : '';
1317 $reservation_detail_id = isset($_GET['reservation_detail']) ? $_GET['reservation_detail'] : '';
1318 $is_host = false;
1319 if( (!empty($invoice_id) || !empty($reservation_detail_id) ) && homey_is_host()) {
1320 $is_host = true;
1321 }
1322
1323 $extra_prices = homey_get_extra_prices($extra_options, $no_of_hours, $guests);
1324
1325 if($is_host) {
1326 $total_price = $total_price - $services_fee;
1327 }
1328
1329 $start_div = '<div class="payment-list">';
1330
1331 if($collapse) {
1332 $output = '<div class="payment-list-price-detail clearfix">';
1333 $output .= '<div class="pull-left">';
1334 $output .= '<div class="payment-list-price-detail-total-price">'.$local['cs_total'].'</div>';
1335 $output .= '<div class="payment-list-price-detail-note">'.$local['cs_tax_fees'].'</div>';
1336 $output .= '</div>';
1337
1338 $output .= '<div class="pull-right text-right">';
1339 $output .= '<div class="payment-list-price-detail-total-price">'.homey_formatted_price($total_price).'</div>';
1340 $output .= '<a class="payment-list-detail-btn" data-toggle="collapse" data-target=".collapseExample" href="javascript:void(0);" aria-expanded="false" aria-controls="collapseExample">'.$local['cs_view_details'].'</a>';
1341 $output .= '</div>';
1342 $output .= '</div>';
1343
1344 $start_div = '<div class="collapse collapseExample" id="collapseExample">';
1345 }
1346
1347
1348 $output .= $start_div;
1349 $output .= '<ul>';
1350
1351 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1352 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_and_weekend_label'].') <span>'.$hours_total_price.'</span></li>';
1353
1354 } elseif($booking_has_weekend == 1) {
1355 $output .= '<li>'.esc_attr($price_per_hour).' x '.$no_of_hours.' '.$hour_label.' ('.$with_weekend_label.') <span>'.$hours_total_price.'</span></li>';
1356
1357 } elseif($booking_has_custom_pricing == 1) {
1358 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_label'].') <span>'.$hours_total_price.'</span></li>';
1359
1360 } else {
1361 $output .= '<li>'.$price_per_hour.' x '.$no_of_hours.' '.$hour_label.' <span>'.$hours_total_price.'</span></li>';
1362 }
1363
1364 if(!empty($additional_guests)) {
1365 $output .= '<li>'.$additional_guests.' '.$add_guest_label.' <span>'.homey_formatted_price($additional_guests_total_price).'</span></li>';
1366 }
1367
1368 if(!empty($reservation_meta['cleaning_fee']) && $reservation_meta['cleaning_fee'] != 0) {
1369 $output .= '<li>'.$local['cs_cleaning_fee'].' <span>'.$cleaning_fee.'</span></li>';
1370 }
1371
1372 if(!empty($extra_prices)) {
1373 $output .= $extra_prices['extra_html'];
1374 }
1375
1376 if(!empty($reservation_meta['city_fee']) && $reservation_meta['city_fee'] != 0) {
1377 $output .= '<li>'.$local['cs_city_fee'].' <span>'.$city_fee.'</span></li>';
1378 }
1379
1380 if(!empty($security_deposit) && $security_deposit != 0) {
1381 $output .= '<li>'.$local['cs_sec_deposit'].' <span>'.homey_formatted_price($security_deposit).'</span></li>';
1382 }
1383
1384 if(!empty($services_fee) && $services_fee != 0 && !$is_host) {
1385 $output .= '<li>'.$local['cs_services_fee'].' <span>'.homey_formatted_price($services_fee).'</span></li>';
1386 }
1387
1388 if(!empty($taxes) && $taxes != 0 ) {
1389 $output .= '<li>'.$local['cs_taxes'].' '.$taxes_percent.'% <span>'.homey_formatted_price($taxes).'</span></li>';
1390 }
1391
1392 if(!empty($upfront_payment) && $upfront_payment != 0) {
1393 if($is_host) {
1394 $upfront_payment = $upfront_payment - $services_fee;
1395 }
1396 $output .= '<li class="payment-due">'.$local['cs_payment_due'].' <span>'.homey_formatted_price($upfront_payment).'</span></li>';
1397 }
1398
1399 if(!empty($balance) && $balance != 0) {
1400 $output .= '<li><i class="fa fa-info-circle"></i> '.$local['cs_pay_rest_1'].' '.homey_formatted_price($balance).' '.$local['cs_pay_rest_2'].'</li>';
1401 }
1402
1403 $output .= '</ul>';
1404 $output .= '</div>';
1405
1406 return $output;
1407 }
1408}
1409
1410if( !function_exists('homey_calculate_hourly_booking_cost_admin') ) {
1411 function homey_calculate_hourly_booking_cost_admin($reservation_id, $collapse = false) {
1412 $prefix = 'homey_';
1413 $local = homey_get_localization();
1414 $allowded_html = array();
1415 $output = '';
1416
1417 if(empty($reservation_id)) {
1418 return;
1419 }
1420 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1421
1422 $listing_id = intval($reservation_meta['listing_id']);
1423 $check_in_date = wp_kses ( $reservation_meta['check_in_date'], $allowded_html );
1424 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1425 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1426 $guests = intval($reservation_meta['guests']);
1427
1428 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests);
1429
1430 $price_per_hour = homey_formatted_price($prices_array['price_per_hour'], true);
1431 $no_of_hours = $prices_array['hours_count'];
1432
1433 $hours_total_price = homey_formatted_price($prices_array['hours_total_price'], false);
1434
1435 $cleaning_fee = homey_formatted_price($prices_array['cleaning_fee']);
1436 $services_fee = $prices_array['services_fee'];
1437 $taxes = $prices_array['taxes'];
1438 $taxes_percent = $prices_array['taxes_percent'];
1439 $city_fee = homey_formatted_price($prices_array['city_fee']);
1440 $security_deposit = $prices_array['security_deposit'];
1441 $additional_guests = $prices_array['additional_guests'];
1442 $additional_guests_price = $prices_array['additional_guests_price'];
1443 $additional_guests_total_price = $prices_array['additional_guests_total_price'];
1444
1445 $upfront_payment = $prices_array['upfront_payment'];
1446 $balance = $prices_array['balance'];
1447 $total_price = $prices_array['total_price'];
1448
1449 $booking_has_weekend = $prices_array['booking_has_weekend'];
1450 $booking_has_custom_pricing = $prices_array['booking_has_custom_pricing'];
1451 $with_weekend_label = $local['with_weekend_label'];
1452
1453 if($no_of_hours > 1) {
1454 $hour_label = $local['hours_label'];
1455 } else {
1456 $hour_label = $local['hour_label'];
1457 }
1458
1459 if($additional_guests > 1) {
1460 $add_guest_label = $local['cs_add_guests'];
1461 } else {
1462 $add_guest_label = $local['cs_add_guest'];
1463 }
1464
1465 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1466 $output .= '<tr>
1467 <td class="manage-column">'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_and_weekend_label'].')</td>
1468 <td>'.$hours_total_price.'</td>
1469 </tr>';
1470
1471 } elseif($booking_has_weekend == 1) {
1472 $output .= '<tr>
1473 <td class="manage-column">'.esc_attr($price_per_hour).' x '.$no_of_hours.' '.$hour_label.' ('.$with_weekend_label.') </td>
1474 <td>'.$hours_total_price.'</td>
1475 </tr>';
1476
1477 } elseif($booking_has_custom_pricing == 1) {
1478 $output .= '<tr>
1479 <td class="manage-column">'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_label'].') </td>
1480 <td>'.$hours_total_price.'</td>
1481 </tr>';
1482
1483 } else {
1484 $output .= '<tr>
1485 <td class="manage-column">'.$price_per_hour.' x '.$no_of_hours.' '.$hour_label.' </td>
1486 <td>'.$hours_total_price.'</td>
1487 </tr>';
1488 }
1489
1490 if(!empty($additional_guests)) {
1491 $output .= '<tr><td class="manage-column">'.$additional_guests.' '.$add_guest_label.'</td> <td>'.homey_formatted_price($additional_guests_total_price).'</td></tr>';
1492 }
1493
1494 $output .= '<tr><td class="manage-column">'.$local['cs_cleaning_fee'].'</td> <td>'.$cleaning_fee.'</td></tr>';
1495 $output .= '<tr><td class="manage-column">'.$local['cs_city_fee'].'</td> <td>'.$city_fee.'</td></tr>';
1496
1497 if(!empty($security_deposit) && $security_deposit != 0) {
1498 $output .= '<tr><td class="manage-column">'.$local['cs_sec_deposit'].'</td> <td>'.homey_formatted_price($security_deposit).'</td></tr>';
1499 }
1500
1501 if(!empty($services_fee) && $services_fee != 0 ) {
1502 $output .= '<tr><td class="manage-column">'.$local['cs_services_fee'].'</td> <td>'.homey_formatted_price($services_fee).'</td></tr>';
1503 }
1504
1505 if(!empty($taxes) && $taxes != 0 ) {
1506 $output .= '<tr><td class="manage-column">'.$local['cs_taxes'].' '.$taxes_percent.'%</td> <td>'.homey_formatted_price($taxes).'</td></tr>';
1507 }
1508
1509
1510 $output .= '<tr class="payment-due"><td class="manage-column"><strong>'.$local['cs_total'].'</strong></td> <td><strong>'.homey_formatted_price($total_price).'</strong></td></tr>';
1511
1512
1513 if(!empty($upfront_payment) && $upfront_payment != 0) {
1514 $output .= '<tr class="payment-due"><td class="manage-column"><strong>'.$local['cs_payment_due'].'</strong></td> <td><strong>'.homey_formatted_price($upfront_payment).'</strong></td></tr>';
1515 }
1516
1517 if(!empty($balance) && $balance != 0) {
1518 $output .= '<tr><td class="manage-column"><i class="fa fa-info-circle"></i> '.$local['cs_pay_rest_1'].' <strong>'.homey_formatted_price($balance).'</strong> '.$local['cs_pay_rest_2'].'</td></tr>';
1519 }
1520
1521
1522
1523 return $output;
1524 }
1525}
1526
1527if( !function_exists('homey_calculate_hourly_reservation_cost_admin') ) {
1528 function homey_calculate_hourly_reservation_cost_admin($reservation_id, $collapse = false) {
1529 $prefix = 'homey_';
1530 $local = homey_get_localization();
1531 $allowded_html = array();
1532 $output = '';
1533
1534 if(empty($reservation_id)) {
1535 return;
1536 }
1537 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1538
1539 $listing_id = intval($reservation_meta['listing_id']);
1540 $check_in_date = wp_kses ( $reservation_meta['check_in_date'], $allowded_html );
1541 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1542 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1543 $guests = intval($reservation_meta['guests']);
1544
1545 $price_per_hour = homey_formatted_price($reservation_meta['price_per_hour'], true);
1546 $no_of_hours = $reservation_meta['no_of_hours'];
1547
1548 $hours_total_price = homey_formatted_price($reservation_meta['hours_total_price'], false);
1549
1550 $cleaning_fee = homey_formatted_price($reservation_meta['cleaning_fee']);
1551 $services_fee = $reservation_meta['services_fee'];
1552 $taxes = $reservation_meta['taxes'];
1553 $taxes_percent = $reservation_meta['taxes_percent'];
1554 $city_fee = homey_formatted_price($reservation_meta['city_fee']);
1555 $security_deposit = $reservation_meta['security_deposit'];
1556 $additional_guests = $reservation_meta['additional_guests'];
1557 $additional_guests_price = $reservation_meta['additional_guests_price'];
1558 $additional_guests_total_price = $reservation_meta['additional_guests_total_price'];
1559
1560 $upfront_payment = $reservation_meta['upfront'];
1561 $balance = $reservation_meta['balance'];
1562 $total_price = $reservation_meta['total'];
1563
1564 $booking_has_weekend = $reservation_meta['booking_has_weekend'];
1565 $booking_has_custom_pricing = $reservation_meta['booking_has_custom_pricing'];
1566 $with_weekend_label = $local['with_weekend_label'];
1567
1568 if($no_of_hours > 1) {
1569 $hour_label = $local['hours_label'];
1570 } else {
1571 $hour_label = $local['hour_label'];
1572 }
1573
1574 if($additional_guests > 1) {
1575 $add_guest_label = $local['cs_add_guests'];
1576 } else {
1577 $add_guest_label = $local['cs_add_guest'];
1578 }
1579
1580 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1581 $output .= '<tr>
1582 <td class="manage-column">'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_and_weekend_label'].')</td>
1583 <td>'.$hours_total_price.'</td>
1584 </tr>';
1585
1586 } elseif($booking_has_weekend == 1) {
1587 $output .= '<tr>
1588 <td class="manage-column">'.esc_attr($price_per_hour).' x '.$no_of_hours.' '.$hour_label.' ('.$with_weekend_label.') </td>
1589 <td>'.$hours_total_price.'</td>
1590 </tr>';
1591
1592 } elseif($booking_has_custom_pricing == 1) {
1593 $output .= '<tr>
1594 <td class="manage-column">'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_label'].') </td>
1595 <td>'.$hours_total_price.'</td>
1596 </tr>';
1597
1598 } else {
1599 $output .= '<tr>
1600 <td class="manage-column">'.$price_per_hour.' x '.$no_of_hours.' '.$hour_label.' </td>
1601 <td>'.$hours_total_price.'</td>
1602 </tr>';
1603 }
1604
1605 if(!empty($additional_guests)) {
1606 $output .= '<tr><td class="manage-column">'.$additional_guests.' '.$add_guest_label.'</td> <td>'.homey_formatted_price($additional_guests_total_price).'</td></tr>';
1607 }
1608
1609 $output .= '<tr><td class="manage-column">'.$local['cs_cleaning_fee'].'</td> <td>'.$cleaning_fee.'</td></tr>';
1610 $output .= '<tr><td class="manage-column">'.$local['cs_city_fee'].'</td> <td>'.$city_fee.'</td></tr>';
1611
1612 if(!empty($security_deposit) && $security_deposit != 0) {
1613 $output .= '<tr><td class="manage-column">'.$local['cs_sec_deposit'].'</td> <td>'.homey_formatted_price($security_deposit).'</td></tr>';
1614 }
1615
1616 if(!empty($services_fee) && $services_fee != 0 ) {
1617 $output .= '<tr><td class="manage-column">'.$local['cs_services_fee'].'</td> <td>'.homey_formatted_price($services_fee).'</td></tr>';
1618 }
1619
1620 if(!empty($taxes) && $taxes != 0 ) {
1621 $output .= '<tr><td class="manage-column">'.$local['cs_taxes'].' '.$taxes_percent.'%</td> <td>'.homey_formatted_price($taxes).'</td></tr>';
1622 }
1623
1624
1625 $output .= '<tr class="payment-due"><td class="manage-column"><strong>'.$local['cs_total'].'</strong></td> <td><strong>'.homey_formatted_price($total_price).'</strong></td></tr>';
1626
1627
1628 if(!empty($upfront_payment) && $upfront_payment != 0) {
1629 $output .= '<tr class="payment-due"><td class="manage-column"><strong>'.$local['cs_payment_due'].'</strong></td> <td><strong>'.homey_formatted_price($upfront_payment).'</strong></td></tr>';
1630 }
1631
1632 if(!empty($balance) && $balance != 0) {
1633 $output .= '<tr><td class="manage-column"><i class="fa fa-info-circle"></i> '.$local['cs_pay_rest_1'].' <strong>'.homey_formatted_price($balance).'</strong> '.$local['cs_pay_rest_2'].'</td></tr>';
1634 }
1635
1636
1637
1638 return $output;
1639 }
1640}
1641
1642if( !function_exists('homey_calculate_hourly_booking_cost_instance') ) {
1643 function homey_calculate_hourly_booking_cost_instance() {
1644 $prefix = 'homey_';
1645 $local = homey_get_localization();
1646 $allowded_html = array();
1647 $output = '';
1648
1649 $listing_id = intval($_GET['listing_id']);
1650 $check_in_date = wp_kses ( $_GET['check_in'], $allowded_html );
1651 $start_hour = wp_kses ( $_GET['start_hour'], $allowded_html );
1652 $end_hour = wp_kses ( $_GET['end_hour'], $allowded_html );
1653 $guests = intval($_GET['guest']);
1654 $extra_options = isset($_GET['extra_options']) ? $_GET['extra_options'] : '';
1655
1656 $check_in_hour = $check_in_date.' '.$start_hour;
1657 $check_out_hour = $check_in_date.' '.$end_hour;
1658
1659 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
1660
1661 $price_per_hour = homey_formatted_price($prices_array['price_per_hour'], true);
1662 $no_of_hours = $prices_array['hours_count'];
1663
1664 $hours_total_price = homey_formatted_price($prices_array['hours_total_price'], false);
1665
1666 $cleaning_fee = homey_formatted_price($prices_array['cleaning_fee']);
1667 $services_fee = $prices_array['services_fee'];
1668 $taxes = $prices_array['taxes'];
1669 $taxes_percent = $prices_array['taxes_percent'];
1670 $city_fee = homey_formatted_price($prices_array['city_fee']);
1671 $security_deposit = $prices_array['security_deposit'];
1672 $additional_guests = $prices_array['additional_guests'];
1673 $additional_guests_price = $prices_array['additional_guests_price'];
1674 $additional_guests_total_price = $prices_array['additional_guests_total_price'];
1675
1676 $upfront_payment = $prices_array['upfront_payment'];
1677 $balance = $prices_array['balance'];
1678 $total_price = $prices_array['total_price'];
1679
1680 $extra_prices_html = $prices_array['extra_prices_html'];
1681
1682 $booking_has_weekend = $prices_array['booking_has_weekend'];
1683 $booking_has_custom_pricing = $prices_array['booking_has_custom_pricing'];
1684 $with_weekend_label = $local['with_weekend_label'];
1685
1686 if($no_of_hours > 1) {
1687 $hour_label = $local['hours_label'];
1688 } else {
1689 $hour_label = $local['hour_label'];
1690 }
1691
1692 if($additional_guests > 1) {
1693 $add_guest_label = $local['cs_add_guests'];
1694 } else {
1695 $add_guest_label = $local['cs_add_guest'];
1696 }
1697
1698 $output = '<div class="payment-list-price-detail clearfix">';
1699 $output .= '<div class="pull-left">';
1700 $output .= '<div class="payment-list-price-detail-total-price">'.$local['cs_total'].'</div>';
1701 $output .= '<div class="payment-list-price-detail-note">'.$local['cs_tax_fees'].'</div>';
1702 $output .= '</div>';
1703
1704 $output .= '<div class="pull-right text-right">';
1705 $output .= '<div class="payment-list-price-detail-total-price">'.homey_formatted_price($total_price).'</div>';
1706 $output .= '<a class="payment-list-detail-btn" data-toggle="collapse" data-target=".collapseExample" href="javascript:void(0);" aria-expanded="false" aria-controls="collapseExample">'.$local['cs_view_details'].'</a>';
1707 $output .= '</div>';
1708 $output .= '</div>';
1709
1710 $output .= '<div class="collapse collapseExample" id="collapseExample">';
1711 $output .= '<ul>';
1712
1713 if($booking_has_custom_pricing == 1 && $booking_has_weekend == 1) {
1714 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_and_weekend_label'].') <span>'.$hours_total_price.'</span></li>';
1715
1716 } elseif($booking_has_weekend == 1) {
1717 $output .= '<li>'.esc_attr($price_per_hour).' x '.$no_of_hours.' '.$hour_label.' ('.$with_weekend_label.') <span>'.$hours_total_price.'</span></li>';
1718
1719 } elseif($booking_has_custom_pricing == 1) {
1720 $output .= '<li>'.$no_of_hours.' '.$hour_label.' ('.$local['with_custom_period_label'].') <span>'.$hours_total_price.'</span></li>';
1721
1722 } else {
1723 $output .= '<li>'.$price_per_hour.' x '.$no_of_hours.' '.$hour_label.' <span>'.$hours_total_price.'</span></li>';
1724 }
1725
1726 if(!empty($additional_guests)) {
1727 $output .= '<li>'.$additional_guests.' '.$add_guest_label.' <span>'.homey_formatted_price($additional_guests_total_price).'</span></li>';
1728 }
1729
1730 if(!empty($prices_array['cleaning_fee']) && $prices_array['cleaning_fee'] != 0) {
1731 $output .= '<li>'.$local['cs_cleaning_fee'].' <span>'.$cleaning_fee.'</span></li>';
1732 }
1733
1734 if(!empty($extra_prices_html)) {
1735 $output .= $extra_prices_html;
1736 }
1737
1738 if(!empty($prices_array['city_fee']) && $prices_array['city_fee'] != 0) {
1739 $output .= '<li>'.$local['cs_city_fee'].' <span>'.$city_fee.'</span></li>';
1740 }
1741
1742 if(!empty($security_deposit) && $security_deposit != 0) {
1743 $output .= '<li>'.$local['cs_sec_deposit'].' <span>'.homey_formatted_price($security_deposit).'</span></li>';
1744 }
1745
1746 if(!empty($services_fee) && $services_fee != 0 ) {
1747 $output .= '<li>'.$local['cs_services_fee'].' <span>'.homey_formatted_price($services_fee).'</span></li>';
1748 }
1749
1750 if(!empty($taxes) && $taxes != 0 ) {
1751 $output .= '<li>'.$local['cs_taxes'].' '.$taxes_percent.'% <span>'.homey_formatted_price($taxes).'</span></li>';
1752 }
1753
1754 if(!empty($upfront_payment) && $upfront_payment != 0) {
1755 $output .= '<li class="payment-due">'.$local['cs_payment_due'].' <span>'.homey_formatted_price($upfront_payment).'</span></li>';
1756 }
1757
1758 if(!empty($balance) && $balance != 0) {
1759 $output .= '<li><i class="fa fa-info-circle"></i> '.$local['cs_pay_rest_1'].' '.homey_formatted_price($balance).' '.$local['cs_pay_rest_2'].'</li>';
1760 }
1761 $output .= '</ul>';
1762 $output .= '</div>';
1763
1764 return $output;
1765 }
1766}
1767
1768/* -----------------------------------------------------------------------------------------------------------
1769* Stripe Form
1770-------------------------------------------------------------------------------------------------------------*/
1771if( !function_exists('homey_hourly_stripe_payment') ) {
1772 function homey_hourly_stripe_payment( $reservation_id ) {
1773
1774 $allowded_html = array();
1775
1776 $current_user = wp_get_current_user();
1777 $userID = $current_user->ID;
1778 $user_email = $current_user->user_email;
1779
1780 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1781
1782
1783 $listing_id = intval($reservation_meta['listing_id']);
1784 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1785 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1786 $guests = intval($reservation_meta['guests']);
1787
1788 $upfront_payment = floatval( $reservation_meta['upfront'] );
1789
1790 require_once( HOMEY_PLUGIN_PATH . '/classes/class-stripe.php' );
1791
1792 $stripe_payments = new Homey_Stripe();
1793
1794 print '<div class="stripe-wrapper" id="homey_stripe_simple"> ';
1795 $metadata=array(
1796 'userID' => $userID,
1797 'reservation_id_for_stripe' => $reservation_id,
1798 'is_hourly' => 1,
1799 'is_instance_booking' => 0,
1800 'extra_options' => 0,
1801 'payment_type' => 'reservation_fee',
1802 'message' => esc_html__( 'Reservation Payment','homey')
1803 );
1804
1805 $stripe_payments->homey_stripe_form($upfront_payment, $metadata);
1806 print'
1807 </div>';
1808
1809
1810 }
1811}
1812
1813if( !function_exists('homey_hourly_stripe_payment_old') ) {
1814 function homey_hourly_stripe_payment_old( $reservation_id ) {
1815
1816 require_once( HOMEY_PLUGIN_PATH . '/includes/stripe-php/init.php' );
1817 $stripe_secret_key = homey_option('stripe_secret_key');
1818 $stripe_publishable_key = homey_option('stripe_publishable_key');
1819 $allowded_html = array();
1820
1821 $stripe = array(
1822 "secret_key" => $stripe_secret_key,
1823 "publishable_key" => $stripe_publishable_key
1824 );
1825
1826 \Stripe\Stripe::setApiKey($stripe['secret_key']);
1827 $submission_currency = homey_option('payment_currency');
1828 $current_user = wp_get_current_user();
1829 $userID = $current_user->ID;
1830 $user_email = $current_user->user_email;
1831
1832 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
1833
1834
1835 $listing_id = intval($reservation_meta['listing_id']);
1836 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
1837 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
1838 $guests = intval($reservation_meta['guests']);
1839
1840 //$prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests);
1841
1842 $upfront_payment = floatval( $reservation_meta['upfront'] );
1843
1844 if( $submission_currency == 'JPY') {
1845 $upfront_payment = $upfront_payment;
1846 } else {
1847 $upfront_payment = $upfront_payment * 100;
1848 }
1849
1850
1851 print '
1852 <div class="homey_stripe_simple">
1853 <script src="https://checkout.stripe.com/checkout.js"
1854 class="stripe-button"
1855 data-key="' . $stripe_publishable_key . '"
1856 data-amount="' . $upfront_payment . '"
1857 data-email="' . $user_email . '"
1858 data-zip-code="true"
1859 data-billing-address="true"
1860 data-locale="'.get_locale().'"
1861 data-currency="' . $submission_currency . '"
1862 data-label="' . esc_html__('Pay with Credit Card', 'homey') . '"
1863 data-description="' . esc_html__('Reservation Payment', 'homey') . '">
1864 </script>
1865 </div>
1866 <input type="hidden" id="reservation_id_for_stripe" name="reservation_id_for_stripe" value="' . $reservation_id . '">
1867 <input type="hidden" id="reservation_pay" name="reservation_pay" value="1">
1868 <input type="hidden" id="is_hourly" name="is_hourly" value="1">
1869 <input type="hidden" id="is_instance_booking" name="is_instance_booking" value="0">
1870 <input type="hidden" name="extra_options" value="0">
1871 <input type="hidden" name="userID" value="' . $userID . '">
1872 <input type="hidden" id="pay_ammout" name="pay_ammout" value="' . $upfront_payment . '">
1873 ';
1874 }
1875}
1876
1877/* -----------------------------------------------------------------------------------------------------------
1878* Stripe Form instance
1879-------------------------------------------------------------------------------------------------------------*/
1880if( !function_exists('homey_hourly_stripe_payment_instance') ) {
1881 function homey_hourly_stripe_payment_instance($listing_id, $check_in, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $guests) {
1882
1883 $allowded_html = array();
1884 $current_user = wp_get_current_user();
1885 $userID = $current_user->ID;
1886 $user_email = $current_user->user_email;
1887
1888 $listing_id = intval($listing_id);
1889 $check_in_date = wp_kses ($check_in, $allowded_html);
1890 $renter_message = '';
1891 $guests = intval($guests);
1892
1893 $check_availability = check_hourly_booking_availability($check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $listing_id, $guests);
1894 $is_available = $check_availability['success'];
1895 $check_message = $check_availability['message'];
1896
1897 $extra_options = isset($_GET['extra_options']) ? $_GET['extra_options'] : '';
1898
1899 update_user_meta($userID, 'extra_prices', $extra_options);
1900
1901 if(!empty($extra_options)) {
1902 $extra_prices = 1;
1903 } else {
1904 $extra_prices = 0;
1905 }
1906
1907 if(!$is_available) {
1908
1909 echo json_encode(
1910 array(
1911 'success' => false,
1912 'message' => $check_message,
1913 'payment_execute_url' => ''
1914 )
1915 );
1916 wp_die();
1917
1918 } else {
1919
1920 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
1921 $upfront_payment = floatval( $prices_array['upfront_payment'] );
1922 }
1923
1924
1925 require_once( HOMEY_PLUGIN_PATH . '/classes/class-stripe.php' );
1926
1927 $stripe_payments = new Homey_Stripe();
1928
1929 print '<div class="stripe-wrapper" id="homey_stripe_simple"> ';
1930 $metadata=array(
1931 'userID' => $userID,
1932 'listing_id' => $listing_id,
1933 'check_in_date' => $check_in_date,
1934 'check_in_hour' => $check_in_hour,
1935 'check_out_hour' => $check_out_hour,
1936 'start_hour' => $start_hour,
1937 'end_hour' => $end_hour,
1938 'guests' => $guests,
1939 'extra_options' => $extra_prices,
1940 'is_hourly' => 1,
1941 'is_instance_booking' => 1,
1942 'extra_options' => 0,
1943 'payment_type' => 'reservation_fee',
1944 'guest_message' => $renter_message,
1945 'reservation_id_for_stripe' => 0,
1946 'message' => esc_html__( 'Reservation Payment','homey')
1947 );
1948
1949 $stripe_payments->homey_stripe_form($upfront_payment, $metadata);
1950 print'
1951 </div>';
1952
1953 }
1954}
1955
1956if( !function_exists('homey_hourly_stripe_payment_instance_old') ) {
1957 function homey_hourly_stripe_payment_instance_old($listing_id, $check_in, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $guests) {
1958
1959 require_once( HOMEY_PLUGIN_PATH . '/includes/stripe-php/init.php' );
1960 $stripe_secret_key = homey_option('stripe_secret_key');
1961 $stripe_publishable_key = homey_option('stripe_publishable_key');
1962 $allowded_html = array();
1963
1964 $stripe = array(
1965 "secret_key" => $stripe_secret_key,
1966 "publishable_key" => $stripe_publishable_key
1967 );
1968
1969 \Stripe\Stripe::setApiKey($stripe['secret_key']);
1970 $submission_currency = homey_option('payment_currency');
1971 $current_user = wp_get_current_user();
1972 $userID = $current_user->ID;
1973 $user_email = $current_user->user_email;
1974
1975 $listing_id = intval($listing_id);
1976 $check_in_date = wp_kses ($check_in, $allowded_html);
1977 $renter_message = '';
1978 $guests = intval($guests);
1979
1980 $check_availability = check_hourly_booking_availability($check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $listing_id, $guests);
1981 $is_available = $check_availability['success'];
1982 $check_message = $check_availability['message'];
1983
1984 $extra_options = isset($_GET['extra_options']) ? $_GET['extra_options'] : '';
1985
1986 update_user_meta($userID, 'extra_prices', $extra_options);
1987
1988 if(!empty($extra_options)) {
1989 $extra_prices = 1;
1990 } else {
1991 $extra_prices = 0;
1992 }
1993
1994 if(!$is_available) {
1995
1996 echo json_encode(
1997 array(
1998 'success' => false,
1999 'message' => $check_message,
2000 'payment_execute_url' => ''
2001 )
2002 );
2003 wp_die();
2004
2005 } else {
2006
2007 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
2008 $upfront_payment = floatval( $prices_array['upfront_payment'] );
2009 }
2010
2011 if( $submission_currency == 'JPY') {
2012 $upfront_payment = $upfront_payment;
2013 } else {
2014 $upfront_payment = $upfront_payment * 100;
2015 }
2016
2017
2018 print '
2019 <div class="homey_stripe_simple">
2020 <script src="https://checkout.stripe.com/checkout.js"
2021 class="stripe-button"
2022 data-key="' . $stripe_publishable_key . '"
2023 data-amount="' . $upfront_payment . '"
2024 data-email="' . $user_email . '"
2025 data-zip-code="true"
2026 data-billing-address="true"
2027 data-locale="'.get_locale().'"
2028 data-currency="' . $submission_currency . '"
2029 data-label="' . esc_html__('Pay with Credit Card', 'homey') . '"
2030 data-description="' . esc_html__('Reservation Payment', 'homey') . '">
2031 </script>
2032 </div>
2033 <input type="hidden" id="reservation_id_for_stripe" name="reservation_id_for_stripe" value="0">
2034 <input type="hidden" id="reservation_pay" name="reservation_pay" value="1">
2035 <input type="hidden" id="is_instance_booking" name="is_instance_booking" value="1">
2036 <input type="hidden" name="check_in_date" value="'.$check_in_date.'">
2037 <input type="hidden" name="check_in_hour" value="'.$check_in_hour.'">
2038 <input type="hidden" name="check_out_hour" value="'.$check_out_hour.'">
2039 <input type="hidden" name="start_hour" value="'.$start_hour.'">
2040 <input type="hidden" name="end_hour" value="'.$end_hour.'">
2041 <input type="hidden" name="guests" value="'.$guests.'">
2042 <input type="hidden" name="extra_options" value="'.$extra_prices.'">
2043 <input type="hidden" name="listing_id" value="'.$listing_id.'">
2044 <input type="hidden" id="is_hourly" name="is_hourly" value="1">
2045 <input type="hidden" id="guest_message" name="guest_message" value="'.$renter_message.'">
2046 <input type="hidden" name="userID" value="' . $userID . '">
2047 <input type="hidden" id="pay_ammout" name="pay_ammout" value="' . $upfront_payment . '">
2048 ';
2049 }
2050}
2051
2052add_action( 'wp_ajax_homey_hourly_booking_paypal_payment', 'homey_hourly_booking_paypal_payment' );
2053if( !function_exists('homey_hourly_booking_paypal_payment') ) {
2054 function homey_hourly_booking_paypal_payment() {
2055 global $current_user;
2056 $allowded_html = array();
2057 $blogInfo = esc_url( home_url('/') );
2058 wp_get_current_user();
2059 $userID = $current_user->ID;
2060 $local = homey_get_localization();
2061 $reservation_id = intval($_POST['reservation_id']);
2062
2063 //check security
2064 $nonce = $_REQUEST['security'];
2065 if ( ! wp_verify_nonce( $nonce, 'checkout-security-nonce' ) ) {
2066
2067 echo json_encode(
2068 array(
2069 'success' => false,
2070 'message' => $local['security_check_text']
2071 )
2072 );
2073 wp_die();
2074 }
2075
2076 if(empty($reservation_id)) {
2077 echo json_encode(
2078 array(
2079 'success' => false,
2080 'message' => $local['something_went_wrong']
2081 )
2082 );
2083 wp_die();
2084 }
2085
2086 $reservation = get_post($reservation_id);
2087
2088 if( $reservation->post_author != $userID ) {
2089 echo json_encode(
2090 array(
2091 'success' => false,
2092 'message' => $local['belong_to']
2093 )
2094 );
2095 wp_die();
2096 }
2097 $reservation_status = get_post_meta($reservation_id, 'reservation_status', true);
2098
2099 if( $reservation_status != 'available') {
2100 echo json_encode(
2101 array(
2102 'success' => false,
2103 'message' => $local['something_went_wrong']
2104 )
2105 );
2106 wp_die();
2107 }
2108
2109
2110 $currency = homey_option('payment_currency');
2111 $reservation_meta = get_post_meta($reservation_id, 'reservation_meta', true);
2112
2113 $listing_id = intval($reservation_meta['listing_id']);
2114 $check_in_hour = wp_kses ( $reservation_meta['check_in_hour'], $allowded_html );
2115 $check_out_hour = wp_kses ( $reservation_meta['check_out_hour'], $allowded_html );
2116 $guests = intval($reservation_meta['guests']);
2117 $extra_options = get_post_meta($reservation_id, 'extra_options', true);
2118
2119 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
2120
2121
2122 $is_paypal_live = homey_option('paypal_api');
2123 $host = 'https://api.sandbox.paypal.com';
2124 $upfront_payment = floatval( $reservation_meta['upfront'] );
2125 $submission_curency = esc_html( $currency );
2126 $payment_description = esc_html__('Reservation payment on ','homey').$blogInfo;
2127
2128 $total_price = number_format( $upfront_payment, 2, '.','' );
2129
2130 // Check if payal live
2131 if( $is_paypal_live =='live'){
2132 $host='https://api.paypal.com';
2133 }
2134
2135 $url = $host.'/v1/oauth2/token';
2136 $postArgs = 'grant_type=client_credentials';
2137
2138 // Get Access token
2139 $paypal_token = homey_get_paypal_access_token( $url, $postArgs );
2140 $url = $host.'/v1/payments/payment';
2141
2142 $payment_page_link = homey_get_template_link_2('template/dashboard-payment.php');
2143 $reservation_page_link = homey_get_template_link('template/dashboard-reservations.php');
2144
2145 $cancel_link = add_query_arg( array('reservation_id' => $reservation_id), $payment_page_link );
2146 $return_link = add_query_arg( 'reservation_detail', $reservation_id, $reservation_page_link );
2147
2148 $payment = array(
2149 'intent' => 'sale',
2150 "redirect_urls" => array(
2151 "return_url" => $return_link,
2152 "cancel_url" => $cancel_link
2153 ),
2154 'payer' => array("payment_method" => "paypal"),
2155 );
2156
2157 /* Prepare basic payment details
2158 *--------------------------------------*/
2159 $payment['transactions'][0] = array(
2160 'amount' => array(
2161 'total' => $total_price,
2162 'currency' => $submission_curency,
2163 'details' => array(
2164 'subtotal' => $total_price,
2165 'tax' => '0.00',
2166 'shipping' => '0.00'
2167 )
2168 ),
2169 'description' => $payment_description
2170 );
2171
2172
2173 /* Prepare individual items
2174 *--------------------------------------*/
2175 $payment['transactions'][0]['item_list']['items'][] = array(
2176 'quantity' => '1',
2177 'name' => esc_html__( 'Reservation ID','homey').' '.$reservation_id.' '.esc_html__( 'Listing ID','homey').' '.$listing_id,
2178 'price' => $total_price,
2179 'currency' => $submission_curency,
2180 'sku' => 'Paid Reservation',
2181 );
2182
2183 /* Convert PHP array into json format
2184 *--------------------------------------*/
2185 $jsonEncode = json_encode($payment);
2186 $json_response = homey_execute_paypal_request( $url, $jsonEncode, $paypal_token );
2187
2188 //print_r($json_response);
2189 foreach ($json_response['links'] as $link) {
2190 if($link['rel'] == 'execute'){
2191 $payment_execute_url = $link['href'];
2192 } else if($link['rel'] == 'approval_url'){
2193 $payment_approval_url = $link['href'];
2194 }
2195 }
2196
2197 // Save data in database for further use on processor page
2198 $output['payment_execute_url'] = $payment_execute_url;
2199 $output['paypal_token'] = $paypal_token;
2200 $output['reservation_id'] = $reservation_id;
2201
2202 $output['listing_id'] = '';
2203 $output['check_in_date'] = '';
2204 $output['check_in_hour'] = '';
2205 $output['check_out_hour'] = '';
2206 $output['guests'] = '';
2207 $output['extra_options'] = '';
2208 $output['renter_message'] = '';
2209 $output['is_instance_booking'] = 0;
2210 $output['is_hourly'] = 1;
2211
2212 $save_output[$userID] = $output;
2213 update_option('homey_paypal_transfer',$save_output);
2214
2215 echo json_encode(
2216 array(
2217 'success' => true,
2218 'message' => 'success',
2219 'payment_execute_url' => $payment_approval_url
2220 )
2221 );
2222
2223 wp_die();
2224 }
2225}
2226
2227add_action( 'wp_ajax_homey_hourly_instance_booking_paypal_payment', 'homey_hourly_instance_booking_paypal_payment' );
2228if( !function_exists('homey_hourly_instance_booking_paypal_payment') ) {
2229 function homey_hourly_instance_booking_paypal_payment() {
2230 global $current_user;
2231 $allowded_html = array();
2232 $blogInfo = esc_url( home_url('/') );
2233 wp_get_current_user();
2234 $userID = $current_user->ID;
2235 $local = homey_get_localization();
2236
2237 //check security
2238 $nonce = $_REQUEST['security'];
2239 if ( ! wp_verify_nonce( $nonce, 'checkout-security-nonce' ) ) {
2240
2241 echo json_encode(
2242 array(
2243 'success' => false,
2244 'message' => $local['security_check_text']
2245 )
2246 );
2247 wp_die();
2248 }
2249
2250 $currency = homey_option('payment_currency');
2251
2252 $listing_id = intval($_POST['listing_id']);
2253 $check_in_date = wp_kses ($_POST['check_in'], $allowded_html);
2254 $renter_message = wp_kses ($_POST['renter_message'], $allowded_html);
2255 $guests = intval($_POST['guests']);
2256 $extra_options = $_POST['extra_options'];
2257
2258 $check_in_hour = wp_kses ($_POST['check_in_hour'], $allowded_html);
2259 $check_out_hour = wp_kses ($_POST['check_out_hour'], $allowded_html);
2260 $start_hour = wp_kses ($_POST['start_hour'], $allowded_html);
2261 $end_hour = wp_kses ($_POST['end_hour'], $allowded_html);
2262
2263 $check_availability = check_hourly_booking_availability($check_in_date, $check_in_hour, $check_out_hour, $start_hour, $end_hour, $listing_id, $guests);
2264
2265 $is_available = $check_availability['success'];
2266 $check_message = $check_availability['message'];
2267
2268 if(!$is_available) {
2269
2270 echo json_encode(
2271 array(
2272 'success' => false,
2273 'message' => $check_message,
2274 'payment_execute_url' => ''
2275 )
2276 );
2277 wp_die();
2278
2279 } else {
2280
2281 $prices_array = homey_get_hourly_prices($check_in_hour, $check_out_hour, $listing_id, $guests, $extra_options);
2282
2283 $is_paypal_live = homey_option('paypal_api');
2284 $host = 'https://api.sandbox.paypal.com';
2285 $upfront_payment = floatval( $prices_array['upfront_payment'] );
2286 $submission_curency = esc_html( $currency );
2287 $payment_description = esc_html__('Reservation payment on ','homey').$blogInfo;
2288
2289 $total_price = number_format( $upfront_payment, 2, '.','' );
2290
2291 // Check if payal live
2292 if( $is_paypal_live =='live'){
2293 $host='https://api.paypal.com';
2294 }
2295
2296 $url = $host.'/v1/oauth2/token';
2297 $postArgs = 'grant_type=client_credentials';
2298
2299 // Get Access token
2300 $paypal_token = homey_get_paypal_access_token( $url, $postArgs );
2301 $url = $host.'/v1/payments/payment';
2302
2303 $instance_payment_page_link = homey_get_template_link_2('template/template-instance-booking.php');
2304 $reservation_page_link = homey_get_template_link('template/dashboard-reservations.php');
2305
2306 $cancel_link = add_query_arg(
2307 array(
2308 'check_in' => $check_in_date,
2309 'start_hour' => $start_hour,
2310 'end_hour' => $end_hour,
2311 'guest' => $guests,
2312 'listing_id' => $listing_id,
2313 ), $instance_payment_page_link );
2314
2315 $return_link = add_query_arg( 'reservation_detail', $reservation_id, $reservation_page_link );
2316
2317 $payment = array(
2318 'intent' => 'sale',
2319 "redirect_urls" => array(
2320 "return_url" => $return_link,
2321 "cancel_url" => $cancel_link
2322 ),
2323 'payer' => array("payment_method" => "paypal"),
2324 );
2325
2326 /* Prepare basic payment details
2327 *--------------------------------------*/
2328 $payment['transactions'][0] = array(
2329 'amount' => array(
2330 'total' => $total_price,
2331 'currency' => $submission_curency,
2332 'details' => array(
2333 'subtotal' => $total_price,
2334 'tax' => '0.00',
2335 'shipping' => '0.00'
2336 )
2337 ),
2338 'description' => $payment_description
2339 );
2340
2341
2342 /* Prepare individual items
2343 *--------------------------------------*/
2344 $payment['transactions'][0]['item_list']['items'][] = array(
2345 'quantity' => '1',
2346 'name' => esc_html__('Reservation Payment','homey'),
2347 'price' => $total_price,
2348 'currency' => $submission_curency,
2349 'sku' => 'Paid Reservation',
2350 );
2351
2352 /* Convert PHP array into json format
2353 *--------------------------------------*/
2354 $jsonEncode = json_encode($payment);
2355 $json_response = homey_execute_paypal_request( $url, $jsonEncode, $paypal_token );
2356
2357 //print_r($json_response);
2358 foreach ($json_response['links'] as $link) {
2359 if($link['rel'] == 'execute'){
2360 $payment_execute_url = $link['href'];
2361 } else if($link['rel'] == 'approval_url'){
2362 $payment_approval_url = $link['href'];
2363 }
2364 }
2365
2366 // Save data in database for further use on processor page
2367 $output['payment_execute_url'] = $payment_execute_url;
2368 $output['paypal_token'] = $paypal_token;
2369 $output['reservation_id'] = '';
2370 $output['listing_id'] = $listing_id;
2371 $output['check_in_date'] = $check_in_date;
2372 $output['check_in_hour'] = $check_in_hour;
2373 $output['check_out_hour'] = $check_out_hour;
2374 $output['start_hour'] = $start_hour;
2375 $output['end_hour'] = $end_hour;
2376 $output['extra_options'] = $extra_options;
2377 $output['guests'] = $guests;
2378 $output['renter_message'] = $renter_message;
2379 $output['is_instance_booking'] = 1;
2380 $output['is_hourly'] = 1;
2381
2382 $save_output[$userID] = $output;
2383 update_option('homey_paypal_transfer',$save_output);
2384
2385 echo json_encode(
2386 array(
2387 'success' => true,
2388 'message' => $local['processing_text'],
2389 'payment_execute_url' => $payment_approval_url
2390 )
2391 );
2392 wp_die();
2393 }
2394 }
2395}
2396
2397add_action('wp_ajax_nopriv_homey_instance_hourly_booking', 'homey_instance_hourly_booking');
2398add_action('wp_ajax_homey_instance_hourly_booking', 'homey_instance_hourly_booking');
2399if(!function_exists('homey_instance_hourly_booking')) {
2400 function homey_instance_hourly_booking() {
2401 global $current_user;
2402 $current_user = wp_get_current_user();
2403 $userID = $current_user->ID;
2404 $local = homey_get_localization();
2405 $allowded_html = array();
2406 $instace_page_link = homey_get_template_link_2('template/template-instance-booking.php');
2407
2408 if ( !is_user_logged_in() || $userID === 0 ) {
2409 echo json_encode(
2410 array(
2411 'success' => false,
2412 'message' => $local['login_for_reservation']
2413 )
2414 );
2415 wp_die();
2416 }
2417
2418 if ( empty($instace_page_link) ) {
2419 echo json_encode(
2420 array(
2421 'success' => false,
2422 'message' => $local['instance_booking_page']
2423 )
2424 );
2425 wp_die();
2426 }
2427
2428 //check security
2429 $nonce = $_REQUEST['security'];
2430 if ( ! wp_verify_nonce( $nonce, 'reservation-security-nonce' ) ) {
2431
2432 echo json_encode(
2433 array(
2434 'success' => false,
2435 'message' => $local['security_check_text']
2436 )
2437 );
2438 wp_die();
2439 }
2440
2441 $listing_id = intval($_POST['listing_id']);
2442 $listing_owner_id = get_post_field( 'post_author', $listing_id );
2443 $check_in_date = wp_kses ( $_POST['check_in_date'], $allowded_html );
2444 $start_hour = wp_kses ( $_POST['start_hour'], $allowded_html );
2445 $end_hour = wp_kses ( $_POST['end_hour'], $allowded_html );
2446 $guests = intval($_POST['guests']);
2447 $extra_options = $_POST['extra_options'];
2448
2449 if($userID == $listing_owner_id) {
2450 echo json_encode(
2451 array(
2452 'success' => false,
2453 'message' => $local['own_listing_error']
2454 )
2455 );
2456 wp_die();
2457 }
2458
2459 if(!homey_is_renter()) {
2460 echo json_encode(
2461 array(
2462 'success' => false,
2463 'message' => $local['host_user_cannot_book']
2464 )
2465 );
2466 wp_die();
2467 }
2468
2469 $instance_page = add_query_arg( array(
2470 'check_in' => $check_in_date,
2471 'start_hour' => $start_hour,
2472 'end_hour' => $end_hour,
2473 'guest' => $guests,
2474 'extra_options' => $extra_options,
2475 'listing_id' => $listing_id,
2476 ), $instace_page_link );
2477
2478 echo json_encode(
2479 array(
2480 'success' => true,
2481 'message' => '',
2482 'instance_url' => $instance_page
2483 )
2484 );
2485 wp_die();
2486 }
2487}
2488
2489if(!function_exists('homey_get_booked_hours')) {
2490 function homey_get_booked_hours($listing_id) {
2491 $now = time();
2492 //$daysAgo = $now-3*24*60*60;
2493 $daysAgo = $now-1*24*60*60;
2494
2495 $args = array(
2496 'post_type' => 'homey_reservation',
2497 'post_status' => 'any',
2498 'posts_per_page' => -1,
2499 'meta_query' => array(
2500 'relation' => 'AND',
2501 array(
2502 'key' => 'reservation_listing_id',
2503 'value' => $listing_id,
2504 'type' => 'NUMERIC',
2505 'compare' => '='
2506 ),
2507 array(
2508 'key' => 'reservation_status',
2509 'value' => 'booked',
2510 'type' => 'CHAR',
2511 'compare' => '='
2512 )
2513 )
2514 );
2515
2516 $booked_hours_array = get_post_meta($listing_id, 'reservation_booked_hours', true );
2517
2518 if( !is_array($booked_hours_array) || empty($booked_hours_array) ) {
2519 $booked_hours_array = array();
2520 }
2521
2522 $wpQry = new WP_Query($args);
2523
2524 if ($wpQry->have_posts()) {
2525
2526 while ($wpQry->have_posts()): $wpQry->the_post();
2527
2528 $resID = get_the_ID();
2529
2530 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2531 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2532
2533 $unix_time_start = strtotime ($check_in_date);
2534
2535 if ($unix_time_start > $daysAgo) {
2536
2537 $check_in = new DateTime($check_in_date);
2538 $check_in_unix = $check_in->getTimestamp();
2539 $check_out = new DateTime($check_out_date);
2540 $check_out_unix = $check_out->getTimestamp();
2541
2542
2543 $booked_hours_array[$check_in_unix] = $resID;
2544
2545 $check_in_unix = $check_in->getTimestamp();
2546
2547 while ($check_in_unix < $check_out_unix){
2548
2549 $booked_hours_array[$check_in_unix] = $resID;
2550
2551 //$check_in->modify('+1 hour');
2552 $check_in->modify('+30 minutes');
2553 $check_in_unix = $check_in->getTimestamp();
2554 }
2555
2556 }
2557 endwhile;
2558 wp_reset_postdata();
2559 }
2560
2561 return $booked_hours_array;
2562
2563 }
2564}
2565
2566
2567if(!function_exists('homey_get_booking_pending_hours')) {
2568 function homey_get_booking_pending_hours($listing_id) {
2569 $now = time();
2570 //$daysAgo = $now-3*24*60*60;
2571 $daysAgo = $now-1*24*60*60;
2572
2573 $args = array(
2574 'post_type' => 'homey_reservation',
2575 'post_status' => 'any',
2576 'posts_per_page' => -1,
2577 'meta_query' => array(
2578 'relation' => 'AND',
2579 array(
2580 'key' => 'reservation_listing_id',
2581 'value' => $listing_id,
2582 'type' => 'NUMERIC',
2583 'compare' => '='
2584 ),
2585 array(
2586 'key' => 'reservation_status',
2587 'value' => 'declined',
2588 'type' => 'CHAR',
2589 'compare' => '!='
2590 )
2591 )
2592 );
2593
2594 $pending_dates_array = get_post_meta($listing_id, 'reservation_pending_hours', true );
2595
2596 if( !is_array($pending_dates_array) || empty($pending_dates_array) ) {
2597 $pending_dates_array = array();
2598 }
2599
2600 $wpQry = new WP_Query($args);
2601
2602 if ($wpQry->have_posts()) {
2603
2604 while ($wpQry->have_posts()): $wpQry->the_post();
2605
2606 $resID = get_the_ID();
2607
2608 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2609 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2610
2611 $unix_time_start = strtotime ($check_in_date);
2612
2613 if ($unix_time_start > $daysAgo) {
2614
2615 $check_in = new DateTime($check_in_date);
2616 $check_in_unix = $check_in->getTimestamp();
2617 $check_out = new DateTime($check_out_date);
2618 $check_out_unix = $check_out->getTimestamp();
2619
2620
2621 $pending_dates_array[$check_in_unix] = $resID;
2622
2623 $check_in_unix = $check_in->getTimestamp();
2624
2625 while ($check_in_unix < $check_out_unix){
2626
2627 $pending_dates_array[$check_in_unix] = $resID;
2628
2629 //$check_in->modify('+1 hour');
2630 $check_in->modify('+30 minutes');
2631 $check_in_unix = $check_in->getTimestamp();
2632 }
2633
2634 }
2635 endwhile;
2636 wp_reset_postdata();
2637 }
2638
2639 return $pending_dates_array;
2640
2641 }
2642}
2643
2644if (!function_exists("homey_make_hours_booked")) {
2645 function homey_make_hours_booked($listing_id, $resID) {
2646 $now = time();
2647 $daysAgo = $now-3*24*60*60;
2648
2649 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2650 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2651
2652 $reservation_dates_array = get_post_meta($listing_id, 'reservation_booked_hours', true );
2653
2654 if( !is_array($reservation_dates_array) || empty($reservation_dates_array) ) {
2655 $reservation_dates_array = array();
2656 }
2657
2658 $unix_time_start = strtotime ($check_in_date);
2659
2660 if ($unix_time_start > $daysAgo) {
2661 $check_in = new DateTime($check_in_date);
2662 $check_in_unix = $check_in->getTimestamp();
2663 $check_out = new DateTime($check_out_date);
2664 $check_out_unix = $check_out->getTimestamp();
2665
2666 $check_in_unix = $check_in->getTimestamp();
2667
2668 while ($check_in_unix < $check_out_unix){
2669
2670 $reservation_dates_array[$check_in_unix] = $resID;
2671
2672 $check_in->modify('+30 minutes');
2673 $check_in_unix = $check_in->getTimestamp();
2674 }
2675 }
2676
2677 return $reservation_dates_array;
2678 }
2679}
2680
2681if (!function_exists("homey_remove_booking_pending_hours")) {
2682 function homey_remove_booking_pending_hours($listing_id, $resID) {
2683 $now = time();
2684 $daysAgo = $now-3*24*60*60;
2685
2686 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2687 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2688
2689 $pending_dates_array = get_post_meta($listing_id, 'reservation_pending_hours', true );
2690
2691 if( !is_array($pending_dates_array) || empty($pending_dates_array) ) {
2692 $pending_dates_array = array();
2693 }
2694
2695 $unix_time_start = strtotime ($check_in_date);
2696
2697 if ($unix_time_start > $daysAgo) {
2698 $check_in = new DateTime($check_in_date);
2699 $check_in_unix = $check_in->getTimestamp();
2700 $check_out = new DateTime($check_out_date);
2701 $check_out_unix = $check_out->getTimestamp();
2702
2703 $check_in_unix = $check_in->getTimestamp();
2704
2705 while ($check_in_unix < $check_out_unix){
2706
2707 unset($pending_dates_array[$check_in_unix]);
2708
2709 $check_in->modify('+30 minutes');
2710 $check_in_unix = $check_in->getTimestamp();
2711 }
2712 }
2713
2714 return $pending_dates_array;
2715 }
2716}
2717
2718if (!function_exists("homey_remove_booked_hours")) {
2719 function homey_remove_booked_hours($listing_id, $resID) {
2720 $now = time();
2721 $daysAgo = $now-3*24*60*60;
2722
2723 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2724 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2725
2726 $pending_dates_array = get_post_meta($listing_id, 'reservation_booked_hours', true );
2727
2728 if( !is_array($pending_dates_array) || empty($pending_dates_array) ) {
2729 $pending_dates_array = array();
2730 }
2731
2732 $unix_time_start = strtotime ($check_in_date);
2733
2734 if ($unix_time_start > $daysAgo) {
2735 $check_in = new DateTime($check_in_date);
2736 $check_in_unix = $check_in->getTimestamp();
2737 $check_out = new DateTime($check_out_date);
2738 $check_out_unix = $check_out->getTimestamp();
2739
2740 $check_in_unix = $check_in->getTimestamp();
2741
2742 while ($check_in_unix < $check_out_unix){
2743
2744 unset($pending_dates_array[$check_in_unix]);
2745
2746 $check_in->modify('+30 minutes');
2747 $check_in_unix = $check_in->getTimestamp();
2748 }
2749 }
2750
2751 return $pending_dates_array;
2752 }
2753}
2754
2755if(!function_exists('homey_get_booked_hours_slots')) {
2756 function homey_get_booked_hours_slots($listing_id) {
2757 $args = array(
2758 'post_type' => 'homey_reservation',
2759 'post_status' => 'any',
2760 'posts_per_page' => -1,
2761 'meta_query' => array(
2762 'relation' => 'AND',
2763 array(
2764 'key' => 'reservation_listing_id',
2765 'value' => $listing_id,
2766 'type' => 'NUMERIC',
2767 'compare' => '='
2768 ),
2769 array(
2770 'key' => 'reservation_status',
2771 'value' => 'booked',
2772 'type' => 'CHAR',
2773 'compare' => '='
2774 )
2775 )
2776 );
2777
2778 $booked_array = array();
2779
2780 $wpQry = new WP_Query($args);
2781
2782 if ($wpQry->have_posts()) {
2783
2784 while ($wpQry->have_posts()): $wpQry->the_post();
2785
2786 $resID = get_the_ID();
2787
2788 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2789 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2790
2791 $check_in_date = strtotime($check_in_date);
2792 $check_out_date = strtotime($check_out_date);
2793
2794 $booked_array[$check_in_date] = $check_out_date;
2795
2796 endwhile;
2797 wp_reset_postdata();
2798 }
2799
2800 return $booked_array;
2801 }
2802}
2803
2804if(!function_exists('homey_get_pending_hours_slots')) {
2805 function homey_get_pending_hours_slots($listing_id) {
2806 $args = array(
2807 'post_type' => 'homey_reservation',
2808 'post_status' => 'any',
2809 'posts_per_page' => -1,
2810 'meta_query' => array(
2811 'relation' => 'AND',
2812 array(
2813 'key' => 'reservation_listing_id',
2814 'value' => $listing_id,
2815 'type' => 'NUMERIC',
2816 'compare' => '='
2817 ),
2818 array(
2819 'key' => 'reservation_status',
2820 'value' => 'declined',
2821 'type' => 'CHAR',
2822 'compare' => '!='
2823 ),
2824 array(
2825 'key' => 'reservation_status',
2826 'value' => 'booked',
2827 'type' => 'CHAR',
2828 'compare' => '!='
2829 )
2830 )
2831 );
2832
2833 $pending_array = array();
2834
2835 $wpQry = new WP_Query($args);
2836
2837 if ($wpQry->have_posts()) {
2838
2839 while ($wpQry->have_posts()): $wpQry->the_post();
2840
2841 $resID = get_the_ID();
2842
2843 $check_in_date = get_post_meta( $resID, 'reservation_checkin_hour', true );
2844 $check_out_date = get_post_meta( $resID, 'reservation_checkout_hour', true );
2845
2846 $check_in_date = strtotime($check_in_date);
2847 $check_out_date = strtotime($check_out_date);
2848
2849 $pending_array[$check_in_date] = $check_out_date;
2850
2851 endwhile;
2852 wp_reset_postdata();
2853 }
2854
2855 return $pending_array;
2856 }
2857}
2858
2859add_action( 'wp_ajax_homey_decline_hourly_reservation', 'homey_decline_hourly_reservation' );
2860if(!function_exists('homey_decline_hourly_reservation')) {
2861 function homey_decline_hourly_reservation() {
2862 global $current_user;
2863 $current_user = wp_get_current_user();
2864 $userID = $current_user->ID;
2865 $local = homey_get_localization();
2866
2867 $reservation_id = intval($_POST['reservation_id']);
2868 $listing_id = get_post_meta($reservation_id, 'reservation_listing_id', true);
2869 $reason = sanitize_text_field($_POST['reason']);
2870
2871 $listing_owner = get_post_meta($reservation_id, 'listing_owner', true);
2872 $listing_renter = get_post_meta($reservation_id, 'listing_renter', true);
2873
2874 $renter = homey_usermeta($listing_renter);
2875 $renter_email = $renter['email'];
2876
2877 if( $listing_owner != $userID ) {
2878 echo json_encode(
2879 array(
2880 'success' => false,
2881 'message' => $local['listing_owner_text']
2882 )
2883 );
2884 wp_die();
2885 }
2886
2887 // Set reservation status from under_review to available
2888 update_post_meta($reservation_id, 'reservation_status', 'declined');
2889 update_post_meta($reservation_id, 'res_decline_reason', $reason);
2890
2891 //Remove Pending Dates
2892 $pending_dates_array = homey_remove_booking_pending_hours($listing_id, $reservation_id);
2893 update_post_meta($listing_id, 'reservation_pending_hours', $pending_dates_array);
2894
2895 echo json_encode(
2896 array(
2897 'success' => true,
2898 'message' => esc_html__('success', 'homey')
2899 )
2900 );
2901
2902 $email_args = array('reservation_detail_url' => reservation_detail_link($reservation_id) );
2903 homey_email_composer( $renter_email, 'declined_reservation', $email_args );
2904 wp_die();
2905 }
2906}
2907
2908add_action( 'wp_ajax_homey_cancelled_hourly_reservation', 'homey_cancelled_hourly_reservation' );
2909if(!function_exists('homey_cancelled_hourly_reservation')) {
2910 function homey_cancelled_hourly_reservation() {
2911 global $current_user;
2912 $current_user = wp_get_current_user();
2913 $userID = $current_user->ID;
2914 $local = homey_get_localization();
2915
2916 $reservation_id = intval($_POST['reservation_id']);
2917 $listing_id = get_post_meta($reservation_id, 'reservation_listing_id', true);
2918 $reason = sanitize_text_field($_POST['reason']);
2919 $host_cancel = sanitize_text_field($_POST['host_cancel']);
2920
2921 $listing_owner = get_post_meta($reservation_id, 'listing_owner', true);
2922 $listing_renter = get_post_meta($reservation_id, 'listing_renter', true);
2923
2924 if( ($listing_renter != $userID) && ($listing_owner != $userID) ) {
2925 echo json_encode(
2926 array(
2927 'success' => false,
2928 'message' => $local['listing_renter_text']
2929 )
2930 );
2931 wp_die();
2932 }
2933
2934 if(empty($reason)) {
2935 echo json_encode(
2936 array(
2937 'success' => false,
2938 'message' => $local['reason_text_req']
2939 )
2940 );
2941 wp_die();
2942 }
2943
2944 // Set reservation status from under_review to available
2945 update_post_meta($reservation_id, 'reservation_status', 'cancelled');
2946 update_post_meta($reservation_id, 'res_cancel_reason', $reason);
2947
2948 //Remove Pending Dates
2949 $pending_dates_array = homey_remove_booking_pending_hours($listing_id, $reservation_id);
2950 update_post_meta($listing_id, 'reservation_pending_hours', $pending_dates_array);
2951
2952 //Remove Booked Dates
2953 $booked_dates_array = homey_remove_booked_hours($listing_id, $reservation_id);
2954 update_post_meta($listing_id, 'reservation_booked_hours', $booked_dates_array);
2955
2956 echo json_encode(
2957 array(
2958 'success' => true,
2959 'message' => esc_html__('success', 'homey')
2960 )
2961 );
2962
2963 if($host_cancel == 'cancelled_by_host') {
2964 $renter = homey_usermeta($listing_renter);
2965 $to_email = $renter['email'];
2966 } else {
2967 $owner = homey_usermeta($listing_owner);
2968 $to_email = $owner['email'];
2969 }
2970
2971 $email_args = array('reservation_detail_url' => reservation_detail_link($reservation_id) );
2972
2973 homey_email_composer( $to_email, 'cancelled_reservation', $email_args );
2974 wp_die();
2975 }
2976}
2977
2978if(!function_exists('homey_hourly_booking_with_no_upfront')) {
2979 function homey_hourly_booking_with_no_upfront($reservation_id) {
2980 $listing_id = get_post_meta($reservation_id, 'reservation_listing_id', true );
2981
2982 //Book days
2983 $booked_days_array = homey_make_hours_booked($listing_id, $reservation_id);
2984 update_post_meta($listing_id, 'reservation_booked_hours', $booked_days_array);
2985
2986 //Remove Pending Dates
2987 $pending_dates_array = homey_remove_booking_pending_hours($listing_id, $reservation_id);
2988 update_post_meta($listing_id, 'reservation_pending_hours', $pending_dates_array);
2989
2990 // Update reservation status
2991 update_post_meta( $reservation_id, 'reservation_status', 'booked' );
2992
2993 // Emails
2994 $listing_owner = get_post_meta($reservation_id, 'listing_owner', true);
2995 $listing_renter = get_post_meta($reservation_id, 'listing_renter', true);
2996
2997 $renter = homey_usermeta($listing_renter);
2998 $renter_email = $renter['email'];
2999
3000 $owner = homey_usermeta($listing_owner);
3001 $owner_email = $owner['email'];
3002
3003 $email_args = array('reservation_detail_url' => reservation_detail_link($reservation_id) );
3004 homey_email_composer( $renter_email, 'booked_reservation', $email_args );
3005 homey_email_composer( $owner_email, 'admin_booked_reservation', $email_args );
3006
3007 return true;
3008 }
3009}