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}"; |
|
|
|
|
21
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
22
|
|
|
|
23
|
|
|
$this->verb = 'get'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
return $this->doPayPalRequest(); |
|
|
|
|
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"; |
|
|
|
|
45
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$this->options['json'] = [ |
|
|
|
|
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'; |
|
|
|
|
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"; |
|
|
|
|
77
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->options['json'] = [ |
|
|
|
|
80
|
|
|
'amount' => [ |
81
|
|
|
'value' => $amount, |
82
|
|
|
'currency_code' => $this->currency, |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
$this->verb = 'post'; |
|
|
|
|
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"; |
|
|
|
|
105
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->verb = 'post'; |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $this->doPayPalRequest(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|