|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bookeo\Endpoints; |
|
4
|
|
|
|
|
5
|
|
|
use Bookeo\Client; |
|
6
|
|
|
use Bookeo\Models\Webhook; |
|
7
|
|
|
use Bookeo\Models\WebhooksList; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Manage callback notifications |
|
11
|
|
|
* |
|
12
|
|
|
* @package Bookeo\Endpoints |
|
13
|
|
|
*/ |
|
14
|
|
|
class Webhooks extends Client |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* List all webhooks |
|
18
|
|
|
* |
|
19
|
|
|
* Retrieve all the webhooks for this api key |
|
20
|
|
|
* |
|
21
|
|
|
* @return $this |
|
22
|
|
|
*/ |
|
23
|
|
|
public function all(): self |
|
24
|
|
|
{ |
|
25
|
|
|
// Set HTTP params |
|
26
|
|
|
$this->type = 'get'; |
|
27
|
|
|
$this->endpoint = '/webhooks' . '?' . $this->getQuery(); |
|
28
|
|
|
$this->response = WebhooksList::class; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
return $this; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create a new webhook |
|
35
|
|
|
* |
|
36
|
|
|
* Note that if an existing webhook for the same domain and type was already set for this api key, it will be automatically replaced by this new webhook. |
|
37
|
|
|
* In other words, there can be only one webhook for each combination of domain and type, for an API key. |
|
38
|
|
|
* So to upgrade an existing webhook URL, simply create a new one with the same domain and type, but a different URL. |
|
39
|
|
|
* |
|
40
|
|
|
* For webhook with domain "bookings" and type "deleted", the notification will be sent whether the booking is canceled or completely deleted. |
|
41
|
|
|
* Users can delete bookings by, for example, deleting their associated customer. |
|
42
|
|
|
* Also note that these "bookings" "deleted" notifications are sent even for bookings in the past. |
|
43
|
|
|
* |
|
44
|
|
|
* @param Webhook $webhook |
|
45
|
|
|
* |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
|
View Code Duplication |
public function create(Webhook $webhook): self |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
// Set HTTP params |
|
51
|
|
|
$this->type = 'post'; |
|
52
|
|
|
$this->endpoint = '/webhooks' . '?' . $this->getQuery(); |
|
53
|
|
|
$this->params = $webhook; |
|
54
|
|
|
$this->response = Webhook::class; |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Retrieve a webhook |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $webhook_id |
|
63
|
|
|
* |
|
64
|
|
|
* @return $this |
|
65
|
|
|
*/ |
|
66
|
|
View Code Duplication |
public function __invoke(string $webhook_id) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$this->webhook_id = $webhook_id; |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
// Set HTTP params |
|
71
|
|
|
$this->type = 'get'; |
|
72
|
|
|
$this->endpoint = '/webhooks/' . $webhook_id . '?' . $this->getQuery(); |
|
73
|
|
|
$this->response = Webhook::class; |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Delete a webhook |
|
80
|
|
|
* |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function delete(): self |
|
84
|
|
|
{ |
|
85
|
|
|
// Set HTTP params |
|
86
|
|
|
$this->type = 'delete'; |
|
87
|
|
|
$this->endpoint = '/webhooks/' . $this->webhook_id; |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.