1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
trait Orders |
6
|
|
|
{ |
7
|
|
|
use Orders\Helpers; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Creates an order. |
11
|
|
|
* |
12
|
|
|
* @param array $data |
13
|
|
|
* |
14
|
|
|
* @throws \Throwable |
15
|
|
|
* |
16
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
17
|
|
|
* |
18
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create |
19
|
|
|
*/ |
20
|
|
|
public function createOrder(array $data) |
21
|
|
|
{ |
22
|
|
|
$this->apiEndPoint = 'v2/checkout/orders'; |
23
|
|
|
|
24
|
|
|
$this->options['json'] = (object) $data; |
25
|
|
|
|
26
|
|
|
$this->verb = 'post'; |
27
|
|
|
|
28
|
|
|
return $this->doPayPalRequest(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Shows details for an order. |
33
|
|
|
* |
34
|
|
|
* @param string $order_id |
35
|
|
|
* |
36
|
|
|
* @throws \Throwable |
37
|
|
|
* |
38
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
39
|
|
|
* |
40
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_get |
41
|
|
|
*/ |
42
|
|
|
public function showOrderDetails(string $order_id) |
43
|
|
|
{ |
44
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}"; |
45
|
|
|
|
46
|
|
|
$this->verb = 'get'; |
47
|
|
|
|
48
|
|
|
return $this->doPayPalRequest(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Update order details. |
53
|
|
|
* |
54
|
|
|
* @param string $order_id |
55
|
|
|
* @param array $data |
56
|
|
|
* |
57
|
|
|
* @throws \Throwable |
58
|
|
|
* |
59
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
60
|
|
|
* |
61
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch |
62
|
|
|
*/ |
63
|
|
|
public function updateOrder(string $order_id, array $data) |
64
|
|
|
{ |
65
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}"; |
66
|
|
|
|
67
|
|
|
$this->options['json'] = $data; |
68
|
|
|
|
69
|
|
|
$this->verb = 'patch'; |
70
|
|
|
|
71
|
|
|
return $this->doPayPalRequest(false); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Confirm the order. |
76
|
|
|
* |
77
|
|
|
* @param string $order_id |
78
|
|
|
* @param array $data |
79
|
|
|
* |
80
|
|
|
* @throws \Throwable |
81
|
|
|
* |
82
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
83
|
|
|
*/ |
84
|
|
|
public function confirmOrder(string $order_id, array $data) |
85
|
|
|
{ |
86
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/confirm-payment-source"; |
87
|
|
|
|
88
|
|
|
$this->options['json'] = (object) $data; |
89
|
|
|
|
90
|
|
|
$this->verb = 'post'; |
91
|
|
|
|
92
|
|
|
return $this->doPayPalRequest(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Authorizes payment for an order. |
97
|
|
|
* |
98
|
|
|
* @param string $order_id |
99
|
|
|
* @param array $data |
100
|
|
|
* |
101
|
|
|
* @throws \Throwable |
102
|
|
|
* |
103
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
104
|
|
|
* |
105
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize |
106
|
|
|
*/ |
107
|
|
|
public function authorizePaymentOrder(string $order_id, array $data = []) |
108
|
|
|
{ |
109
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize"; |
110
|
|
|
|
111
|
|
|
$this->options['json'] = (object) $data; |
112
|
|
|
|
113
|
|
|
$this->verb = 'post'; |
114
|
|
|
|
115
|
|
|
return $this->doPayPalRequest(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Captures payment for an order. |
120
|
|
|
* |
121
|
|
|
* @param string $order_id |
122
|
|
|
* @param array $data |
123
|
|
|
* |
124
|
|
|
* @throws \Throwable |
125
|
|
|
* |
126
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
127
|
|
|
* |
128
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture |
129
|
|
|
*/ |
130
|
|
|
public function capturePaymentOrder(string $order_id, array $data = []) |
131
|
|
|
{ |
132
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture"; |
133
|
|
|
|
134
|
|
|
$this->options['json'] = (object) $data; |
135
|
|
|
|
136
|
|
|
$this->verb = 'post'; |
137
|
|
|
|
138
|
|
|
return $this->doPayPalRequest(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Add tracking information for an Order. |
143
|
|
|
* |
144
|
|
|
* @param string $order_id |
145
|
|
|
* @param array $data |
146
|
|
|
* |
147
|
|
|
* @throws \Throwable |
148
|
|
|
* |
149
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
150
|
|
|
* |
151
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_track_create |
152
|
|
|
*/ |
153
|
|
|
public function addTrackingForOrder(string $order_id, array $data) |
154
|
|
|
{ |
155
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/track"; |
156
|
|
|
|
157
|
|
|
$this->options['json'] = $data; |
158
|
|
|
|
159
|
|
|
$this->verb = 'post'; |
160
|
|
|
|
161
|
|
|
return $this->doPayPalRequest(); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|