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(string $authorization_id) |
19
|
|
|
{ |
20
|
|
|
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}"; |
21
|
|
|
|
22
|
|
|
$this->verb = 'get'; |
23
|
|
|
|
24
|
|
|
return $this->doPayPalRequest(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Capture an authorized payment. |
29
|
|
|
* |
30
|
|
|
* @param string $authorization_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/#authorizations_capture |
40
|
|
|
*/ |
41
|
|
|
public function captureAuthorizedPayment(string $authorization_id, string $invoice_id, float $amount, string $note) |
42
|
|
|
{ |
43
|
|
|
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/capture"; |
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
|
|
|
'final_capture' => true, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
$this->verb = 'post'; |
56
|
|
|
|
57
|
|
|
return $this->doPayPalRequest(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Reauthorize an authorized payment. |
62
|
|
|
* |
63
|
|
|
* @param string $authorization_id |
64
|
|
|
* @param float $amount |
65
|
|
|
* |
66
|
|
|
* @throws \Throwable |
67
|
|
|
* |
68
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
69
|
|
|
* |
70
|
|
|
* @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize |
71
|
|
|
*/ |
72
|
|
|
public function reAuthorizeAuthorizedPayment(string $authorization_id, float $amount) |
73
|
|
|
{ |
74
|
|
|
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/reauthorize"; |
75
|
|
|
|
76
|
|
|
$this->options['json'] = [ |
77
|
|
|
'amount' => [ |
78
|
|
|
'value' => $amount, |
79
|
|
|
'currency_code' => $this->currency, |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$this->verb = 'post'; |
84
|
|
|
|
85
|
|
|
return $this->doPayPalRequest(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Void an authorized payment. |
90
|
|
|
* |
91
|
|
|
* @param string $authorization_id |
92
|
|
|
* |
93
|
|
|
* @throws \Throwable |
94
|
|
|
* |
95
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
96
|
|
|
* |
97
|
|
|
* @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_void |
98
|
|
|
*/ |
99
|
|
|
public function voidAuthorizedPayment(string $authorization_id) |
100
|
|
|
{ |
101
|
|
|
$this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/void"; |
102
|
|
|
|
103
|
|
|
$this->verb = 'post'; |
104
|
|
|
|
105
|
|
|
return $this->doPayPalRequest(false); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|