PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / abilities / bookings / create-booking.php
latepoint / lib / abilities / bookings Last commit date
abstract-booking-ability.php 1 week ago approve-booking.php 4 months ago cancel-booking.php 4 months ago change-booking-status.php 1 week ago create-booking.php 4 months ago delete-booking.php 1 week ago get-booking-stats.php 1 week ago get-booking-statuses.php 4 months ago get-booking.php 1 week ago get-bookings-for-date.php 4 months ago get-bookings-per-day.php 1 week ago get-upcoming-bookings.php 4 months ago list-bookings.php 4 months ago reschedule-booking.php 1 week ago update-booking.php 1 week ago
create-booking.php
113 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; }
4
5 class LatePointAbilityCreateBooking extends LatePointAbstractBookingAbility {
6
7 protected function configure(): void {
8 $this->id = 'latepoint/create-booking';
9 $this->label = __( 'Create booking', 'latepoint' );
10 $this->description = __( 'Creates a new booking for a customer with a specific service, agent, date and time. May trigger booking confirmation notifications.', 'latepoint' );
11 $this->permission = 'booking__create';
12 $this->read_only = false;
13 $this->destructive = false;
14 $this->idempotent = false;
15 }
16
17 public function get_input_schema(): array {
18 return [
19 'type' => 'object',
20 'properties' => [
21 'customer_id' => [
22 'type' => 'integer',
23 'description' => __( 'Customer ID.', 'latepoint' ),
24 ],
25 'service_id' => [
26 'type' => 'integer',
27 'description' => __( 'Service ID.', 'latepoint' ),
28 ],
29 'agent_id' => [
30 'type' => 'integer',
31 'description' => __( 'Agent ID.', 'latepoint' ),
32 ],
33 'location_id' => [
34 'type' => 'integer',
35 'description' => __( 'Location ID.', 'latepoint' ),
36 ],
37 'start_date' => [
38 'type' => 'string',
39 'format' => 'date',
40 'description' => __( 'Booking date (Y-m-d).', 'latepoint' ),
41 ],
42 'start_time' => [
43 'type' => 'integer',
44 'description' => __( 'Start time (minutes from midnight).', 'latepoint' ),
45 ],
46 'end_time' => [
47 'type' => 'integer',
48 'description' => __( 'End time (minutes from midnight).', 'latepoint' ),
49 ],
50 'status' => [
51 'type' => 'string',
52 'enum' => [ 'approved', 'pending' ],
53 'default' => 'approved',
54 'description' => __( 'Initial booking status.', 'latepoint' ),
55 ],
56 'notes' => [
57 'type' => 'string',
58 'description' => __( 'Internal booking notes.', 'latepoint' ),
59 ],
60 ],
61 'required' => [ 'customer_id', 'service_id', 'start_date', 'start_time' ],
62 ];
63 }
64
65 public function get_output_schema(): array {
66 return $this->booking_output_schema();
67 }
68
69 public function execute( array $args ) {
70 $order = new OsOrderModel();
71 $order->customer_id = (int) $args['customer_id'];
72 $order->status = LATEPOINT_ORDER_STATUS_OPEN;
73 if ( ! $order->save() ) {
74 return new WP_Error( 'save_failed', __( 'Failed to create order.', 'latepoint' ), [ 'status' => 422 ] );
75 }
76
77 $order_item = new OsOrderItemModel();
78 $order_item->order_id = $order->id;
79 if ( ! $order_item->save() ) {
80 return new WP_Error( 'save_failed', __( 'Failed to create order item.', 'latepoint' ), [ 'status' => 422 ] );
81 }
82
83 $booking = new OsBookingModel();
84 $booking->customer_id = (int) $args['customer_id'];
85 $booking->service_id = (int) $args['service_id'];
86 $booking->order_item_id = $order_item->id;
87 $booking->start_date = sanitize_text_field( $args['start_date'] );
88 $booking->start_time = (int) $args['start_time'];
89
90 if ( ! empty( $args['agent_id'] ) ) {
91 $booking->agent_id = (int) $args['agent_id'];
92 }
93 if ( ! empty( $args['location_id'] ) ) {
94 $booking->location_id = (int) $args['location_id'];
95 }
96 if ( ! empty( $args['end_time'] ) ) {
97 $booking->end_time = (int) $args['end_time'];
98 }
99
100 $booking->status = isset( $args['status'] ) ? sanitize_text_field( $args['status'] ) : LATEPOINT_BOOKING_STATUS_APPROVED;
101
102 if ( ! $booking->save() ) {
103 return new WP_Error(
104 'save_failed',
105 __( 'Failed to create booking.', 'latepoint' ),
106 WP_DEBUG ? [ 'errors' => $booking->get_error_messages() ] : [ 'status' => 422 ]
107 );
108 }
109
110 return $this->serialize_booking( new OsBookingModel( $booking->id ) );
111 }
112 }
113