1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bookeo\Endpoints; |
4
|
|
|
|
5
|
|
|
use Bookeo\Client; |
6
|
|
|
use Bookeo\Interfaces\QueryInterface; |
7
|
|
|
use Bookeo\Models\BookingsList; |
8
|
|
|
use Bookeo\Models\Customer; |
9
|
|
|
use Bookeo\Models\CustomersList; |
10
|
|
|
use Bookeo\Models\LinkedPersonList; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Operations to manage customers |
14
|
|
|
* |
15
|
|
|
* @package Bookeo\Endpoints |
16
|
|
|
*/ |
17
|
|
|
class Customers extends Client |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Retrieve customers |
21
|
|
|
* |
22
|
|
|
* Get a list of customers. |
23
|
|
|
* |
24
|
|
|
* @param string|null $searchText |
25
|
|
|
* @param string|null $searchField |
26
|
|
|
* @param string|null $createdSince date-time |
27
|
|
|
* @param bool|null $currentMembers |
28
|
|
|
* @param bool|null $currentNonMembers |
29
|
|
|
* @param int $itemsPerPage maximum: 100 |
30
|
|
|
* @param string|null $pageNavigationToken |
31
|
|
|
* @param int $pageNumber |
32
|
|
|
* |
33
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
34
|
|
|
*/ |
35
|
|
|
public function all( |
36
|
|
|
string $searchText = null, |
37
|
|
|
string $searchField = null, |
38
|
|
|
string $createdSince = null, |
39
|
|
|
bool $currentMembers = true, |
40
|
|
|
bool $currentNonMembers = true, |
41
|
|
|
int $itemsPerPage = 50, |
42
|
|
|
string $pageNavigationToken = null, |
43
|
|
|
int $pageNumber = 1 |
44
|
|
|
): QueryInterface { |
45
|
|
|
|
46
|
|
|
if (!empty($searchText)) { |
47
|
|
|
$this->appendToQuery('searchText', $searchText); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (!empty($searchField)) { |
51
|
|
|
$this->appendToQuery('searchField', $searchField); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (!empty($createdSince)) { |
55
|
|
|
$this->appendToQuery('createdSince', $createdSince); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($currentMembers !== null) { |
59
|
|
|
$this->appendToQuery('currentMembers', $currentMembers); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($currentNonMembers !== null) { |
63
|
|
|
$this->appendToQuery('currentNonMembers', $currentNonMembers); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (!empty($itemsPerPage)) { |
67
|
|
|
$this->appendToQuery('itemsPerPage', $itemsPerPage); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!empty($pageNavigationToken)) { |
71
|
|
|
$this->appendToQuery('pageNavigationToken', $pageNavigationToken); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!empty($pageNumber)) { |
75
|
|
|
$this->appendToQuery('pageNumber', $pageNumber); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Set HTTP params |
79
|
|
|
$this->type = 'get'; |
80
|
|
|
$this->endpoint = '/customers' . '?' . $this->getQuery(); |
81
|
|
|
$this->response = CustomersList::class; |
|
|
|
|
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Create a new customer. |
88
|
|
|
* |
89
|
|
|
* 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. |
90
|
|
|
* |
91
|
|
|
* @param Customer $customer |
92
|
|
|
* |
93
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
94
|
|
|
*/ |
95
|
|
|
public function create(Customer $customer): QueryInterface |
96
|
|
|
{ |
97
|
|
|
// Set HTTP params |
98
|
|
|
$this->type = 'post'; |
99
|
|
|
$this->endpoint = '/customers' . '?' . $this->getQuery(); |
100
|
|
|
$this->params = $customer; |
101
|
|
|
$this->response = Customer::class; |
|
|
|
|
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Retrieve a customer |
108
|
|
|
* |
109
|
|
|
* Retrieve a customer by its id |
110
|
|
|
* |
111
|
|
|
* @param string $customer_id |
112
|
|
|
* |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function __invoke(string $customer_id) |
116
|
|
|
{ |
117
|
|
|
$this->customer_id = $customer_id; |
|
|
|
|
118
|
|
|
|
119
|
|
|
// Set HTTP params |
120
|
|
|
$this->type = 'get'; |
121
|
|
|
$this->endpoint = '/customers/' . $customer_id . '?' . $this->getQuery(); |
122
|
|
|
$this->response = Customer::class; |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Update an existing customer |
129
|
|
|
* |
130
|
|
|
* @param Customer $customer |
131
|
|
|
* |
132
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
133
|
|
|
*/ |
134
|
|
View Code Duplication |
public function update(Customer $customer): QueryInterface |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
// Set HTTP params |
137
|
|
|
$this->type = 'put'; |
138
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery(); |
|
|
|
|
139
|
|
|
$this->params = $customer; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Delete a customer |
146
|
|
|
* |
147
|
|
|
* Please note it is not possible to delete customers that have bookings in the future, and that are not cancelled. |
148
|
|
|
* If your application needs to delete a customer with future bookings, make sure to cancel all future bookings for that customer first. |
149
|
|
|
* |
150
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
151
|
|
|
*/ |
152
|
|
|
public function delete(): QueryInterface |
153
|
|
|
{ |
154
|
|
|
// Set HTTP params |
155
|
|
|
$this->type = 'delete'; |
156
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '?' . $this->getQuery(); |
|
|
|
|
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* The customer's email address is the "username" used by Bookeo to authenticate customers. |
163
|
|
|
* So to authenticate a customer your application would typically use GET /customers to search for customers with a given email address, and then GET |
164
|
|
|
* /customers/{id}/authenticate to authenticate. Remember that there may be duplicate customer records with the same email address, ex. due to duplicate importing or manual |
165
|
|
|
* record creation. |
166
|
|
|
* |
167
|
|
|
* @param string $password |
168
|
|
|
* |
169
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
170
|
|
|
*/ |
171
|
|
View Code Duplication |
public function authenticate(string $password): QueryInterface |
|
|
|
|
172
|
|
|
{ |
173
|
|
|
$this->appendToQuery('password', $password); |
174
|
|
|
|
175
|
|
|
// Set HTTP params |
176
|
|
|
$this->type = 'get'; |
177
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/authenticate?' . $this->getQuery(); |
|
|
|
|
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string|null $beginDate if specified, only bookings on or after this date will be included |
184
|
|
|
* @param string|null $endDate if specified, only bookings on or before this date will be included |
185
|
|
|
* @param bool $expandParticipants if true, full details of the participants are included (provided the application has read permission over the participant) |
186
|
|
|
* @param int $itemsPerPage maximum: 100 |
187
|
|
|
* @param string|null $pageNavigationToken |
188
|
|
|
* @param int $pageNumber |
189
|
|
|
* |
190
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
191
|
|
|
*/ |
192
|
|
|
public function bookings( |
193
|
|
|
string $beginDate = null, |
194
|
|
|
string $endDate = null, |
195
|
|
|
bool $expandParticipants = false, |
196
|
|
|
int $itemsPerPage = 50, |
197
|
|
|
string $pageNavigationToken = null, |
198
|
|
|
int $pageNumber = 1 |
199
|
|
|
): QueryInterface { |
200
|
|
|
|
201
|
|
|
if (!empty($beginDate)) { |
202
|
|
|
$this->appendToQuery('beginDate', $beginDate); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
if (!empty($endDate)) { |
206
|
|
|
$this->appendToQuery('endDate', $endDate); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
if (!empty($expandParticipants)) { |
210
|
|
|
$this->appendToQuery('expandParticipants', $expandParticipants); |
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
if (!empty($itemsPerPage)) { |
214
|
|
|
$this->appendToQuery('itemsPerPage', $itemsPerPage); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
if (!empty($pageNavigationToken)) { |
218
|
|
|
$this->appendToQuery('pageNavigationToken', $pageNavigationToken); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
if (!empty($pageNumber)) { |
222
|
|
|
$this->appendToQuery('pageNumber', $pageNumber); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
// Set HTTP params |
226
|
|
|
$this->type = 'get'; |
227
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/bookings?' . $this->getQuery(); |
|
|
|
|
228
|
|
|
$this->response = BookingsList::class; |
|
|
|
|
229
|
|
|
|
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get the people linked to a customer |
235
|
|
|
* |
236
|
|
|
* @param int $itemsPerPage maximum: 100 |
237
|
|
|
* @param string|null $pageNavigationToken |
238
|
|
|
* @param int $pageNumber |
239
|
|
|
* |
240
|
|
|
* @return \Bookeo\Interfaces\QueryInterface |
241
|
|
|
*/ |
242
|
|
View Code Duplication |
public function linkedpeople( |
|
|
|
|
243
|
|
|
int $itemsPerPage = 50, |
244
|
|
|
string $pageNavigationToken = null, |
245
|
|
|
int $pageNumber = 1 |
246
|
|
|
): QueryInterface { |
247
|
|
|
|
248
|
|
|
if (!empty($itemsPerPage)) { |
249
|
|
|
$this->appendToQuery('itemsPerPage', $itemsPerPage); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
if (!empty($pageNavigationToken)) { |
253
|
|
|
$this->appendToQuery('pageNavigationToken', $pageNavigationToken); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
if (!empty($pageNumber)) { |
257
|
|
|
$this->appendToQuery('pageNumber', $pageNumber); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
// Set HTTP params |
261
|
|
|
$this->type = 'get'; |
262
|
|
|
$this->endpoint = '/customers/' . $this->customer_id . '/linkedpeople?' . $this->getQuery(); |
|
|
|
|
263
|
|
|
$this->response = LinkedPersonList::class; |
|
|
|
|
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: