1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Amelia\Monzo\Api; |
4
|
|
|
|
5
|
|
|
use Amelia\Monzo\Models\Webhook; |
6
|
|
|
|
7
|
|
|
trait Webhooks |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Get a user's webhooks. |
11
|
|
|
* |
12
|
|
|
* @param string|null $account |
13
|
|
|
* @return \Amelia\Monzo\Models\Webhook[]|\Illuminate\Support\Collection |
14
|
|
|
*/ |
15
|
|
|
public function webhooks(string $account = null) |
16
|
|
|
{ |
17
|
|
|
$results = $this->call('GET', 'webhooks', [ |
18
|
|
|
'account_id' => $account ?? $this->getAccountId(), |
19
|
|
|
], [], 'webhooks'); |
20
|
|
|
|
21
|
|
|
return collect($results)->map(function ($item) { |
22
|
|
|
return new Webhook($item, $this); |
23
|
|
|
}); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get an individual webhook by ID. |
28
|
|
|
* |
29
|
|
|
* @param string $id |
30
|
|
|
* @return \Amelia\Monzo\Models\Webhook |
31
|
|
|
*/ |
32
|
|
|
public function webhook(string $id) |
33
|
|
|
{ |
34
|
|
|
$result = $this->call('GET', "webhooks/$id", [], [], 'webhooks'); |
35
|
|
|
|
36
|
|
|
return new Webhook($result, $this); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Delete a webhook by ID. |
41
|
|
|
* |
42
|
|
|
* @param string $id |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function deleteWebhook(string $id) |
46
|
|
|
{ |
47
|
|
|
$this->call('DELETE', "webhooks/$id"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register a webhook to an optional account. |
52
|
|
|
* |
53
|
|
|
* @param string $url |
54
|
|
|
* @param string|null $account |
55
|
|
|
* @return \Amelia\Monzo\Models\Webhook |
56
|
|
|
*/ |
57
|
|
|
public function registerWebhook(string $url, string $account = null) |
58
|
|
|
{ |
59
|
|
|
$result = $this->call('POST', 'webhooks', [], [ |
60
|
|
|
'url' => $url, |
61
|
|
|
'account_id' => $account ?? $this->getAccountId(), |
62
|
|
|
], 'webhook'); |
63
|
|
|
|
64
|
|
|
return new Webhook($result, $this); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|