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

PaymentAuthorizations::voidAuthorizedPayment()   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 PaymentAuthorizations
6
{
7
    /**
8
     * Show details for authorized payment.
9
     *
10
     * @param string $authorization_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/#authorizations_get
17
     */
18
    public function showAuthorizedPaymentDetails($authorization_id)
19
    {
20
        $this->apiEndPoint = "v2/payments/authorizations/{$authorization_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
     * Capture an authorized payment.
30
     *
31
     * @param string $authorization_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/#authorizations_capture
41
     */
42
    public function captureAuthorizedPayment($authorization_id, $invoice_id, $amount, $note)
43
    {
44
        $this->apiEndPoint = "v2/payments/authorizations/{$authorization_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...
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
            'final_capture' => true,
55
        ];
56
57
        $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...
58
59
        return $this->doPayPalRequest();
60
    }
61
62
    /**
63
     * Reauthorize an authorized payment.
64
     *
65
     * @param string $authorization_id
66
     * @param float  $amount
67
     *
68
     * @throws \Throwable
69
     *
70
     * @return array|\Psr\Http\Message\StreamInterface|string
71
     *
72
     * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize
73
     */
74
    public function reAuthorizeAuthorizedPayment($authorization_id, $amount)
75
    {
76
        $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/reauthorize";
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...
77
        $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...
78
79
        $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...
80
            'amount' => [
81
                'value'         => $amount,
82
                'currency_code' => $this->currency,
83
            ],
84
        ];
85
86
        $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...
87
88
        return $this->doPayPalRequest();
89
    }
90
91
    /**
92
     * Void an authorized payment.
93
     *
94
     * @param string $authorization_id
95
     *
96
     * @throws \Throwable
97
     *
98
     * @return array|\Psr\Http\Message\StreamInterface|string
99
     *
100
     * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_void
101
     */
102
    public function voidAuthorizedPayment($authorization_id)
103
    {
104
        $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/void";
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...
105
        $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...
106
107
        $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...
108
109
        return $this->doPayPalRequest();
110
    }
111
}
112