1 | <?php |
||
9 | class ExpressCheckout |
||
10 | { |
||
11 | // Integrate PayPal Request trait |
||
12 | use PayPalAPIRequest, RecurringProfiles; |
||
13 | |||
14 | /** |
||
15 | * PayPal Processor Constructor. |
||
16 | * |
||
17 | * @param array $config |
||
18 | */ |
||
19 | public function __construct(array $config = []) |
||
28 | |||
29 | /** |
||
30 | * Set Http Client request body param. Should only be called when Guzzle version 5 is used. |
||
31 | */ |
||
32 | public function setPreviousHttpBodyParam() |
||
36 | |||
37 | /** |
||
38 | * Set ExpressCheckout API endpoints & options. |
||
39 | * |
||
40 | * @param array $credentials |
||
41 | * |
||
42 | * @return void |
||
43 | */ |
||
44 | public function setExpressCheckoutOptions($credentials) |
||
64 | |||
65 | /** |
||
66 | * Set cart item details for PayPal. |
||
67 | * |
||
68 | * @param array $items |
||
69 | * |
||
70 | * @return \Illuminate\Support\Collection |
||
71 | */ |
||
72 | protected function setCartItems($items) |
||
73 | { |
||
74 | return (new Collection($items))->map(function ($item, $num) { |
||
75 | return [ |
||
76 | 'L_PAYMENTREQUEST_0_NAME'.$num => $item['name'], |
||
77 | 'L_PAYMENTREQUEST_0_AMT'.$num => $item['price'], |
||
78 | 'L_PAYMENTREQUEST_0_QTY'.$num => isset($item['qty']) ? $item['qty'] : 1, |
||
79 | ]; |
||
80 | })->flatMap(function ($value) { |
||
81 | return $value; |
||
82 | }); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Set Recurring payments details for SetExpressCheckout API call. |
||
87 | * |
||
88 | * @param array $data |
||
89 | * @param bool $subscription |
||
90 | */ |
||
91 | protected function setExpressCheckoutRecurringPaymentConfig($data, $subscription = false) |
||
99 | |||
100 | /** |
||
101 | * Function to perform SetExpressCheckout PayPal API operation. |
||
102 | * |
||
103 | * @param array $data |
||
104 | * @param bool $subscription |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | public function setExpressCheckout($data, $subscription = false) |
||
133 | |||
134 | /** |
||
135 | * Function to perform GetExpressCheckoutDetails PayPal API operation. |
||
136 | * |
||
137 | * @param string $token |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function getExpressCheckoutDetails($token) |
||
149 | |||
150 | /** |
||
151 | * Function to perform DoExpressCheckoutPayment PayPal API operation. |
||
152 | * |
||
153 | * @param array $data |
||
154 | * @param string $token |
||
155 | * @param string $payerid |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | public function doExpressCheckoutPayment($data, $token, $payerid) |
||
175 | |||
176 | /** |
||
177 | * Function to perform DoCapture PayPal API operation. |
||
178 | * |
||
179 | * @param string $authorization_id Transaction ID |
||
180 | * @param float $amount Amount to capture |
||
181 | * @param string $complete Indicates whether or not this is the last capture. |
||
182 | * @param array $data Optional request fields |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | public function doCapture($authorization_id, $amount, $complete = 'Complete', $data = []) |
||
199 | |||
200 | /** |
||
201 | * Function to perform DoAuthorization PayPal API operation. |
||
202 | * |
||
203 | * @param string $authorization_id Transaction ID |
||
204 | * @param float $amount Amount to capture |
||
205 | * @param array $data Optional request fields |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | public function doAuthorization($authorization_id, $amount, $data = []) |
||
220 | |||
221 | /** |
||
222 | * Function to perform DoVoid PayPal API operation. |
||
223 | * |
||
224 | * @param string $authorization_id Transaction ID |
||
225 | * @param array $data Optional request fields |
||
226 | * |
||
227 | * @return array |
||
228 | */ |
||
229 | public function doVoid($authorization_id, $data = []) |
||
239 | |||
240 | /** |
||
241 | * Function to perform CreateBillingAgreement PayPal API operation. |
||
242 | * |
||
243 | * @param string $token |
||
244 | * |
||
245 | * @return array |
||
246 | */ |
||
247 | public function createBillingAgreement($token) |
||
255 | |||
256 | /** |
||
257 | * Function to perform CreateRecurringPaymentsProfile PayPal API operation. |
||
258 | * |
||
259 | * @param array $data |
||
260 | * @param string $token |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | public function createRecurringPaymentsProfile($data, $token) |
||
272 | |||
273 | /** |
||
274 | * Function to perform GetRecurringPaymentsProfileDetails PayPal API operation. |
||
275 | * |
||
276 | * @param string $id |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function getRecurringPaymentsProfileDetails($id) |
||
288 | |||
289 | /** |
||
290 | * Function to perform UpdateRecurringPaymentsProfile PayPal API operation. |
||
291 | * |
||
292 | * @param array $data |
||
293 | * @param string $id |
||
294 | * |
||
295 | * @return array |
||
296 | */ |
||
297 | public function updateRecurringPaymentsProfile($data, $id) |
||
305 | |||
306 | /** |
||
307 | * Change Recurring payment profile status on PayPal. |
||
308 | * |
||
309 | * @param string $id |
||
310 | * @param string $status |
||
311 | * |
||
312 | * @return array|\Psr\Http\Message\StreamInterface |
||
313 | */ |
||
314 | protected function manageRecurringPaymentsProfileStatus($id, $status) |
||
323 | |||
324 | /** |
||
325 | * Cancel RecurringPaymentsProfile on PayPal. |
||
326 | * |
||
327 | * @param string $id |
||
328 | * |
||
329 | * @return array |
||
330 | */ |
||
331 | public function cancelRecurringPaymentsProfile($id) |
||
335 | |||
336 | /** |
||
337 | * Suspend an active RecurringPaymentsProfile on PayPal. |
||
338 | * |
||
339 | * @param string $id |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | public function suspendRecurringPaymentsProfile($id) |
||
347 | |||
348 | /** |
||
349 | * Reactivate a suspended RecurringPaymentsProfile on PayPal. |
||
350 | * |
||
351 | * @param string $id |
||
352 | * |
||
353 | * @return array |
||
354 | */ |
||
355 | public function reactivateRecurringPaymentsProfile($id) |
||
359 | } |
||
360 |