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 | * Function To Set PayPal API Configuration. |
||
92 | * |
||
93 | * @param array $config |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | private function setConfig(array $config = []) |
||
113 | |||
114 | /** |
||
115 | * Function to initialize Http Client. |
||
116 | * |
||
117 | * @return HttpClient |
||
118 | */ |
||
119 | protected function setClient() |
||
128 | |||
129 | /** |
||
130 | * Set PayPal API Credentials. |
||
131 | * |
||
132 | * @param array $credentials |
||
133 | * |
||
134 | * @throws \Exception |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | public function setApiCredentials($credentials) |
||
161 | |||
162 | /** |
||
163 | * Set API environment to be used by PayPal. |
||
164 | * |
||
165 | * @param array $credentials |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | private function setApiEnvironment($credentials) |
||
177 | |||
178 | /** |
||
179 | * Set configuration details for the provider. |
||
180 | * |
||
181 | * @param array $credentials |
||
182 | * |
||
183 | * @throws \Exception |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | private function setApiProviderConfiguration($credentials) |
||
206 | |||
207 | /** |
||
208 | * Setup request data to be sent to PayPal. |
||
209 | * |
||
210 | * @param array $data |
||
211 | * |
||
212 | * @return \Illuminate\Support\Collection |
||
213 | */ |
||
214 | protected function setRequestData(array $data = []) |
||
224 | |||
225 | /** |
||
226 | * Set other/override PayPal API parameters. |
||
227 | * |
||
228 | * @param array $options |
||
229 | * |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function addOptions(array $options) |
||
238 | |||
239 | /** |
||
240 | * Function to set currency. |
||
241 | * |
||
242 | * @param string $currency |
||
243 | * |
||
244 | * @throws \Exception |
||
245 | * |
||
246 | * @return $this |
||
247 | */ |
||
248 | public function setCurrency($currency = 'USD') |
||
261 | |||
262 | /** |
||
263 | * Retrieve PayPal IPN Response. |
||
264 | * |
||
265 | * @param array $post |
||
266 | * |
||
267 | * @return array |
||
268 | */ |
||
269 | public function verifyIPN($post) |
||
277 | |||
278 | /** |
||
279 | * Create request payload to be sent to PayPal. |
||
280 | * |
||
281 | * @param string $method |
||
282 | */ |
||
283 | private function createRequestPayload($method) |
||
298 | |||
299 | /** |
||
300 | * Perform PayPal API request & return response. |
||
301 | * |
||
302 | * @throws \Exception |
||
303 | * |
||
304 | * @return \Psr\Http\Message\StreamInterface |
||
305 | */ |
||
306 | private function makeHttpRequest() |
||
320 | |||
321 | /** |
||
322 | * Function To Perform PayPal API Request. |
||
323 | * |
||
324 | * @param string $method |
||
325 | * |
||
326 | * @throws \Exception |
||
327 | * |
||
328 | * @return array|\Psr\Http\Message\StreamInterface |
||
329 | */ |
||
330 | private function doPayPalRequest($method) |
||
349 | |||
350 | /** |
||
351 | * Parse PayPal NVP Response. |
||
352 | * |
||
353 | * @param string $method |
||
354 | * @param array|\Psr\Http\Message\StreamInterface $response |
||
355 | * |
||
356 | * @return array |
||
357 | */ |
||
358 | private function retrieveData($method, $response) |
||
368 | } |
||
369 |