1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
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'; |
|
|
|
|
22
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
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; |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->verb = 'post'; |
|
|
|
|
32
|
|
|
|
33
|
|
|
return $this->doPayPalRequest(); |
|
|
|
|
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'; |
|
|
|
|
48
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->verb = 'get'; |
|
|
|
|
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}"; |
|
|
|
|
69
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->verb = 'delete'; |
|
|
|
|
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) |
89
|
|
|
{ |
90
|
|
|
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; |
|
|
|
|
91
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
92
|
|
|
|
93
|
|
|
$this->options['json'] = $data; |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->verb = 'patch'; |
|
|
|
|
96
|
|
|
|
97
|
|
|
return $this->doPayPalRequest(); |
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}"; |
|
|
|
|
114
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$this->verb = 'get'; |
|
|
|
|
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) |
133
|
|
|
{ |
134
|
|
|
$this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}/event-types"; |
|
|
|
|
135
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
136
|
|
|
|
137
|
|
|
$this->verb = 'get'; |
|
|
|
|
138
|
|
|
|
139
|
|
|
return $this->doPayPalRequest(); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|