Total Complexity | 23 |
Total Lines | 402 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | trait Invoices |
||
6 | { |
||
7 | /** |
||
8 | * Generate the next invoice number. |
||
9 | * |
||
10 | * @throws \Throwable |
||
11 | * |
||
12 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
13 | * |
||
14 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-next-invoice-number |
||
15 | */ |
||
16 | public function generateInvoiceNumber() |
||
17 | { |
||
18 | $this->apiEndPoint = "v2/invoicing/generate-next-invoice-number"; |
||
1 ignored issue
–
show
|
|||
19 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
20 | |||
21 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
22 | |||
23 | return $this->doPayPalRequest(); |
||
1 ignored issue
–
show
|
|||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Create a new draft invoice. |
||
28 | * |
||
29 | * @param array $data |
||
30 | * |
||
31 | * @throws \Throwable |
||
32 | * |
||
33 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
34 | * |
||
35 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_create |
||
36 | */ |
||
37 | public function createInvoice(array $data) |
||
38 | { |
||
39 | $this->apiEndPoint = "v2/invoicing/invoices"; |
||
1 ignored issue
–
show
|
|||
40 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
41 | |||
42 | $this->options['json'] = $data; |
||
1 ignored issue
–
show
|
|||
43 | |||
44 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
45 | |||
46 | return $this->doPayPalRequest(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Get list of invoices. |
||
51 | * |
||
52 | * @param int $page |
||
53 | * @param int $size |
||
54 | * @param bool $totals |
||
55 | * @param array $fields |
||
56 | * |
||
57 | * @throws \Throwable |
||
58 | * |
||
59 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
60 | * |
||
61 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list |
||
62 | */ |
||
63 | public function listInvoices($page=1, $size=20, $totals=true, array $fields=[]) |
||
64 | { |
||
65 | $fields_list = collect($fields); |
||
66 | |||
67 | $fields = ""; |
||
68 | if ($fields_list->count() > 0) |
||
69 | $fields = "&fields={$fields_list->implode(",")}"; |
||
70 | |||
71 | $this->apiEndPoint = "v2/invoicing/invoices?page={$page}&page_size={$size}&total_required={$totals}{$fields}"; |
||
1 ignored issue
–
show
|
|||
72 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
73 | |||
74 | $this->verb = 'get'; |
||
1 ignored issue
–
show
|
|||
75 | |||
76 | return $this->doPayPalRequest(); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Delete an invoice. |
||
81 | * |
||
82 | * @param string $invoice_id |
||
83 | * |
||
84 | * @throws \Throwable |
||
85 | * |
||
86 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
87 | * |
||
88 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list |
||
89 | */ |
||
90 | public function deleteInvoice($invoice_id) |
||
91 | { |
||
92 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; |
||
1 ignored issue
–
show
|
|||
93 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
94 | |||
95 | $this->verb = 'delete'; |
||
1 ignored issue
–
show
|
|||
96 | |||
97 | return $this->doPayPalRequest(); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Update an existing invoice. |
||
102 | * |
||
103 | * @param string $invoice_id |
||
104 | * @param array $data |
||
105 | * |
||
106 | * @throws \Throwable |
||
107 | * |
||
108 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
109 | * |
||
110 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update |
||
111 | */ |
||
112 | public function updateInvoice($invoice_id, array $data) |
||
113 | { |
||
114 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; |
||
1 ignored issue
–
show
|
|||
115 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
116 | |||
117 | $this->options['json'] = $data; |
||
1 ignored issue
–
show
|
|||
118 | |||
119 | $this->verb = 'put'; |
||
1 ignored issue
–
show
|
|||
120 | |||
121 | return $this->doPayPalRequest(); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Show details for an existing invoice. |
||
126 | * |
||
127 | * @param string $invoice_id |
||
128 | * |
||
129 | * @throws \Throwable |
||
130 | * |
||
131 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
132 | * |
||
133 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get |
||
134 | */ |
||
135 | public function showInvoiceDetails($invoice_id) |
||
136 | { |
||
137 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; |
||
1 ignored issue
–
show
|
|||
138 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
139 | |||
140 | $this->verb = 'get'; |
||
1 ignored issue
–
show
|
|||
141 | |||
142 | return $this->doPayPalRequest(); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Cancel an existing invoice which is already sent. |
||
147 | * |
||
148 | * @param string $invoice_id |
||
149 | * |
||
150 | * @throws \Throwable |
||
151 | * |
||
152 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
153 | * |
||
154 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_cancel |
||
155 | */ |
||
156 | public function cancelInvoice($invoice_id) |
||
157 | { |
||
158 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/cancel"; |
||
1 ignored issue
–
show
|
|||
159 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
160 | |||
161 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
162 | |||
163 | return $this->doPayPalRequest(); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Generate QR code against an existing invoice. |
||
168 | * |
||
169 | * @param string $invoice_id |
||
170 | * @param int $width |
||
171 | * @param int $height |
||
172 | * |
||
173 | * @throws \Throwable |
||
174 | * |
||
175 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
176 | * |
||
177 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code |
||
178 | */ |
||
179 | public function generateQRCodeInvoice($invoice_id, $width=200, $height=20) |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * Register payment against an existing invoice. |
||
195 | * |
||
196 | * @param string $invoice_id |
||
197 | * @param string $payment_id |
||
198 | * @param string $payment_date |
||
199 | * @param string $payment_method |
||
200 | * @param string $payment_note |
||
201 | * @param float $amount |
||
202 | * @param string $currency |
||
203 | * |
||
204 | * @throws \Throwable |
||
205 | * |
||
206 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
207 | * |
||
208 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments |
||
209 | */ |
||
210 | public function registerPaymentInvoice($invoice_id, $payment_id, $payment_date, $payment_method, $payment_note, $amount, $currency='') |
||
211 | { |
||
212 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments"; |
||
1 ignored issue
–
show
|
|||
213 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
214 | |||
215 | if (isset($currency)) { |
||
216 | $this->setCurrency($currency); |
||
217 | } |
||
218 | |||
219 | $data = [ |
||
220 | "payment_id" => $payment_id, |
||
221 | "payment_date" => $payment_date, |
||
222 | "method" => $payment_method, |
||
223 | "note" => $payment_note, |
||
224 | "amount" => [ |
||
225 | "currency" => $this->currency, |
||
226 | "value" => $amount, |
||
227 | ], |
||
228 | ]; |
||
229 | |||
230 | $this->options['json'] = $data; |
||
1 ignored issue
–
show
|
|||
231 | |||
232 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
233 | |||
234 | return $this->doPayPalRequest(); |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Delete payment against an existing invoice. |
||
239 | * |
||
240 | * @param string $invoice_id |
||
241 | * @param string $transaction_id |
||
242 | * |
||
243 | * @throws \Throwable |
||
244 | * |
||
245 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
246 | * |
||
247 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete |
||
248 | */ |
||
249 | public function deleteExternalPaymentInvoice($invoice_id, $transaction_id) |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Register payment against an existing invoice. |
||
261 | * |
||
262 | * @param string $invoice_id |
||
263 | * @param string $payment_date |
||
264 | * @param string $payment_method |
||
265 | * @param float $amount |
||
266 | * @param string $currency |
||
267 | * |
||
268 | * @throws \Throwable |
||
269 | * |
||
270 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
271 | * |
||
272 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds |
||
273 | */ |
||
274 | public function refundInvoice($invoice_id, $payment_date, $payment_method, $amount, $currency='') |
||
275 | { |
||
276 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds"; |
||
1 ignored issue
–
show
|
|||
277 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
278 | |||
279 | if (isset($currency)) { |
||
280 | $this->setCurrency($currency); |
||
281 | } |
||
282 | |||
283 | $data = [ |
||
284 | "refund_date" => $payment_date, |
||
285 | "method" => $payment_method, |
||
286 | "amount" => [ |
||
287 | "currency" => $this->currency, |
||
288 | "value" => $amount, |
||
289 | ], |
||
290 | ]; |
||
291 | |||
292 | $this->options['json'] = $data; |
||
1 ignored issue
–
show
|
|||
293 | |||
294 | $this->verb = 'post'; |
||
1 ignored issue
–
show
|
|||
295 | |||
296 | return $this->doPayPalRequest(); |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Delete refund against an existing invoice. |
||
301 | * |
||
302 | * @param string $invoice_id |
||
303 | * @param string $transaction_id |
||
304 | * |
||
305 | * @throws \Throwable |
||
306 | * |
||
307 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
308 | * |
||
309 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds-delete |
||
310 | */ |
||
311 | public function deleteRefundInvoice($invoice_id, $transaction_id) |
||
312 | { |
||
313 | $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds/{$transaction_id}"; |
||
1 ignored issue
–
show
|
|||
314 | $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
||
1 ignored issue
–
show
|
|||
315 | |||
316 | $this->verb = 'delete'; |
||
1 ignored issue
–
show
|
|||
317 | |||
318 | return $this->doPayPalRequest(); |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * Send an existing invoice. |
||
323 | * |
||
324 | * @param string $invoice_id |
||
325 | * @param string $subject |
||
326 | * @param string $note |
||
327 | * @param bool $send_recipient |
||
328 | * @param bool $send_merchant |
||
329 | * @param array $recipients |
||
330 | * |
||
331 | * @throws \Throwable |
||
332 | * |
||
333 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
334 | * |
||
335 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send |
||
336 | */ |
||
337 | public function sendInvoice($invoice_id, $subject='', $note='', $send_recipient=true, $send_merchant=false, array $recipients=[]) |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Send reminder for an existing invoice. |
||
367 | * |
||
368 | * @param string $invoice_id |
||
369 | * @param string $subject |
||
370 | * @param string $note |
||
371 | * @param bool $send_recipient |
||
372 | * @param bool $send_merchant |
||
373 | * @param array $recipients |
||
374 | * |
||
375 | * @throws \Throwable |
||
376 | * |
||
377 | * @return array|\Psr\Http\Message\StreamInterface|string |
||
378 | * |
||
379 | * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_remind |
||
380 | */ |
||
381 | public function sendInvoiceReminder($invoice_id, $subject='', $note='', $send_recipient=true, $send_merchant=false, array $recipients=[]) |
||
407 | } |
||
408 | } |
||
409 |