1 | <?php |
||
11 | trait PayPalRequest |
||
12 | { |
||
13 | /** |
||
14 | * Http Client class object. |
||
15 | * |
||
16 | * @var HttpClient |
||
17 | */ |
||
18 | private $client; |
||
19 | |||
20 | /** |
||
21 | * PayPal API mode to be used. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $mode; |
||
26 | |||
27 | /** |
||
28 | * Request data to be sent to PayPal. |
||
29 | * |
||
30 | * @var \Illuminate\Support\Collection |
||
31 | */ |
||
32 | protected $post; |
||
33 | |||
34 | /** |
||
35 | * PayPal API configuration. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | private $config; |
||
40 | |||
41 | /** |
||
42 | * Default currency for PayPal. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $currency; |
||
47 | |||
48 | /** |
||
49 | * Additional options for PayPal API request. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | private $options; |
||
54 | |||
55 | /** |
||
56 | * Default payment action for PayPal. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | private $paymentAction; |
||
61 | |||
62 | /** |
||
63 | * Default locale for PayPal. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | private $locale; |
||
68 | |||
69 | /** |
||
70 | * PayPal API Endpoint. |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | private $apiUrl; |
||
75 | |||
76 | /** |
||
77 | * IPN notification url for PayPal. |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | private $notifyUrl; |
||
82 | |||
83 | /** |
||
84 | * Http Client request body parameter name. |
||
85 | * |
||
86 | * @var string |
||
87 | */ |
||
88 | private $httpBodyParam; |
||
89 | |||
90 | /** |
||
91 | * Validate SSL details when creating HTTP client. |
||
92 | * |
||
93 | * @var bool |
||
94 | */ |
||
95 | private $validateSSL; |
||
96 | |||
97 | /** |
||
98 | * Function To Set PayPal API Configuration. |
||
99 | * |
||
100 | * @param array $config |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | private function setConfig(array $config = []) |
||
117 | |||
118 | /** |
||
119 | * Function to initialize Http Client. |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | protected function setClient() |
||
132 | |||
133 | /** |
||
134 | * Set PayPal API Credentials. |
||
135 | * |
||
136 | * @param array $credentials |
||
137 | * |
||
138 | * @throws \Exception |
||
139 | * |
||
140 | * @return void |
||
141 | */ |
||
142 | public function setApiCredentials($credentials) |
||
168 | |||
169 | /** |
||
170 | * Set API environment to be used by PayPal. |
||
171 | * |
||
172 | * @param array $credentials |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | private function setApiEnvironment($credentials) |
||
184 | |||
185 | /** |
||
186 | * Set configuration details for the provider. |
||
187 | * |
||
188 | * @param array $credentials |
||
189 | * |
||
190 | * @throws \Exception |
||
191 | * |
||
192 | * @return void |
||
193 | */ |
||
194 | private function setApiProviderConfiguration($credentials) |
||
215 | |||
216 | /** |
||
217 | * Setup request data to be sent to PayPal. |
||
218 | * |
||
219 | * @param array $data |
||
220 | * |
||
221 | * @return \Illuminate\Support\Collection |
||
222 | */ |
||
223 | protected function setRequestData(array $data = []) |
||
233 | |||
234 | /** |
||
235 | * Set other/override PayPal API parameters. |
||
236 | * |
||
237 | * @param array $options |
||
238 | * |
||
239 | * @return $this |
||
240 | */ |
||
241 | public function addOptions(array $options) |
||
247 | |||
248 | /** |
||
249 | * Function to set currency. |
||
250 | * |
||
251 | * @param string $currency |
||
252 | * |
||
253 | * @throws \Exception |
||
254 | * |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function setCurrency($currency = 'USD') |
||
270 | |||
271 | /** |
||
272 | * Retrieve PayPal IPN Response. |
||
273 | * |
||
274 | * @param array $post |
||
275 | * |
||
276 | * @return array |
||
277 | */ |
||
278 | public function verifyIPN($post) |
||
286 | |||
287 | /** |
||
288 | * Create request payload to be sent to PayPal. |
||
289 | * |
||
290 | * @param string $method |
||
291 | */ |
||
292 | private function createRequestPayload($method) |
||
307 | |||
308 | /** |
||
309 | * Perform PayPal API request & return response. |
||
310 | * |
||
311 | * @throws \Exception |
||
312 | * |
||
313 | * @return \Psr\Http\Message\StreamInterface |
||
314 | */ |
||
315 | private function makeHttpRequest() |
||
329 | |||
330 | /** |
||
331 | * Function To Perform PayPal API Request. |
||
332 | * |
||
333 | * @param string $method |
||
334 | * |
||
335 | * @throws \Exception |
||
336 | * |
||
337 | * @return array|\Psr\Http\Message\StreamInterface |
||
338 | */ |
||
339 | private function doPayPalRequest($method) |
||
358 | |||
359 | /** |
||
360 | * Parse PayPal NVP Response. |
||
361 | * |
||
362 | * @param string $method |
||
363 | * @param array|\Psr\Http\Message\StreamInterface $response |
||
364 | * |
||
365 | * @return array |
||
366 | */ |
||
367 | private function retrieveData($method, $response) |
||
377 | } |
||
378 |