1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bookeo\Endpoints; |
4
|
|
|
|
5
|
|
|
use Bookeo\Client; |
6
|
|
|
use Bookeo\Models\BookingsList; |
7
|
|
|
use Bookeo\Models\Customer; |
8
|
|
|
use Bookeo\Models\CustomersList; |
9
|
|
|
use Bookeo\Models\LinkedPersonList; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Operations to manage customers |
13
|
|
|
* |
14
|
|
|
* @package Bookeo\Endpoints |
15
|
|
|
*/ |
16
|
|
|
class Customers extends Client |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Retrieve customers |
20
|
|
|
* |
21
|
|
|
* Get a list of customers. |
22
|
|
|
* |
23
|
|
|
* @return $this |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function all(): self |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
// Set HTTP params |
28
|
|
|
$this->type = 'get'; |
29
|
|
|
$this->endpoint = '/customers' . '?' . $this->getQuery(); |
30
|
|
|
$this->response = CustomersList::class; |
|
|
|
|
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create a new customer. |
37
|
|
|
* |
38
|
|
|
* Please note there is a limit to the number of customers that can be imported in Bookeo. Bookeo is primarily a booking system, not a CRM. |
39
|
|
|
* |
40
|
|
|
* @param Customer $customer |
41
|
|
|
* |
42
|
|
|
* @return $this |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function create(Customer $customer): self |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
// Set HTTP params |
47
|
|
|
$this->type = 'post'; |
48
|
|
|
$this->endpoint = '/customers' . '?' . $this->getQuery(); |
49
|
|
|
$this->params = $customer; |
50
|
|
|
$this->response = Customer::class; |
|
|
|
|
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Retrieve a customer |
57
|
|
|
* |
58
|
|
|
* Retrieve a customer by its id |
59
|
|
|
* |
60
|
|
|
* @param string $customer_id |
61
|
|
|
* |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function __invoke(string $customer_id) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$this->customer_id = $customer_id; |
|
|
|
|
67
|
|
|
|
68
|
|
|
// Set HTTP params |
69
|
|
|
$this->type = 'get'; |
70
|
|
|
$this->endpoint = '/customers/' . $customer_id . '?' . $this->getQuery(); |
71
|
|
|
$this->response = Customer::class; |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Update an existing customer |
78
|
|
|
* |
79
|
|
|
* @param Customer $customer |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function update(Customer $customer): self |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
// Set HTTP params |
86
|
|
|
$this->type = 'put'; |
87
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery(); |
|
|
|
|
88
|
|
|
$this->params = $customer; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Delete a customer |
95
|
|
|
* |
96
|
|
|
* Please note it is not possible to delete customers that have bookings in the future, and that are not cancelled. |
97
|
|
|
* If your application needs to delete a customer with future bookings, make sure to cancel all future bookings for that customer first. |
98
|
|
|
* |
99
|
|
|
* @return $this |
100
|
|
|
*/ |
101
|
|
|
public function delete(): self |
102
|
|
|
{ |
103
|
|
|
// Set HTTP params |
104
|
|
|
$this->type = 'delete'; |
105
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery(); |
|
|
|
|
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* The customer's email address is the "username" used by Bookeo to authenticate customers. |
112
|
|
|
* So to authenticate a customer your application would typically use GET /customers to search for customers with a given email address, and then GET /customers/{id}/authenticate to authenticate. |
113
|
|
|
* Remember that there may be duplicate customer records with the same email address, ex. due to duplicate importing or manual record creation. |
114
|
|
|
* |
115
|
|
|
* @param string $password |
116
|
|
|
* |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
|
|
public function authenticate(string $password): self |
120
|
|
|
{ |
121
|
|
|
$this->appendToQuery('password', $password); |
122
|
|
|
|
123
|
|
|
// Set HTTP params |
124
|
|
|
$this->type = 'get'; |
125
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/authenticate?' . $this->getQuery(); |
|
|
|
|
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param string|null $beginDate if specified, only bookings on or after this date will be included |
132
|
|
|
* @param string|null $endDate if specified, only bookings on or before this date will be included |
133
|
|
|
* @param bool $expandParticipants if true, full details of the participants are included (provided the application has read permission over the participant) |
134
|
|
|
* @param int $itemsPerPage maximum: 100 |
135
|
|
|
* @param string|null $pageNavigationToken |
136
|
|
|
* @param int $pageNumber |
137
|
|
|
* @return Customers |
138
|
|
|
*/ |
139
|
|
|
public function bookings(string $beginDate = null, string $endDate = null, bool $expandParticipants = false, int $itemsPerPage = 50, string $pageNavigationToken = null, int $pageNumber = 1): self |
140
|
|
|
{ |
141
|
|
|
if (null !== $beginDate) { |
142
|
|
|
$this->appendToQuery('beginDate', $beginDate); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if (null !== $endDate) { |
146
|
|
|
$this->appendToQuery('endDate', $endDate); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if (null !== $expandParticipants) { |
150
|
|
|
$this->appendToQuery('expandParticipants', $expandParticipants); |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (null !== $itemsPerPage) { |
154
|
|
|
$this->appendToQuery('itemsPerPage', $itemsPerPage); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
if (null !== $pageNavigationToken) { |
158
|
|
|
$this->appendToQuery('pageNavigationToken', $pageNavigationToken); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if (null !== $pageNumber) { |
162
|
|
|
$this->appendToQuery('pageNumber', $pageNumber); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
// Set HTTP params |
166
|
|
|
$this->type = 'get'; |
167
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/bookings?' . $this->getQuery(); |
|
|
|
|
168
|
|
|
$this->response = BookingsList::class; |
|
|
|
|
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the people linked to a customer |
175
|
|
|
* |
176
|
|
|
* @param int $itemsPerPage maximum: 100 |
177
|
|
|
* @param string|null $pageNavigationToken |
178
|
|
|
* @param int $pageNumber |
179
|
|
|
* @return Customers |
180
|
|
|
*/ |
181
|
|
View Code Duplication |
public function linkedpeople(int $itemsPerPage = 50, string $pageNavigationToken = null, int $pageNumber = 1): self |
|
|
|
|
182
|
|
|
{ |
183
|
|
|
if (null !== $itemsPerPage) { |
184
|
|
|
$this->appendToQuery('itemsPerPage', $itemsPerPage); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if (null !== $pageNavigationToken) { |
188
|
|
|
$this->appendToQuery('pageNavigationToken', $pageNavigationToken); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
if (null !== $pageNumber) { |
192
|
|
|
$this->appendToQuery('pageNumber', $pageNumber); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// Set HTTP params |
196
|
|
|
$this->type = 'get'; |
197
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/linkedpeople?' . $this->getQuery(); |
|
|
|
|
198
|
|
|
$this->response = LinkedPersonList::class; |
|
|
|
|
199
|
|
|
|
200
|
|
|
return $this; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.