Passed
Push — v2.0 ( 36b776...013406 )
by Raza
02:14
created

WebHooks::listWebHookDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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';
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
33
        return $this->doPayPalRequest();
1 ignored issue
show
Bug introduced by
It seems like doPayPalRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
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
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
49
50
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
69
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
70
71
        $this->verb = 'delete';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
91
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
92
93
        $this->options['json'] = $data;
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
94
95
        $this->verb = 'patch';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
114
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
115
116
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
135
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
136
137
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
138
139
        return $this->doPayPalRequest();
140
    }
141
}
142