Total Complexity | 6 |
Total Lines | 135 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | trait WebHooks |
||
6 | { |
||
7 | /** |
||
8 | * Create a new web hook. |
||
9 | * |
||
10 | * @param string $url |
||
11 | * @param array $events |
||
12 | * |
||
13 | * @throws \Throwable |
||
14 | * |
||
15 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
16 | * |
||
17 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post |
||
18 | */ |
||
19 | public function createWebHook($url, array $events) |
||
20 | { |
||
21 | $this->apiEndPoint = 'v1/notifications/webhooks'; |
||
1 ignored issue
–
show
|
|||
22 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
23 | |||
24 | $data = ['url' => $url]; |
||
25 | $data['event_types'] = collect($events)->map(function ($item) { |
||
26 | return ['name' => $item]; |
||
27 | })->toArray(); |
||
28 | |||
29 | $this->options['json'] = $data; |
||
1 ignored issue
–
show
|
|||
30 | |||
31 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
32 | |||
33 | return $this->doPayPalRequest(); |
||
1 ignored issue
–
show
|
|||
34 | } |
||
35 | |||
36 | /** |
||
37 | * List all web hooks. |
||
38 | * |
||
39 | * @throws \Throwable |
||
40 | * |
||
41 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
42 | * |
||
43 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_list |
||
44 | */ |
||
45 | public function listWebHooks() |
||
46 | { |
||
47 | $this->apiEndPoint = 'v1/notifications/webhooks'; |
||
1 ignored issue
–
show
|
|||
48 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
49 | |||
50 | $this->verb = 'get'; |
||
1 ignored issue
–
show
|
|||
51 | |||
52 | return $this->doPayPalRequest(); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Delete a web hook. |
||
57 | * |
||
58 | * @param string $web_hook_id |
||
59 | * |
||
60 | * @throws \Throwable |
||
61 | * |
||
62 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
63 | * |
||
64 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_delete |
||
65 | */ |
||
66 | public function deleteWebHook($web_hook_id) |
||
67 | { |
||
68 | $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; |
||
1 ignored issue
–
show
|
|||
69 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
70 | |||
71 | $this->verb = 'delete'; |
||
1 ignored issue
–
show
|
|||
72 | |||
73 | return $this->doPayPalRequest(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Update an existing web hook. |
||
78 | * |
||
79 | * @param string $web_hook_id |
||
80 | * @param array $data |
||
81 | * |
||
82 | * @throws \Throwable |
||
83 | * |
||
84 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
85 | * |
||
86 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_update |
||
87 | */ |
||
88 | public function updateWebHook($web_hook_id, array $data) |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Show details for an existing web hook. |
||
102 | * |
||
103 | * @param string $web_hook_id |
||
104 | * |
||
105 | * @throws \Throwable |
||
106 | * |
||
107 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
108 | * |
||
109 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get |
||
110 | */ |
||
111 | public function showWebHookDetails($web_hook_id) |
||
112 | { |
||
113 | $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; |
||
1 ignored issue
–
show
|
|||
114 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
115 | |||
116 | $this->verb = 'get'; |
||
1 ignored issue
–
show
|
|||
117 | |||
118 | return $this->doPayPalRequest(); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * List events for an existing web hook. |
||
123 | * |
||
124 | * @param string $web_hook_id |
||
125 | * |
||
126 | * @throws \Throwable |
||
127 | * |
||
128 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
129 | * |
||
130 | * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get |
||
131 | */ |
||
132 | public function listWebHookDetails($web_hook_id) |
||
140 | } |
||
141 | } |
||
142 |