PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Services / Reservation / EventReservationService.php
ameliabooking / src / Application / Services / Reservation Last commit date
AbstractReservationService.php 1 year ago AppointmentReservationService.php 1 year ago EventReservationService.php 1 year ago ReservationService.php 2 years ago
EventReservationService.php
1286 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Services\Reservation;
4
5 use AmeliaBooking\Application\Commands\CommandResult;
6 use AmeliaBooking\Application\Services\Booking\EventApplicationService;
7 use AmeliaBooking\Application\Services\Coupon\CouponApplicationService;
8 use AmeliaBooking\Application\Services\Deposit\AbstractDepositApplicationService;
9 use AmeliaBooking\Application\Services\Helper\HelperService;
10 use AmeliaBooking\Application\Services\Tax\TaxApplicationService;
11 use AmeliaBooking\Domain\Collection\Collection;
12 use AmeliaBooking\Domain\Common\Exceptions\BookingCancellationException;
13 use AmeliaBooking\Domain\Common\Exceptions\BookingsLimitReachedException;
14 use AmeliaBooking\Domain\Common\Exceptions\BookingUnavailableException;
15 use AmeliaBooking\Domain\Common\Exceptions\CouponExpiredException;
16 use AmeliaBooking\Domain\Common\Exceptions\CouponInvalidException;
17 use AmeliaBooking\Domain\Common\Exceptions\CouponUnknownException;
18 use AmeliaBooking\Domain\Common\Exceptions\CustomerBookedException;
19 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
20 use AmeliaBooking\Domain\Entity\Bookable\AbstractBookable;
21 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
22 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBookingExtra;
23 use AmeliaBooking\Domain\Entity\Booking\Event\CustomerBookingEventPeriod;
24 use AmeliaBooking\Domain\Entity\Booking\Event\CustomerBookingEventTicket;
25 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
26 use AmeliaBooking\Domain\Entity\Booking\Event\EventPeriod;
27 use AmeliaBooking\Domain\Entity\Booking\Event\EventTicket;
28 use AmeliaBooking\Domain\Entity\Booking\Reservation;
29 use AmeliaBooking\Domain\Entity\Coupon\Coupon;
30 use AmeliaBooking\Domain\Entity\Entities;
31 use AmeliaBooking\Domain\Entity\Location\Location;
32 use AmeliaBooking\Domain\Entity\Payment\Payment;
33 use AmeliaBooking\Domain\Entity\Tax\Tax;
34 use AmeliaBooking\Domain\Entity\User\AbstractUser;
35 use AmeliaBooking\Domain\Entity\User\Provider;
36 use AmeliaBooking\Domain\Factory\Booking\Appointment\CustomerBookingFactory;
37 use AmeliaBooking\Domain\Factory\Booking\Event\CustomerBookingEventPeriodFactory;
38 use AmeliaBooking\Domain\Factory\Booking\Event\CustomerBookingEventTicketFactory;
39 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
40 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
41 use AmeliaBooking\Domain\Services\Settings\SettingsService;
42 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
43 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
44 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
45 use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue;
46 use AmeliaBooking\Domain\ValueObjects\String\AmountType;
47 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
48 use AmeliaBooking\Domain\ValueObjects\String\PaymentType;
49 use AmeliaBooking\Domain\ValueObjects\String\Token;
50 use AmeliaBooking\Domain\ValueObjects\Json;
51 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
52 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingExtraRepository;
53 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
54 use AmeliaBooking\Infrastructure\Repository\Booking\Event\CustomerBookingEventPeriodRepository;
55 use AmeliaBooking\Infrastructure\Repository\Booking\Event\CustomerBookingEventTicketRepository;
56 use AmeliaBooking\Infrastructure\Repository\Booking\Event\EventRepository;
57 use AmeliaBooking\Infrastructure\Repository\Location\LocationRepository;
58 use AmeliaBooking\Infrastructure\Repository\User\CustomerRepository;
59 use AmeliaBooking\Infrastructure\WP\Translations\FrontendStrings;
60 use DateTime;
61 use Exception;
62 use Slim\Exception\ContainerException;
63 use Slim\Exception\ContainerValueNotFoundException;
64
65 /**
66 * Class EventReservationService
67 *
68 * @package AmeliaBooking\Application\Services\Reservation
69 */
70 class EventReservationService extends AbstractReservationService
71 {
72 /**
73 * @return string
74 */
75 public function getType()
76 {
77 return Entities::EVENT;
78 }
79
80 /**
81 * @param array $eventData
82 * @param Reservation $reservation
83 * @param bool $save
84 *
85 * @return void
86 *
87 * @throws CouponExpiredException
88 * @throws CouponInvalidException
89 * @throws CouponUnknownException
90 * @throws BookingUnavailableException
91 * @throws ContainerValueNotFoundException
92 * @throws InvalidArgumentException
93 * @throws QueryExecutionException
94 * @throws Exception
95 */
96 public function book($eventData, $reservation, $save)
97 {
98 /** @var LocationRepository $locationRepository */
99 $locationRepository = $this->container->get('domain.locations.repository');
100
101 /** @var EventApplicationService $eventApplicationService */
102 $eventApplicationService = $this->container->get('application.booking.event.service');
103
104 /** @var CouponApplicationService $couponAS */
105 $couponAS = $this->container->get('application.coupon.service');
106
107 /** @var AbstractDepositApplicationService $depositAS */
108 $depositAS = $this->container->get('application.deposit.service');
109
110 $this->manageTaxes($eventData);
111
112 /** @var Coupon $coupon */
113 $coupon = !empty($eventData['couponCode']) ? $couponAS->processCoupon(
114 $eventData['couponCode'],
115 [$eventData['eventId']],
116 Entities::EVENT,
117 $eventData['bookings'][0]['customerId'],
118 $reservation->hasCouponValidation()->getValue()
119 ) : null;
120
121 if ($coupon) {
122 $eventData['bookings'][0]['coupon'] = $coupon->toArray();
123
124 $eventData['bookings'][0]['couponId'] = $coupon->getId()->getValue();
125 }
126
127 /** @var Event $event */
128 $event = $eventApplicationService->getEventById(
129 $eventData['eventId'],
130 [
131 'fetchEventsPeriods' => true,
132 'fetchEventsTickets' => true,
133 'fetchApprovedBookings' => true,
134 'fetchBookings' => true,
135 'fetchBookingsTickets' => true,
136 'fetchEventsProviders' => true,
137 ]
138 );
139
140 if ($event->getCustomPricing()->getValue()) {
141 $event->setCustomTickets($eventApplicationService->getTicketsPriceByDateRange($event->getCustomTickets()));
142 }
143
144 $bookingArray = array_merge(
145 $eventData['bookings'][0],
146 empty($eventData['bookings'][0]['status']) ?
147 ['status' => BookingStatus::APPROVED] : ['status' => $eventData['bookings'][0]['status']]
148 );
149
150 $bookingArray = apply_filters('amelia_before_event_booking_saved_filter', $bookingArray, $event ? $event->toArray() : null);
151
152 do_action('amelia_before_event_booking_saved', $bookingArray, $event ? $event->toArray() : null);
153
154 $booking = CustomerBookingFactory::create($bookingArray);
155
156 if ($event->getCustomPricing()->getValue()) {
157 $booking->setPersons(new IntegerValue(0));
158 }
159
160 $bookingStatus = empty($eventData['bookings'][0]['status']) ? BookingStatus::APPROVED : $eventData['bookings'][0]['status'];
161
162 if (!empty($eventData['payment']['gateway'])) {
163 $bookingStatus = in_array($eventData['payment']['gateway'], [PaymentType::MOLLIE]) ?
164 BookingStatus::PENDING : (empty($eventData['bookings'][0]['status']) ? BookingStatus::APPROVED : $eventData['bookings'][0]['status']);
165
166 if (!empty($eventData['payment']['orderStatus'])) {
167 $bookingStatus = $this->getWcStatus(
168 Entities::EVENT,
169 $eventData['payment']['orderStatus'],
170 'booking',
171 false
172 ) ?: $bookingStatus;
173 }
174 }
175
176 $booking->setStatus(new BookingStatus($bookingStatus));
177
178 $personsCount = 0;
179
180 /** @var CustomerBooking $customerBooking */
181 foreach ($event->getBookings()->getItems() as $customerBooking) {
182 if ($customerBooking->getStatus()->getValue() === BookingStatus::APPROVED) {
183 $personsCount += $customerBooking->getPersons()->getValue();
184 }
185 if (
186 $customerBooking->getStatus()->getValue() !== BookingStatus::CANCELED &&
187 !$event->getBookMultipleTimes()->getValue() &&
188 $booking->getCustomerId() &&
189 $booking->getCustomerId()->getValue() === $customerBooking->getCustomerId()->getValue()
190 ) {
191 throw new CustomerBookedException(
192 FrontendStrings::getCommonStrings()['customer_already_booked_ev']
193 );
194 }
195 }
196
197 /** @var SettingsService $settingsDS */
198 $settingsDS = $this->container->get('domain.settings.service');
199
200 $limitPerCustomerEvents = $settingsDS->getSetting('roles', 'limitPerCustomerEvent');
201
202 if (
203 !empty($limitPerCustomerEvents) &&
204 $limitPerCustomerEvents['enabled'] &&
205 empty($eventData['isBackendOrCabinet'])
206 ) {
207 /** @var EventRepository $eventRepository */
208 $eventRepository = $this->container->get('domain.booking.event.repository');
209
210 $count = $eventRepository->getRelevantBookingsCount(
211 $event,
212 $booking->toArray(),
213 $limitPerCustomerEvents
214 );
215
216 if ($count >= $limitPerCustomerEvents['numberOfApp']) {
217 throw new BookingsLimitReachedException(
218 FrontendStrings::getCommonStrings()['bookings_limit_reached']
219 );
220 }
221 }
222
223 /** @var AbstractUser $currentUser */
224 $currentUser = $this->container->get('logged.in.user');
225
226 $isCustomer = (!$currentUser || ($currentUser->getType() === AbstractUser::USER_ROLE_CUSTOMER));
227
228 $isProvider =
229 $reservation->getLoggedInUser() &&
230 $reservation->getLoggedInUser()->getType() === AbstractUser::USER_ROLE_PROVIDER;
231
232 if (
233 $reservation->hasAvailabilityValidation()->getValue() &&
234 $isCustomer &&
235 !$isProvider &&
236 !$this->isBookable($event, $booking, DateTimeService::getNowDateTimeObject())
237 ) {
238 throw new BookingUnavailableException(
239 FrontendStrings::getCommonStrings()['time_slot_unavailable']
240 );
241 }
242
243
244 $booking->setAggregatedPrice(new BooleanValueObject($event->getAggregatedPrice() ? $event->getAggregatedPrice()->getValue() : true));
245
246 $paymentAmount = $this->getPaymentAmount($booking, $event)['price'];
247
248 $applyDeposit =
249 !empty($eventData['bookings'][0]['deposit']) && $eventData['payment']['gateway'] !== PaymentType::ON_SITE;
250
251 if ($applyDeposit) {
252 $personsCount = $booking->getPersons()->getValue();
253
254 if ($booking->getTicketsBooking() && $event->getCustomPricing()->getValue()) {
255 $personsCount = 0;
256
257 /** @var CustomerBookingEventTicket $bookingToEventTicket */
258 foreach ($booking->getTicketsBooking()->getItems() as $bookingToEventTicket) {
259 $personsCount += ($bookingToEventTicket->getPersons() ?
260 $bookingToEventTicket->getPersons()->getValue() : 0);
261 }
262 }
263
264 $paymentDeposit = $depositAS->calculateDepositAmount(
265 $paymentAmount,
266 $event,
267 $personsCount
268 );
269
270 $eventData['payment']['deposit'] = $paymentAmount !== $paymentDeposit;
271
272 $paymentAmount = $paymentDeposit;
273 }
274
275 if ($save) {
276 /** @var CustomerBookingRepository $bookingRepository */
277 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
278
279 /** @var CustomerBookingExtraRepository $bookingExtraRepository */
280 $bookingExtraRepository = $this->container->get('domain.booking.customerBookingExtra.repository');
281
282 /** @var CustomerBookingEventPeriodRepository $bookingEventPeriodRepository */
283 $bookingEventPeriodRepository =
284 $this->container->get('domain.booking.customerBookingEventPeriod.repository');
285
286 /** @var CustomerBookingEventTicketRepository $bookingEventTicketRepository */
287 $bookingEventTicketRepository = $this->container->get('domain.booking.customerBookingEventTicket.repository');
288
289 $booking->setPrice(new Price($event->getPrice()->getValue()));
290 $booking->setToken(new Token());
291
292 if ($booking->getTicketsBooking() && $event->getCustomPricing()->getValue()) {
293 $ticketSumPrice = 0;
294
295 /** @var CustomerBookingEventTicket $bookingToEventTicket */
296 foreach ($booking->getTicketsBooking()->getItems() as $bookingToEventTicket) {
297 /** @var EventTicket $ticket */
298 $ticket = $event->getCustomTickets()->getItem(
299 $bookingToEventTicket->getEventTicketId()->getValue()
300 );
301
302 $ticketPrice = $ticket->getDateRangePrice() ?
303 $ticket->getDateRangePrice()->getValue() : $ticket->getPrice()->getValue();
304
305 $ticketSumPrice += $bookingToEventTicket->getPersons() ?
306 ($booking->getAggregatedPrice()->getValue() ? $bookingToEventTicket->getPersons()->getValue() : 1)
307 * $ticketPrice : 0;
308 }
309
310 $booking->setPrice(new Price($ticketSumPrice));
311 }
312
313 $booking->setActionsCompleted(new BooleanValueObject(!empty($eventData['payment']['isBackendBooking'])));
314
315 $bookingId = $bookingRepository->add($booking);
316
317 /** @var CustomerBookingExtra $bookingExtra */
318 foreach ($booking->getExtras()->getItems() as $bookingExtra) {
319 $bookingExtra->setCustomerBookingId(new Id($bookingId));
320 $bookingExtraId = $bookingExtraRepository->add($bookingExtra);
321 $bookingExtra->setId(new Id($bookingExtraId));
322 }
323
324 $booking->setId(new Id($bookingId));
325
326 /** @var Payment $payment */
327 $payment = $this->addPayment(
328 $booking->getId()->getValue(),
329 null,
330 $eventData['payment'],
331 $paymentAmount,
332 $event->getPeriods()->getItem(0)->getPeriodStart()->getValue(),
333 Entities::EVENT
334 );
335
336 /** @var Collection $payments */
337 $payments = new Collection();
338
339 $payments->addItem($payment);
340
341 $booking->setPayments($payments);
342
343 /** @var EventPeriod $eventPeriod */
344 foreach ($event->getPeriods()->getItems() as $eventPeriod) {
345 /** @var CustomerBookingEventPeriod $bookingEventPeriod */
346 $bookingEventPeriod = CustomerBookingEventPeriodFactory::create(
347 [
348 'eventPeriodId' => $eventPeriod->getId()->getValue(),
349 'customerBookingId' => $bookingId
350 ]
351 );
352
353 $bookingEventPeriodRepository->add($bookingEventPeriod);
354 }
355
356 /** @var CustomerBookingEventTicket $eventTicket */
357 foreach ($booking->getTicketsBooking()->getItems() as $eventTicket) {
358 if ($eventTicket->getPersons()) {
359 /** @var EventTicket $ticket */
360 $ticket = $event->getCustomTickets()->getItem($eventTicket->getEventTicketId()->getValue());
361
362 $ticketPrice = $ticket->getDateRangePrice() ?
363 $ticket->getDateRangePrice()->getValue() : $ticket->getPrice()->getValue();
364
365 /** @var CustomerBookingEventTicket $bookingEventTicket */
366 $bookingEventTicket = CustomerBookingEventTicketFactory::create(
367 [
368 'eventTicketId' => $eventTicket->getEventTicketId()->getValue(),
369 'customerBookingId' => $bookingId,
370 'persons' => $eventTicket->getPersons()->getValue(),
371 'price' => $ticketPrice,
372 ]
373 );
374
375 $bookingEventTicketRepository->add($bookingEventTicket);
376 }
377 }
378
379 $event->getBookings()->addItem($booking, $booking->getId()->getValue());
380
381 do_action('amelia_after_event_booking_saved', $booking ? $booking->toArray() : null, $event ? $event->toArray() : null);
382 }
383
384 if ($event->getLocationId()) {
385 /** @var Location $location */
386 $location = $locationRepository->getById($event->getLocationId()->getValue());
387
388 $event->setLocation($location);
389 }
390
391 $reservation->setApplyDeposit(new BooleanValueObject($applyDeposit));
392 if ($booking->getCustomer()) {
393 $reservation->setCustomer($booking->getCustomer());
394 }
395
396 /** @var Collection $bookings */
397 $bookings = new Collection();
398
399 $bookings->addItem($booking);
400
401 $event->setBookings($bookings);
402
403 $reservation->setBookable($event);
404 $reservation->setBooking($booking);
405 $reservation->setReservation($event);
406 $reservation->setRecurring(new Collection());
407 $reservation->setPackageReservations(new Collection());
408 $reservation->setIsStatusChanged(new BooleanValueObject(false));
409 }
410
411 /**
412 * @param CustomerBooking $booking
413 * @param string $requestedStatus
414 *
415 * @return array
416 *
417 * @throws ContainerException
418 * @throws ContainerValueNotFoundException
419 * @throws InvalidArgumentException
420 * @throws QueryExecutionException
421 * @throws BookingCancellationException
422 */
423 public function updateStatus($booking, $requestedStatus)
424 {
425 /** @var CustomerBookingRepository $bookingRepository */
426 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
427 /** @var SettingsService $settingsDS */
428 $settingsDS = $this->container->get('domain.settings.service');
429
430 /** @var Event $event */
431 $event = $this->getReservationByBookingId($booking->getId()->getValue());
432
433 if ($requestedStatus === BookingStatus::CANCELED) {
434 $minimumCancelTimeInSeconds = $settingsDS
435 ->getEntitySettings($event->getSettings())
436 ->getGeneralSettings()
437 ->getMinimumTimeRequirementPriorToCanceling();
438
439 $this->inspectMinimumCancellationTime(
440 $event->getPeriods()->getItem(0)->getPeriodStart()->getValue(),
441 $minimumCancelTimeInSeconds
442 );
443 }
444
445 $booking->setStatus(new BookingStatus($requestedStatus));
446
447 $bookingRepository->update($booking->getId()->getValue(), $booking);
448
449 return [
450 Entities::EVENT => $event->toArray(),
451 'appointmentStatusChanged' => false,
452 Entities::BOOKING => $booking->toArray()
453 ];
454 }
455
456 /**
457 * @param Event $reservation
458 * @param CustomerBooking $booking
459 * @param AbstractBookable $bookable
460 *
461 * @return array
462 */
463 public function getBookingPeriods($reservation, $booking, $bookable)
464 {
465 $dates = [];
466
467 /** @var EventPeriod $period */
468 foreach ($reservation->getPeriods()->getItems() as $period) {
469 $dates[] = [
470 'start' => DateTimeService::getCustomDateTimeInUtc(
471 $period->getPeriodStart()->getValue()->format('Y-m-d H:i:s')
472 ),
473 'end' => DateTimeService::getCustomDateTimeInUtc(
474 $period->getPeriodEnd()->getValue()->format('Y-m-d H:i:s')
475 )
476 ];
477 }
478
479 return $dates;
480 }
481
482 /**
483 * @param array $data
484 *
485 * @return AbstractBookable
486 *
487 * @throws ContainerValueNotFoundException
488 * @throws QueryExecutionException
489 * @throws InvalidArgumentException
490 */
491 public function getBookableEntity($data)
492 {
493 /** @var EventRepository $eventRepository */
494 $eventRepository = $this->container->get('domain.booking.event.repository');
495
496 return $eventRepository->getById($data['eventId']);
497 }
498
499 /**
500 * @param Event $bookable
501 *
502 * @return boolean
503 */
504 public function isAggregatedPrice($bookable)
505 {
506 return $bookable->getAggregatedPrice()->getValue();
507 }
508
509 /**
510 * @param BooleanValueObject $bookableAggregatedPrice
511 * @param BooleanValueObject $extraAggregatedPrice
512 *
513 * @return boolean
514 */
515 public function isExtraAggregatedPrice($extraAggregatedPrice, $bookableAggregatedPrice)
516 {
517 return true;
518 }
519
520 /**
521 * @param Reservation $reservation
522 * @param string $paymentGateway
523 * @param array $requestData
524 *
525 * @return array
526 *
527 * @throws InvalidArgumentException
528 */
529 public function getWooCommerceData($reservation, $paymentGateway, $requestData)
530 {
531 /** @var Event $event */
532 $event = $reservation->getBookable();
533
534 /** @var AbstractUser $customer */
535 $customer = $reservation->getCustomer();
536
537 /** @var CustomerBooking $booking */
538 $booking = $reservation->getBooking();
539
540 $dateTimeValues = [];
541
542 /** @var EventPeriod $period */
543 foreach ($event->getPeriods()->getItems() as $period) {
544 $dateTimeValues[] = [
545 'start' => $period->getPeriodStart()->getValue()->format('Y-m-d H:i'),
546 'end' => $period->getPeriodEnd()->getValue()->format('Y-m-d H:i')
547 ];
548 }
549
550 $info = [
551 'type' => Entities::EVENT,
552 'eventId' => $event->getId()->getValue(),
553 'name' => $event->getName()->getValue(),
554 'couponId' => $booking->getCoupon() ? $booking->getCoupon()->getId()->getValue() : '',
555 'couponCode' => $booking->getCoupon() ? $booking->getCoupon()->getCode()->getValue() : '',
556 'dateTimeValues' => $dateTimeValues,
557 'bookings' => [
558 [
559 'customerId' => $customer->getId() ? $customer->getId()->getValue() : null,
560 'customer' => [
561 'email' => $customer->getEmail()->getValue(),
562 'externalId' => $customer->getExternalId() ? $customer->getExternalId()->getValue() : null,
563 'firstName' => $customer->getFirstName()->getValue(),
564 'id' => $customer->getId() ? $customer->getId()->getValue() : null,
565 'lastName' => $customer->getLastName()->getValue(),
566 'phone' => $customer->getPhone()->getValue(),
567 'countryPhoneIso' => $customer->getCountryPhoneIso() ?
568 $customer->getCountryPhoneIso()->getValue() : null
569 ],
570 'info' => $booking->getInfo()->getValue(),
571 'persons' => $booking->getPersons()->getValue(),
572 'extras' => [],
573 'utcOffset' => $booking->getUtcOffset() ? $booking->getUtcOffset()->getValue() : null,
574 'customFields' => $booking->getCustomFields() ?
575 json_decode($booking->getCustomFields()->getValue(), true) : null,
576 'deposit' => $reservation->getApplyDeposit()->getValue(),
577 'ticketsData' => $requestData['bookings'][0]['ticketsData'],
578 ]
579 ],
580 'payment' => [
581 'gateway' => $paymentGateway
582 ],
583 'locale' => $reservation->getLocale()->getValue(),
584 'timeZone' => $reservation->getTimeZone()->getValue(),
585 'recurring' => [],
586 'package' => [],
587 ];
588
589 foreach ($booking->getExtras()->keys() as $extraKey) {
590 /** @var CustomerBookingExtra $bookingExtra */
591 $bookingExtra = $booking->getExtras()->getItem($extraKey);
592
593 $info['bookings'][0]['extras'][] = [
594 'extraId' => $bookingExtra->getExtraId()->getValue(),
595 'quantity' => $bookingExtra->getQuantity()->getValue()
596 ];
597 }
598
599 return $info;
600 }
601
602
603 /**
604 * @param array $reservation
605 *
606 * @return array
607 *
608 * @throws InvalidArgumentException
609 */
610 public function getWooCommerceDataFromArray($reservation, $index)
611 {
612 /** @var array $event */
613 $event = $reservation['bookable'];
614
615 /** @var array $customer */
616 $customer = !empty($reservation['customer'])
617 ? $reservation['customer']
618 : (!empty($reservation['booking']['customer']) ? $reservation['booking']['customer'] : null);
619
620 /** @var array $booking */
621 $booking = $reservation['booking'];
622
623 if (!empty($booking['ticketsData'])) {
624 foreach ($booking['ticketsData'] as &$ticket) {
625 $customTicketIndex = array_search(
626 $ticket['eventTicketId'],
627 array_column($reservation['event']['customTickets'], 'id')
628 );
629 if ($customTicketIndex !== false) {
630 $ticket['name'] = $reservation['event']['customTickets'][$customTicketIndex]['name'];
631 }
632 }
633 }
634
635 $dateTimeValues = [];
636
637 $customerInfo = !empty($booking['info']) ? json_decode($booking['info'], true) : null;
638
639 /** @var EventPeriod $period */
640 foreach ($event['periods'] as $period) {
641 $dateTimeValues[] = [
642 'start' => $period['periodStart'],
643 'end' => $period['periodEnd']
644 ];
645 }
646
647 $info = [
648 'type' => Entities::EVENT,
649 'eventId' => $event['id'],
650 'name' => $event['name'],
651 'couponId' => $booking['coupon'] ? $booking['coupon']['id'] : '',
652 'couponCode' => $booking['coupon'] ? $booking['coupon']['code'] : '',
653 'dateTimeValues' => $dateTimeValues,
654 'bookings' => [
655 [
656 'customerId' => $customer['id'],
657 'customer' => [
658 'email' => $customer['email'],
659 'externalId' => $customer['externalId'],
660 'firstName' => $customer['firstName'],
661 'id' => $customer['id'],
662 'lastName' => $customer['lastName'],
663 'phone' => $customer['phone'],
664 'countryPhoneIso' => $customer['countryPhoneIso']
665 ],
666 'info' => $booking['info'],
667 'persons' => $booking['persons'],
668 'extras' => [],
669 'utcOffset' => $booking['utcOffset'],
670 'customFields' => $booking['customFields'] ?
671 json_decode($booking['customFields'], true) : null,
672 'deposit' => $booking['price'] > $booking['payments'][0]['amount'],
673 'ticketsData' => $booking['ticketsData'],
674 ]
675 ],
676 'payment' => [
677 'gateway' => $booking['payments'][0]['gateway']
678 ],
679 'locale' => $customerInfo ? $customerInfo['locale'] : null,
680 'timeZone' => $customerInfo ? $customerInfo['timeZone'] : null,
681 'recurring' => [],
682 'package' => [],
683 ];
684
685 foreach ($booking['extras'] as $extra) {
686 $info['bookings'][0]['extras'][] = [
687 'extraId' => $extra['id'],
688 'quantity' => $extra['quantity']
689 ];
690 }
691
692 return $info;
693 }
694
695 /**
696 * @param int $id
697 *
698 * @return Event
699 *
700 * @throws ContainerValueNotFoundException
701 * @throws QueryExecutionException
702 * @throws InvalidArgumentException
703 */
704 public function getReservationByBookingId($id)
705 {
706 /** @var EventRepository $eventRepository */
707 $eventRepository = $this->container->get('domain.booking.event.repository');
708
709 /** @var Event $event */
710 $event = $eventRepository->getByBookingId(
711 $id,
712 [
713 'fetchEventsTickets' => true,
714 'fetchEventsTags' => true,
715 'fetchEventsProviders' => true,
716 'fetchEventsImages' => true,
717 ]
718 );
719
720 /** @var Collection $eventsBookings */
721 $eventsBookings = $eventRepository->getBookingsByCriteria(
722 [
723 'ids' => [$event->getId()->getValue()],
724 'fetchBookings' => true,
725 'fetchBookingsTickets' => true,
726 'fetchBookingsUsers' => true,
727 'fetchBookingsPayments' => true,
728 ]
729 );
730
731 if ($eventsBookings->keyExists($event->getId()->getValue())) {
732 $event->setBookings($eventsBookings->getItem($event->getId()->getValue()));
733 }
734
735 return $event;
736 }
737
738 /**
739 * @param Event $reservation
740 * @param CustomerBooking $newBooking
741 * @param DateTime $dateTime
742 *
743 * @return boolean
744 *
745 * @throws InvalidArgumentException
746 */
747 public function isBookable($reservation, $newBooking, $dateTime)
748 {
749 if ($reservation->getCustomPricing() && $reservation->getCustomPricing()->getValue() && !$reservation->getMaxCustomCapacity()) {
750 $availableTicketsSpots = [];
751
752 /** @var EventTicket $ticket */
753 foreach ($reservation->getCustomTickets()->getItems() as $ticket) {
754 $availableTicketsSpots[$ticket->getId()->getValue()] = $ticket->getSpots()->getValue();
755 }
756
757 $reservedTicketsSpots = [];
758
759 /** @var CustomerBooking $booking */
760 foreach ($reservation->getBookings()->getItems() as $booking) {
761 if ($booking->getStatus()->getValue() === BookingStatus::APPROVED) {
762 /** @var CustomerBookingEventTicket $bookingTicket */
763 foreach ($booking->getTicketsBooking()->getItems() as $bookingTicket) {
764 $eventTicketId = $bookingTicket->getEventTicketId()->getValue();
765
766 if (!array_key_exists($eventTicketId, $reservedTicketsSpots)) {
767 $reservedTicketsSpots[$eventTicketId] = 0;
768 }
769
770 $reservedTicketsSpots[$eventTicketId] += $bookingTicket->getPersons()->getValue();
771 }
772 }
773 }
774
775 if ($newBooking) {
776 /** @var CustomerBookingEventTicket $newBookingTicket */
777 foreach ($newBooking->getTicketsBooking()->getItems() as $newBookingTicket) {
778 $eventTicketId = $newBookingTicket->getEventTicketId()->getValue();
779
780 if (empty($reservedTicketsSpots[$eventTicketId])) {
781 $reservedTicketsSpots[$eventTicketId] = 0;
782 }
783
784 $reservedTicketsSpots[$eventTicketId] +=
785 $newBookingTicket->getPersons() ? $newBookingTicket->getPersons()->getValue() : 0;
786 }
787 }
788
789 $hasTicketCapacity = [];
790
791 foreach ($availableTicketsSpots as $eventTicketId => $availablePersons) {
792 $hasTicketCapacity[$eventTicketId] = array_key_exists($eventTicketId, $reservedTicketsSpots) ?
793 ($newBooking ?
794 $reservedTicketsSpots[$eventTicketId] <= $availablePersons :
795 $reservedTicketsSpots[$eventTicketId] < $availablePersons
796 ) : true;
797 }
798
799 $hasCapacity = false;
800
801 foreach ($hasTicketCapacity as $ticketId => $ticketCapacity) {
802 if ($newBooking) {
803 $hasCapacity = true;
804
805 /** @var EventTicket $ticket */
806 $ticket = $reservation->getCustomTickets()->getItem($ticketId);
807
808 /** @var CustomerBookingEventTicket $ticketBooking */
809 foreach ($newBooking->getTicketsBooking()->getItems() as $ticketBooking) {
810 if (
811 $ticketBooking->getEventTicketId()->getValue() === $ticketId &&
812 $ticketBooking->getPersons() &&
813 $ticketBooking->getPersons()->getValue() &&
814 (!$ticketCapacity || !$ticket->getEnabled()->getValue())
815 ) {
816 $hasCapacity = false;
817
818 break 2;
819 }
820 }
821 } else {
822 $hasCapacity = $hasCapacity || $ticketCapacity;
823 }
824 }
825 } elseif ($reservation->getMaxCustomCapacity()) {
826 $availableTicketsSpots = $reservation->getMaxCustomCapacity()->getValue();
827 $reservedTicketsSpots = 0;
828 /** @var CustomerBooking $booking */
829 foreach ($reservation->getBookings()->getItems() as $booking) {
830 if ($booking->getStatus()->getValue() === BookingStatus::APPROVED) {
831 /** @var CustomerBookingEventTicket $bookingTicket */
832 foreach ($booking->getTicketsBooking()->getItems() as $bookingTicket) {
833 $reservedTicketsSpots += $bookingTicket->getPersons()->getValue();
834 }
835 }
836 }
837
838 if ($newBooking) {
839 /** @var CustomerBookingEventTicket $newBookingTicket */
840 foreach ($newBooking->getTicketsBooking()->getItems() as $newBookingTicket) {
841 $reservedTicketsSpots += $newBookingTicket->getPersons() ? $newBookingTicket->getPersons()->getValue() : 0;
842 }
843 }
844
845 $hasCapacity = ($newBooking ? $reservedTicketsSpots <= $availableTicketsSpots : $reservedTicketsSpots < $availableTicketsSpots);
846 } else {
847 $persons = 0;
848
849 /** @var CustomerBooking $booking */
850 foreach ($reservation->getBookings()->getItems() as $booking) {
851 if ($booking->getStatus()->getValue() === BookingStatus::APPROVED) {
852 $persons += $booking->getPersons()->getValue();
853 }
854 }
855 if ($newBooking) {
856 $hasCapacity = ($reservation->getMaxCapacity()->getValue() - $persons - $newBooking->getPersons()->getValue()) >= 0;
857 } else {
858 $hasCapacity = $reservation->getMaxCapacity()->getValue() - $persons > 0;
859 }
860 }
861
862 $bookingCloses = $reservation->getBookingCloses() ?
863 $reservation->getBookingCloses()->getValue() :
864 $reservation->getPeriods()->getItem(0)->getPeriodStart()->getValue();
865
866 $bookingOpens = $reservation->getBookingOpens() ?
867 $reservation->getBookingOpens()->getValue() :
868 $reservation->getCreated()->getValue();
869
870 $hasWaitingList = false;
871 $eventSettings = $reservation->getSettings() ? json_decode($reservation->getSettings()->getValue(), true) : null;
872
873 /** @var SettingsService $settingsDS */
874 $settingsDS = $this->container->get('domain.settings.service');
875 $waitingListSettings = $settingsDS->getSetting('appointments', 'waitingListEvents');
876
877 if (
878 $waitingListSettings['enabled'] && $eventSettings && !empty($eventSettings['waitingList']) &&
879 $eventSettings['waitingList']['enabled']
880 ) {
881 $waitingCustomers = 0;
882
883 foreach ($reservation->getBookings()->getItems() as $booking) {
884 if ($booking->getStatus()->getValue() === BookingStatus::WAITING) {
885 if ($reservation->getCustomPricing()->getValue()) {
886 foreach ($booking->getTicketsBooking()->getItems() as $item) {
887 $waitingCustomers += $item->getPersons()->getValue();
888 }
889 } else {
890 $waitingCustomers += $booking->getPersons()->getValue();
891 }
892 }
893 }
894
895 if ($newBooking && $reservation->getCustomPricing() && $reservation->getCustomPricing()->getValue()) {
896 foreach ($newBooking->getTicketsBooking()->getItems() as $item) {
897 if (!$reservation->getMaxCustomCapacity()) {
898 $ticketData = $reservation->getCustomTickets()->getItem($item->getId()->getValue());
899
900 $hasWaitingList = $ticketData->getWaitingListSpots() && $ticketData->getWaitingListSpots()->getValue() >=
901 ($item->getPersons() ? $item->getPersons()->getValue() : 0
902 + ($ticketData->getWaiting() ? $ticketData->getWaiting()->getValue() : 0));
903 }
904 }
905
906 if ($reservation->getMaxCustomCapacity()) {
907 $hasWaitingList = $eventSettings['waitingList']['maxCapacity'] > $waitingCustomers;
908 }
909 } else {
910 $hasWaitingList = $eventSettings['waitingList']['maxCapacity'] > $waitingCustomers;
911 }
912
913 $eventSettings['waitingList']['peopleWaiting'] = $waitingCustomers;
914
915 $reservation->setSettings(new Json(json_encode($eventSettings)));
916 }
917
918 return $dateTime > $bookingOpens &&
919 $dateTime < $bookingCloses &&
920 ($hasCapacity || ($hasWaitingList && $newBooking && $newBooking->getStatus()->getValue() === BookingStatus::WAITING)) &&
921 in_array($reservation->getStatus()->getValue(), [BookingStatus::APPROVED, BookingStatus::PENDING], true);
922 }
923
924 /**
925 * @param CustomerBooking $booking
926 * @param Event $bookable
927 * @param bool $invoice
928 *
929 * @return array
930 *
931 * @throws InvalidArgumentException
932 */
933 public function getPaymentAmount($booking, $bookable, $invoice = false)
934 {
935 /** @var TaxApplicationService $taxApplicationService */
936 $taxApplicationService = $this->container->get('application.tax.service');
937
938 /** @var Tax $eventTax */
939 $eventTax = $this->getTax($booking->getTax());
940
941 $persons = $booking->getPersons()->getValue();
942
943 $unitPrice = (float)$bookable->getPrice()->getValue();
944
945 $price = $unitPrice * ($this->isAggregatedPrice($bookable) ? $persons : 1);
946
947 $taxAmount = 0;
948
949 $ticketsTax = [];
950
951 if (
952 $booking->getTicketsBooking() &&
953 $booking->getTicketsBooking()->length() &&
954 $bookable->getCustomPricing() &&
955 $bookable->getCustomPricing()->getValue()
956 ) {
957 /** @var EventApplicationService $eventApplicationService */
958 $eventApplicationService = $this->container->get('application.booking.event.service');
959
960 $bookable->setCustomTickets(
961 $eventApplicationService->getTicketsPriceByDateRange($bookable->getCustomTickets())
962 );
963
964 $ticketSumPrice = 0;
965
966 /** @var CustomerBookingEventTicket $bookingToEventTicket */
967 foreach ($booking->getTicketsBooking()->getItems() as $bookingToEventTicket) {
968 /** @var EventTicket $ticket */
969 $ticket = $bookable->getCustomTickets()->getItem($bookingToEventTicket->getEventTicketId()->getValue());
970
971 $ticketPrice = $ticket->getDateRangePrice() ?
972 $ticket->getDateRangePrice()->getValue() : $ticket->getPrice()->getValue();
973
974 $ticketPersons = $bookingToEventTicket->getPersons() ?
975 ($booking->getAggregatedPrice()->getValue() ? $bookingToEventTicket->getPersons()->getValue() : 1)
976 : 0;
977
978 $ticketSubtotal = $ticketPersons * $ticketPrice;
979
980 $ticketSumPrice += $ticketSubtotal;
981
982 if ($bookingToEventTicket->getId()) {
983 if ($eventTax && $eventTax->getExcluded()->getValue()) {
984 $ticketsTax[$bookingToEventTicket->getId()->getValue()] = $this->getTaxAmount($eventTax, $ticketSubtotal);
985 } elseif ($eventTax && !$eventTax->getExcluded()->getValue()) {
986 $ticketsTax[$bookingToEventTicket->getId()->getValue()] =
987 $this->getTaxAmount($eventTax, $taxApplicationService->getBasePrice($ticketSubtotal, $eventTax));
988 } else {
989 $ticketsTax[$bookingToEventTicket->getId()->getValue()] = 0;
990 }
991 }
992 }
993
994 $price = $ticketSumPrice;
995 }
996
997 if ($eventTax && !$eventTax->getExcluded()->getValue() && ($booking->getCoupon() || $invoice)) {
998 $price = $taxApplicationService->getBasePrice($price, $eventTax);
999 }
1000
1001 $subtraction = 0;
1002
1003 $reductionAmount = [
1004 'deduction' => 0,
1005 'discount' => 0,
1006 ];
1007
1008 if ($booking->getCoupon()) {
1009 $reductionAmount['discount'] = $price / 100 * ($booking->getCoupon()->getDiscount()->getValue() ?: 0);
1010
1011 $reductionAmount['deduction'] = $booking->getCoupon()->getDeduction()->getValue();
1012
1013 $subtraction = $reductionAmount['discount'] + $reductionAmount['deduction'];
1014
1015 $price = max($price - $subtraction, 0);
1016 }
1017
1018 if ($eventTax && ($eventTax->getExcluded()->getValue() || $subtraction || $invoice)) {
1019 $taxAmount = $this->getTaxAmount($eventTax, $price);
1020 $price += $taxAmount;
1021 }
1022
1023 $price = (float)max(round($price, 2), 0);
1024
1025 if (!$price) {
1026 foreach ($ticketsTax as $ticketId => $ticketTax) {
1027 $ticketsTax[$ticketId] = 0;
1028 }
1029 }
1030
1031 return [
1032 'price' => apply_filters('amelia_modify_payment_amount', $price, $booking),
1033 'discount' => $reductionAmount['discount'],
1034 'deduction' => $reductionAmount['deduction'],
1035 'unit_price' => $unitPrice,
1036 'qty' => $persons,
1037 'subtotal' => $unitPrice * ($this->isAggregatedPrice($bookable) ? $persons : 1),
1038 'tax' => !empty($ticketsTax) || !$unitPrice ? null : $taxAmount,
1039 'tax_rate' => $eventTax && $unitPrice ? $this->getTaxRate($eventTax) : '',
1040 'tax_type' => $eventTax && $unitPrice ? $eventTax->getType()->getValue() : '',
1041 'tax_excluded' => $eventTax && $unitPrice ? $eventTax->getExcluded()->getValue() : false,
1042 'tickets_tax' => $ticketsTax,
1043 'full_discount' => $reductionAmount['discount'] + $reductionAmount['deduction']
1044 ];
1045 }
1046
1047 /**
1048 * @param Reservation $reservation
1049 *
1050 * @return float
1051 *
1052 * @throws InvalidArgumentException
1053 */
1054 public function getReservationPaymentAmount($reservation)
1055 {
1056 /** @var AbstractDepositApplicationService $depositAS */
1057 $depositAS = $this->container->get('application.deposit.service');
1058
1059 /** @var Event $bookable */
1060 $bookable = $reservation->getBookable();
1061
1062 $paymentAmount = $this->getPaymentAmount($reservation->getBooking(), $bookable)['price'];
1063
1064 if ($reservation->getApplyDeposit()->getValue()) {
1065 $personsCount = $reservation->getBooking()->getPersons()->getValue();
1066
1067 if ($reservation->getBooking()->getTicketsBooking() && $bookable->getCustomPricing()->getValue()) {
1068 $personsCount = 0;
1069
1070 /** @var CustomerBookingEventTicket $bookingToEventTicket */
1071 foreach ($reservation->getBooking()->getTicketsBooking()->getItems() as $bookingToEventTicket) {
1072 $personsCount += ($bookingToEventTicket->getPersons() ?
1073 $bookingToEventTicket->getPersons()->getValue() : 0);
1074 }
1075 }
1076
1077 $paymentAmount = $depositAS->calculateDepositAmount(
1078 $paymentAmount,
1079 $bookable,
1080 $personsCount
1081 );
1082 }
1083
1084 return $paymentAmount;
1085 }
1086
1087 /**
1088 * @param Reservation $reservation
1089 * @param bool $usePayment
1090 *
1091 * @return array
1092 *
1093 * @throws InvalidArgumentException
1094 */
1095 public function getProvidersPaymentAmount($reservation, $usePayment = true)
1096 {
1097 $amountData = [];
1098
1099 /** @var Payment $payment */
1100 $payment = $usePayment ? $reservation->getBooking()->getPayments()->getItem(0) : null;
1101
1102 /** @var Event $event */
1103 $event = $reservation->getBookable();
1104
1105 /** @var Provider $provider */
1106 foreach ($event->getProviders()->getItems() as $provider) {
1107 $amountData[$provider->getId()->getValue()][] = [
1108 'paymentId' => $payment ? $payment->getId()->getValue() : null,
1109 'amount' => $this->getReservationPaymentAmount($reservation),
1110 ];
1111 }
1112
1113 return $amountData;
1114 }
1115
1116 /**
1117 * @param Payment $payment
1118 * @param boolean $fromLink
1119 *
1120 * @return CommandResult
1121 * @throws InvalidArgumentException
1122 * @throws Exception
1123 * @throws \Interop\Container\Exception\ContainerException
1124 */
1125 public function getReservationByPayment($payment, $fromLink = false)
1126 {
1127 $result = new CommandResult();
1128
1129 /** @var CustomerRepository $customerRepository */
1130 $customerRepository = $this->container->get('domain.users.customers.repository');
1131
1132 /** @var LocationRepository $locationRepository */
1133 $locationRepository = $this->container->get('domain.locations.repository');
1134
1135 /** @var ReservationServiceInterface $reservationService */
1136 $reservationService = $this->container->get('application.reservation.service')->get(Entities::EVENT);
1137
1138 /** @var Event $event */
1139 $event = $reservationService->getReservationByBookingId(
1140 $payment->getCustomerBookingId()->getValue()
1141 );
1142
1143 if ($event->getLocationId()) {
1144 /** @var Location $location */
1145 $location = $locationRepository->getById($event->getLocationId()->getValue());
1146
1147 $event->setLocation($location);
1148 }
1149
1150 /** @var CustomerBooking $booking */
1151 $booking = $event->getBookings()->getItem($payment->getCustomerBookingId()->getValue());
1152
1153 $booking->setChangedStatus(new BooleanValueObject(true));
1154
1155 $this->setToken($booking);
1156
1157 /** @var AbstractUser $customer */
1158 $customer = $customerRepository->getById($booking->getCustomerId()->getValue());
1159
1160 $result->setData(
1161 [
1162 'type' => Entities::EVENT,
1163 Entities::EVENT => $event->toArray(),
1164 Entities::BOOKING => $booking->toArray(),
1165 'appointmentStatusChanged' => false,
1166 'customer' => $customer->toArray(),
1167 'packageId' => 0,
1168 'recurring' => [],
1169 'utcTime' => $reservationService->getBookingPeriods(
1170 $event,
1171 $booking,
1172 $event
1173 ),
1174 'isRetry' => !$fromLink,
1175 'fromLink' => $fromLink,
1176 'paymentId' => $payment->getId()->getValue(),
1177 'packageCustomerId' => null,
1178 'payment' => [
1179 'id' => $payment->getId()->getValue(),
1180 'amount' => $payment->getAmount()->getValue(),
1181 'gateway' => $payment->getGateway()->getName()->getValue(),
1182 'gatewayTitle' => $payment->getGatewayTitle() ? $payment->getGatewayTitle()->getValue() : '',
1183 'invoiceNumber' => $payment->getInvoiceNumber() ? $payment->getInvoiceNumber()->getValue() : '',
1184 ],
1185 ]
1186 );
1187
1188 return $result;
1189 }
1190
1191 /**
1192 * @param int $bookingId
1193 *
1194 * @return CommandResult
1195 * @throws InvalidArgumentException
1196 * @throws Exception
1197 * @throws \Interop\Container\Exception\ContainerException
1198 */
1199 public function getBookingResultByBookingId($bookingId)
1200 {
1201 $result = new CommandResult();
1202
1203 /** @var CustomerRepository $customerRepository */
1204 $customerRepository = $this->container->get('domain.users.customers.repository');
1205
1206 /** @var LocationRepository $locationRepository */
1207 $locationRepository = $this->container->get('domain.locations.repository');
1208
1209 /** @var ReservationServiceInterface $reservationService */
1210 $reservationService = $this->container->get('application.reservation.service')->get(Entities::EVENT);
1211
1212 /** @var Event $event */
1213 $event = $reservationService->getReservationByBookingId(
1214 $bookingId
1215 );
1216
1217 if ($event->getLocationId()) {
1218 /** @var Location $location */
1219 $location = $locationRepository->getById($event->getLocationId()->getValue());
1220
1221 $event->setLocation($location);
1222 }
1223
1224 /** @var CustomerBooking $booking */
1225 $booking = $event->getBookings()->getItem($bookingId);
1226
1227 $booking->setChangedStatus(new BooleanValueObject(true));
1228
1229 $this->setToken($booking);
1230
1231 /** @var AbstractUser $customer */
1232 $customer = $customerRepository->getById($booking->getCustomerId()->getValue());
1233
1234 $result->setData(
1235 [
1236 'type' => Entities::EVENT,
1237 Entities::EVENT => $event->toArray(),
1238 Entities::BOOKING => $booking->toArray(),
1239 'appointmentStatusChanged' => false,
1240 'customer' => $customer->toArray(),
1241 'packageId' => 0,
1242 'recurring' => [],
1243 'utcTime' => $reservationService->getBookingPeriods(
1244 $event,
1245 $booking,
1246 $event
1247 ),
1248 'isRetry' => true,
1249 'paymentId' => null,
1250 'packageCustomerId' => null,
1251 'payment' => null,
1252 ]
1253 );
1254
1255 return $result;
1256 }
1257
1258 /**
1259 * @param array $data
1260 *
1261 * @return void
1262 * @throws QueryExecutionException
1263 */
1264 public function manageTaxes(&$data)
1265 {
1266 /** @var TaxApplicationService $taxAS */
1267 $taxAS = $this->container->get('application.tax.service');
1268
1269 /** @var SettingsService $settingsService */
1270 $settingsService = $this->container->get('domain.settings.service');
1271
1272 $taxesSettings = $settingsService->getSetting('payments', 'taxes');
1273
1274 if ($taxesSettings['enabled']) {
1275 /** @var Collection $taxes */
1276 $taxes = $taxAS->getAll();
1277
1278 $data['bookings'][0]['tax'] = $taxAS->getTaxData(
1279 $data['eventId'],
1280 Entities::EVENT,
1281 $taxes
1282 );
1283 }
1284 }
1285 }
1286