Completed
Push — v2.0 ( e925c3...86b790 )
by Raza
10:06
created

PaymentCaptures::refundCapturedPayment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 17
rs 9.9332
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($capture_id)
19
    {
20
        $this->apiEndPoint = "v2/payments/captures/{$capture_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...
21
        $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...
22
23
        $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...
24
25
        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

25
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
26
    }
27
28
    /**
29
     * Refund a captured payment.
30
     *
31
     * @param string $capture_id
32
     * @param string $invoice_id
33
     * @param float  $amount
34
     * @param string $note
35
     *
36
     * @throws \Throwable
37
     *
38
     * @return array|\Psr\Http\Message\StreamInterface|string
39
     *
40
     * @see https://developer.paypal.com/docs/api/payments/v2/#captures_refund
41
     */
42
    public function refundCapturedPayment($capture_id, $invoice_id, $amount, $note)
43
    {
44
        $this->apiEndPoint = "v2/payments/captures/{$capture_id}/refund";
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...
45
        $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...
46
47
        $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...
48
            'amount' => [
49
                'value'         => $amount,
50
                'currency_code' => $this->currency,
51
            ],
52
            'invoice_id'    => $invoice_id,
53
            'note_to_payer' => $note,
54
        ];
55
56
        $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...
57
58
        return $this->doPayPalRequest();
59
    }
60
}
61