Completed
Push — v2.0 ( 6a6c92...092e88 )
by Raza
13:05
created

Subscriptions::listSubscriptionTransactions()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 16
rs 9.9332
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
use Carbon\Carbon;
6
7
trait Subscriptions
8
{
9
    /**
10
     * Create a new subscription.
11
     *
12
     * @param array  $data
13
     *
14
     * @throws \Throwable
15
     *
16
     * @return array|\Psr\Http\Message\StreamInterface|string
17
     *
18
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
19
     */
20
    public function createSubscription(array $data)
21
    {
22
        $this->apiEndPoint = 'v1/billing/subscriptions';
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...
23
        $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...
24
25
        $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...
26
27
        $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...
28
29
        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

29
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
30
    }
31
32
    /**
33
     * Update an existing billing plan.
34
     *
35
     * @param string $subscription_id
36
     * @param array  $data
37
     *
38
     * @throws \Throwable
39
     *
40
     * @return array|\Psr\Http\Message\StreamInterface|string
41
     *
42
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch
43
     */
44
    public function updateSubscription($subscription_id, array $data)
45
    {
46
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_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...
47
        $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...
48
49
        $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...
50
51
        $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...
52
53
        return $this->doPayPalRequest();
54
    }
55
56
    /**
57
     * Show details for an existing subscription.
58
     *
59
     * @param string $subscription_id
60
     *
61
     * @throws \Throwable
62
     *
63
     * @return array|\Psr\Http\Message\StreamInterface|string
64
     *
65
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
66
     */
67
    public function showSubscriptionDetails($subscription_id)
68
    {
69
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_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...
70
        $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...
71
72
        $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...
73
74
        return $this->doPayPalRequest();
75
    }
76
77
    /**
78
     * Activate an existing subscription.
79
     *
80
     * @param string $subscription_id
81
     *
82
     * @throws \Throwable
83
     *
84
     * @return array|\Psr\Http\Message\StreamInterface|string
85
     *
86
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate
87
     */
88
    public function activateSubscription($subscription_id)
89
    {
90
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/activate";
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->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...
94
95
        return $this->doPayPalRequest();
96
    }
97
98
    /**
99
     * Cancel an existing subscription.
100
     *
101
     * @param string $subscription_id
102
     *
103
     * @throws \Throwable
104
     *
105
     * @return array|\Psr\Http\Message\StreamInterface|string
106
     *
107
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel
108
     */
109
    public function cancelSubscription($subscription_id)
110
    {
111
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/cancel";
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...
112
        $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...
113
114
        $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...
115
116
        return $this->doPayPalRequest();
117
    }
118
119
    /**
120
     * Suspend an existing subscription.
121
     *
122
     * @param string $subscription_id
123
     *
124
     * @throws \Throwable
125
     *
126
     * @return array|\Psr\Http\Message\StreamInterface|string
127
     *
128
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend
129
     */
130
    public function suspendSubscription($subscription_id)
131
    {
132
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/suspend";
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...
133
        $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...
134
135
        $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...
136
137
        return $this->doPayPalRequest();
138
    }
139
140
    /**
141
     * Capture payment for an existing subscription.
142
     *
143
     * @param string $subscription_id
144
     * @param string $note
145
     * @param float  $amount
146
     *
147
     * @throws \Throwable
148
     *
149
     * @return array|\Psr\Http\Message\StreamInterface|string
150
     *
151
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture
152
     */
153
    public function captureSubscriptionPayment($subscription_id, $note, $amount)
154
    {
155
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/capture";
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...
156
        $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...
157
158
        $this->options['json'] = [
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...
159
            "note"          => $note,
160
            "capture_type"  => "OUTSTANDING_BALANCE",
161
            "amount"        => [
162
                "currency"  => $this->currency,
163
                "value"     => "{$amount}",
164
            ],
165
        ];
166
167
        $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...
168
169
        return $this->doPayPalRequest();
170
    }
171
172
    /**
173
     * Revise quantity, product or service for an existing subscription.
174
     *
175
     * @param string $subscription_id
176
     * @param array  $items
177
     *
178
     * @throws \Throwable
179
     *
180
     * @return array|\Psr\Http\Message\StreamInterface|string
181
     *
182
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise
183
     */
184
    public function reviseSubscription($subscription_id, array $items)
185
    {
186
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/revise";
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...
187
        $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...
188
189
        $this->options['json'] = $items;
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...
190
191
        $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...
192
193
        return $this->doPayPalRequest();
194
    }
195
196
    /**
197
     * List transactions for an existing subscription.
198
     *
199
     * @param string $subscription_id
200
     * @param string $start_date
201
     * @param string $end_date
202
     *
203
     * @throws \Throwable
204
     *
205
     * @return array|\Psr\Http\Message\StreamInterface|string
206
     *
207
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
208
     */
209
    public function listSubscriptionTransactions($subscription_id, $start_date = "", $end_date = "")
210
    {
211
        $start_date = empty($start_date) ?
212
            Carbon::now()->subDay()->toIso8601String() :
213
            Carbon::parse($start_date)->toIso8601String();
214
215
        $end_date = empty($end_date) ?
216
            Carbon::now()->toIso8601String() :
217
            Carbon::parse($end_date)->toIso8601String();
218
219
        $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/transactions?start_time={$start_date}&end_time={$end_date}";
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...
220
        $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...
221
222
        $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...
223
224
        return $this->doPayPalRequest();
225
    }
226
}
227