1 | <?php |
||
11 | trait PayPalRequest |
||
12 | { |
||
13 | /** |
||
14 | * Http Client class object. |
||
15 | * |
||
16 | * @var HttpClient |
||
17 | */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * Request data to be sent to PayPal. |
||
22 | * |
||
23 | * @var \Illuminate\Support\Collection |
||
24 | */ |
||
25 | protected $post; |
||
26 | |||
27 | /** |
||
28 | * PayPal API configuration. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | private $config; |
||
33 | |||
34 | /** |
||
35 | * Default currency for PayPal. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $currency; |
||
40 | |||
41 | /** |
||
42 | * Additional options for PayPal API request. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | private $options; |
||
47 | |||
48 | /** |
||
49 | * Default payment action for PayPal. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | private $paymentAction; |
||
54 | |||
55 | /** |
||
56 | * Default locale for PayPal. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $locale; |
||
61 | |||
62 | /** |
||
63 | * PayPal API Endpoint. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | private $apiUrl; |
||
68 | |||
69 | /** |
||
70 | * IPN notification url for PayPal. |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | private $notifyUrl; |
||
75 | |||
76 | /** |
||
77 | * Http Client request body parameter name. |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | private $httpBodyParam; |
||
82 | |||
83 | /** |
||
84 | * Function To Set PayPal API Configuration. |
||
85 | * |
||
86 | * @param array $config |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | private function setConfig(array $config = []) |
||
109 | |||
110 | /** |
||
111 | * Function to initialize Http Client. |
||
112 | * |
||
113 | * @return HttpClient |
||
114 | */ |
||
115 | protected function setClient() |
||
123 | |||
124 | /** |
||
125 | * Set PayPal API Credentials. |
||
126 | * |
||
127 | * @param array $credentials |
||
128 | * @param string $mode |
||
129 | * |
||
130 | * @throws \Exception |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | public function setApiCredentials($credentials, $mode = '') |
||
185 | |||
186 | /** |
||
187 | * Setup request data to be sent to PayPal. |
||
188 | * |
||
189 | * @param array $data |
||
190 | * |
||
191 | * @return \Illuminate\Support\Collection |
||
192 | */ |
||
193 | protected function setRequestData(array $data = []) |
||
203 | |||
204 | /** |
||
205 | * Set other/override PayPal API parameters. |
||
206 | * |
||
207 | * @param array $options |
||
208 | * |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function addOptions(array $options) |
||
217 | |||
218 | /** |
||
219 | * Function to set currency. |
||
220 | * |
||
221 | * @param string $currency |
||
222 | * |
||
223 | * @throws \Exception |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | public function setCurrency($currency = 'USD') |
||
240 | |||
241 | /** |
||
242 | * Retrieve PayPal IPN Response. |
||
243 | * |
||
244 | * @param array $post |
||
245 | * |
||
246 | * @return array |
||
247 | */ |
||
248 | public function verifyIPN($post) |
||
256 | |||
257 | /** |
||
258 | * Refund PayPal Transaction. |
||
259 | * |
||
260 | * @param string $transaction |
||
261 | * @param float $amount |
||
262 | * |
||
263 | * @return array |
||
264 | */ |
||
265 | public function refundTransaction($transaction, $amount = 0.00) |
||
280 | |||
281 | /** |
||
282 | * Search Transactions On PayPal. |
||
283 | * |
||
284 | * @param array $post |
||
285 | * |
||
286 | * @return array |
||
287 | */ |
||
288 | public function searchTransactions($post) |
||
294 | |||
295 | /** |
||
296 | * Create request payload to be sent to PayPal. |
||
297 | * |
||
298 | * @param string $method |
||
299 | */ |
||
300 | private function createRequestPayload($method) |
||
315 | |||
316 | /** |
||
317 | * Function To Perform PayPal API Request. |
||
318 | * |
||
319 | * @param string $method |
||
320 | * |
||
321 | * @throws \Exception |
||
322 | * |
||
323 | * @return array|\Psr\Http\Message\StreamInterface |
||
324 | */ |
||
325 | private function doPayPalRequest($method) |
||
353 | |||
354 | /** |
||
355 | * Parse PayPal NVP Response. |
||
356 | * |
||
357 | * @param string $request |
||
358 | * @param array $response |
||
359 | * |
||
360 | * @return array |
||
361 | */ |
||
362 | private function retrieveData($request, array $response = null) |
||
368 | } |
||
369 |