1 | <?php |
||
7 | trait PayPalRequest |
||
8 | { |
||
9 | use PayPalHttpClient; |
||
10 | |||
11 | /** |
||
12 | * Http Client class object. |
||
13 | * |
||
14 | * @var HttpClient |
||
15 | */ |
||
16 | private $client; |
||
17 | |||
18 | /** |
||
19 | * Http Client configuration. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $httpClientConfig; |
||
24 | |||
25 | /** |
||
26 | * PayPal API Certificate data for authentication. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $certificate; |
||
31 | |||
32 | /** |
||
33 | * PayPal API mode to be used. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $mode; |
||
38 | |||
39 | /** |
||
40 | * Request data to be sent to PayPal. |
||
41 | * |
||
42 | * @var \Illuminate\Support\Collection |
||
43 | */ |
||
44 | protected $post; |
||
45 | |||
46 | /** |
||
47 | * PayPal API configuration. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | private $config; |
||
52 | |||
53 | /** |
||
54 | * Item subtotal. |
||
55 | * |
||
56 | * @var float |
||
57 | */ |
||
58 | private $subtotal; |
||
59 | |||
60 | /** |
||
61 | * Default currency for PayPal. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | private $currency; |
||
66 | |||
67 | /** |
||
68 | * Defaut billing type for PayPal reference transactions |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | private $billingType; |
||
73 | |||
74 | /** |
||
75 | * Additional options for PayPal API request. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | private $options; |
||
80 | |||
81 | /** |
||
82 | * Default payment action for PayPal. |
||
83 | * |
||
84 | * @var string |
||
85 | */ |
||
86 | private $paymentAction; |
||
87 | |||
88 | /** |
||
89 | * Default locale for PayPal. |
||
90 | * |
||
91 | * @var string |
||
92 | */ |
||
93 | private $locale; |
||
94 | |||
95 | /** |
||
96 | * PayPal API Endpoint. |
||
97 | * |
||
98 | * @var string |
||
99 | */ |
||
100 | private $apiUrl; |
||
101 | |||
102 | /** |
||
103 | * IPN notification url for PayPal. |
||
104 | * |
||
105 | * @var string |
||
106 | */ |
||
107 | private $notifyUrl; |
||
108 | |||
109 | /** |
||
110 | * Http Client request body parameter name. |
||
111 | * |
||
112 | * @var string |
||
113 | */ |
||
114 | private $httpBodyParam; |
||
115 | |||
116 | /** |
||
117 | * Validate SSL details when creating HTTP client. |
||
118 | * |
||
119 | * @var bool |
||
120 | */ |
||
121 | private $validateSSL; |
||
122 | |||
123 | /** |
||
124 | * Function To Set PayPal API Configuration. |
||
125 | * |
||
126 | * @param array $config |
||
127 | * |
||
128 | * @throws \Exception |
||
129 | */ |
||
130 | private function setConfig(array $config = []) |
||
143 | |||
144 | /** |
||
145 | * Set default values for configuration. |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | private function setDefaultValues() |
||
166 | |||
167 | /** |
||
168 | * Set PayPal API Credentials. |
||
169 | * |
||
170 | * @param array $credentials |
||
171 | * |
||
172 | * @throws \Exception |
||
173 | * |
||
174 | * @return void |
||
175 | */ |
||
176 | public function setApiCredentials($credentials) |
||
193 | |||
194 | /** |
||
195 | * Set API environment to be used by PayPal. |
||
196 | * |
||
197 | * @param array $credentials |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | private function setApiEnvironment($credentials) |
||
209 | |||
210 | /** |
||
211 | * Set configuration details for the provider. |
||
212 | * |
||
213 | * @param array $credentials |
||
214 | * |
||
215 | * @throws \Exception |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | private function setApiProviderConfiguration($credentials) |
||
240 | |||
241 | /** |
||
242 | * Determines which API provider should be used. |
||
243 | * |
||
244 | * @param array $credentials |
||
245 | * |
||
246 | * @throws \Exception |
||
247 | */ |
||
248 | private function setApiProvider($credentials) |
||
258 | |||
259 | /** |
||
260 | * Setup request data to be sent to PayPal. |
||
261 | * |
||
262 | * @param array $data |
||
263 | * |
||
264 | * @return \Illuminate\Support\Collection |
||
265 | */ |
||
266 | protected function setRequestData(array $data = []) |
||
276 | |||
277 | /** |
||
278 | * Set other/override PayPal API parameters. |
||
279 | * |
||
280 | * @param array $options |
||
281 | * |
||
282 | * @return $this |
||
283 | */ |
||
284 | public function addOptions(array $options) |
||
290 | |||
291 | /** |
||
292 | * Function to set currency. |
||
293 | * |
||
294 | * @param string $currency |
||
295 | * |
||
296 | * @throws \Exception |
||
297 | * |
||
298 | * @return $this |
||
299 | */ |
||
300 | public function setCurrency($currency = 'USD') |
||
313 | |||
314 | /** |
||
315 | * Function to set billing type. |
||
316 | * |
||
317 | * @param string $billingType |
||
318 | * |
||
319 | * @throws \Exception |
||
320 | * |
||
321 | * @return $this |
||
322 | */ |
||
323 | public function setBillingType($billingType = 'MerchantInitiatedBilling') |
||
335 | |||
336 | /** |
||
337 | * Retrieve PayPal IPN Response. |
||
338 | * |
||
339 | * @param array $post |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | public function verifyIPN($post) |
||
351 | |||
352 | /** |
||
353 | * Create request payload to be sent to PayPal. |
||
354 | * |
||
355 | * @param string $method |
||
356 | */ |
||
357 | private function createRequestPayload($method) |
||
372 | |||
373 | /** |
||
374 | * Parse PayPal NVP Response. |
||
375 | * |
||
376 | * @param string $method |
||
377 | * @param array|\Psr\Http\Message\StreamInterface $response |
||
378 | * |
||
379 | * @return array |
||
380 | */ |
||
381 | private function retrieveData($method, $response) |
||
391 | } |
||
392 |