1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
trait WebHooksEvents |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* List all events types for web hooks. |
9
|
|
|
* |
10
|
|
|
* @throws \Throwable |
11
|
|
|
* |
12
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
13
|
|
|
* |
14
|
|
|
* @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-event-types_list |
15
|
|
|
*/ |
16
|
|
|
public function listEventTypes() |
17
|
|
|
{ |
18
|
|
|
$this->apiEndPoint = 'v1/notifications/webhooks-event-types'; |
|
|
|
|
19
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
20
|
|
|
|
21
|
|
|
$this->verb = 'get'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
return $this->doPayPalRequest(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* List all events notifications for web hooks. |
28
|
|
|
* |
29
|
|
|
* @throws \Throwable |
30
|
|
|
* |
31
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
32
|
|
|
* |
33
|
|
|
* @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_list |
34
|
|
|
*/ |
35
|
|
|
public function listEvents() |
36
|
|
|
{ |
37
|
|
|
$this->apiEndPoint = 'v1/notifications/webhooks-events'; |
|
|
|
|
38
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->verb = 'get'; |
|
|
|
|
41
|
|
|
|
42
|
|
|
return $this->doPayPalRequest(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* List all events notifications for web hooks. |
47
|
|
|
* |
48
|
|
|
* @param string $event_id |
49
|
|
|
* |
50
|
|
|
* @throws \Throwable |
51
|
|
|
* |
52
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
53
|
|
|
* |
54
|
|
|
* @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_get |
55
|
|
|
*/ |
56
|
|
|
public function showEventDetails($event_id) |
57
|
|
|
{ |
58
|
|
|
$this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}"; |
|
|
|
|
59
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$this->verb = 'get'; |
|
|
|
|
62
|
|
|
|
63
|
|
|
return $this->doPayPalRequest(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Resend notification for the event. |
68
|
|
|
* |
69
|
|
|
* @param string $event_id |
70
|
|
|
* @param array $items |
71
|
|
|
* |
72
|
|
|
* @throws \Throwable |
73
|
|
|
* |
74
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
75
|
|
|
* |
76
|
|
|
* @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_resend |
77
|
|
|
*/ |
78
|
|
|
public function resendEventNotification($event_id, array $items) |
79
|
|
|
{ |
80
|
|
|
$this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}/resend"; |
|
|
|
|
81
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->options['json'] = [ |
|
|
|
|
84
|
|
|
'webhook_ids' => $items |
85
|
|
|
]; |
86
|
|
|
$this->verb = 'post'; |
|
|
|
|
87
|
|
|
|
88
|
|
|
return $this->doPayPalRequest(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|