PaymentCaptures   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refundCapturedPayment() 0 16 1
A showCapturedPaymentDetails() 0 7 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait PaymentCaptures
6
{
7
    /**
8
     * Show details for a captured payment.
9
     *
10
     * @param string $capture_id
11
     *
12
     * @throws \Throwable
13
     *
14
     * @return array|\Psr\Http\Message\StreamInterface|string
15
     *
16
     * @see https://developer.paypal.com/docs/api/payments/v2/#captures_get
17
     */
18
    public function showCapturedPaymentDetails(string $capture_id)
19
    {
20
        $this->apiEndPoint = "v2/payments/captures/{$capture_id}";
21
22
        $this->verb = 'get';
23
24
        return $this->doPayPalRequest();
25
    }
26
27
    /**
28
     * Refund a captured payment.
29
     *
30
     * @param string $capture_id
31
     * @param string $invoice_id
32
     * @param float  $amount
33
     * @param string $note
34
     *
35
     * @throws \Throwable
36
     *
37
     * @return array|\Psr\Http\Message\StreamInterface|string
38
     *
39
     * @see https://developer.paypal.com/docs/api/payments/v2/#captures_refund
40
     */
41
    public function refundCapturedPayment(string $capture_id, string $invoice_id, float $amount, string $note)
42
    {
43
        $this->apiEndPoint = "v2/payments/captures/{$capture_id}/refund";
44
45
        $this->options['json'] = [
46
            'amount' => [
47
                'value'         => $amount,
48
                'currency_code' => $this->currency,
49
            ],
50
            'invoice_id'    => $invoice_id,
51
            'note_to_payer' => $note,
52
        ];
53
54
        $this->verb = 'post';
55
56
        return $this->doPayPalRequest();
57
    }
58
}
59