PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.15
VikBooking Hotel Booking Engine & PMS v1.8.15
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / notification / elements / virtualcreditcardupdate.php

virtualcreditcardupdate.php in VikBooking Hotel Booking Engine & PMS 1.8.15, at admin/helpers/src/notification/elements/virtualcreditcardupdate.php

134 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author Alessio Gaggii - E4J s.r.l.
6 * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Notification elements registry (Notification Center) of type "Virtual Credit Card Update".
16 *
17 * @since 1.18.6 (J) - 1.8.6 (WP)
18 */
19 class VBONotificationElementsVirtualcreditcardupdate extends VBONotificationElements
20 {
21 /**
22 * @inheritDoc
23 */
24 public function postflight()
25 {
26 $ota_res_id = $this->getOTAReservationID();
27 $channel = $this->getChannel();
28 $data = (array) $this->get('data', []);
29
30 if (empty($ota_res_id) || empty($channel) || empty($data['activationDate']) || empty($data['balance'])) {
31 // no interesting payload data information to process
32 return;
33 }
34
35 // ensure we received a positive amount (VCC balance)
36 $vccBalance = (float) $data['balance'];
37
38 if ($vccBalance <= 0) {
39 // invalid amount
40 return;
41 }
42
43 if (!VBOFactory::getConfig()->getBool('auto_payment_collection', false)) {
44 // automatic payment collection is disabled, so we ignore the notification
45 return;
46 }
47
48 // access the reservation model
49 $resModel = VBOModelReservation::getInstance();
50
51 // fetch the OTA booking details (list of records returned)
52 $booking = $resModel
53 ->setFilters([
54 'ota_id' => $ota_res_id,
55 'channel' => $channel,
56 ])
57 ->search();
58
59 if (!$booking) {
60 // booking not found
61 return;
62 }
63
64 // access the pay-schedules model
65 $paySchedulesModel = VBOModelPayschedules::getInstance();
66
67 // make sure this booking does not have any payment schedule to process
68 $prevSchedules = $paySchedulesModel->getItems([
69 'idorder' => [
70 'value' => $booking[0]['id'],
71 ],
72 'status' => [
73 'value' => 0,
74 ],
75 ]);
76
77 if ($prevSchedules) {
78 // do not schedule any other payment collection for this booking
79 return;
80 }
81
82 // if the VCC update notification comes from Booking.com, ensure the card status is eligible
83 if (stripos($channel, 'booking.com') !== false && !in_array(strtoupper((string) ($data['status'] ?? '')), ['AVAILABLE', 'FUNDED'])) {
84 // do not process the notification due to a not-eligible status
85 return;
86 }
87
88 // today's date object and current SQL date-time
89 $todayDate = JFactory::getdate('now');
90 $midnightDate = clone $todayDate;
91 $midnightDate->modify('00:00:00');
92
93 // validate and store the payment collection schedule
94 try {
95 // ensure the card activation date is in the future
96 $activationDate = JFactory::getdate($data['activationDate']);
97
98 if ($activationDate < $midnightDate) {
99 // delayed notification occurred, notification is still accepted
100 // payment collection date will be adjusted to a date in the future
101 }
102
103 if ($activationDate->format('H:i') === '00:00') {
104 // give the payment collection date some grace hours
105 $activationDate->modify('+6 hours');
106 }
107
108 // make sure the payment collection date is not in the past
109 if ($activationDate < $todayDate) {
110 // adjust the collection schedule time so the cron will process it
111 $activationDate = clone $todayDate;
112 $activationDate->modify('+1 hour');
113 }
114
115 // prepare the new payment schedule record
116 $record = [
117 'idorder' => (int) $booking[0]['id'],
118 'fordt' => $activationDate->toSql(),
119 'amount' => $vccBalance,
120 'status' => 0,
121 'created_on' => $todayDate->toSql(),
122 'created_by' => 'Automatic Payment Scheduler',
123 ];
124
125 // store the record
126 $paySchedulesModel->save($record);
127 } catch (Exception $e) {
128 // do nothing
129 }
130
131 return;
132 }
133 }
134