1 | <?php |
||
13 | trait PayPalRequest |
||
14 | { |
||
15 | use PayPalHttpClient; |
||
16 | |||
17 | /** |
||
18 | * Http Client class object. |
||
19 | * |
||
20 | * @var HttpClient |
||
21 | */ |
||
22 | private $client; |
||
23 | |||
24 | /** |
||
25 | * Http Client configuration. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $httpClientConfig; |
||
30 | |||
31 | /** |
||
32 | * PayPal API Certificate data for authentication. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $certificate; |
||
37 | |||
38 | /** |
||
39 | * PayPal API mode to be used. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | public $mode; |
||
44 | |||
45 | /** |
||
46 | * Request data to be sent to PayPal. |
||
47 | * |
||
48 | * @var Collection |
||
49 | */ |
||
50 | protected $post; |
||
51 | |||
52 | /** |
||
53 | * PayPal API configuration. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | private $config; |
||
58 | |||
59 | /** |
||
60 | * Item subtotal. |
||
61 | * |
||
62 | * @var float |
||
63 | */ |
||
64 | private $subtotal; |
||
65 | |||
66 | /** |
||
67 | * Default currency for PayPal. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | private $currency; |
||
72 | |||
73 | /** |
||
74 | * Default billing type for PayPal reference transactions. |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | private $billingType; |
||
79 | |||
80 | /** |
||
81 | * Additional options for PayPal API request. |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | private $options; |
||
86 | |||
87 | /** |
||
88 | * Default payment action for PayPal. |
||
89 | * |
||
90 | * @var string |
||
91 | */ |
||
92 | private $paymentAction; |
||
93 | |||
94 | /** |
||
95 | * Default locale for PayPal. |
||
96 | * |
||
97 | * @var string |
||
98 | */ |
||
99 | private $locale; |
||
100 | |||
101 | /** |
||
102 | * PayPal API Endpoint. |
||
103 | * |
||
104 | * @var string |
||
105 | */ |
||
106 | private $apiUrl; |
||
107 | |||
108 | /** |
||
109 | * IPN notification url for PayPal. |
||
110 | * |
||
111 | * @var string |
||
112 | */ |
||
113 | private $notifyUrl; |
||
114 | |||
115 | /** |
||
116 | * Http Client request body parameter name. |
||
117 | * |
||
118 | * @var string |
||
119 | */ |
||
120 | private $httpBodyParam; |
||
121 | |||
122 | /** |
||
123 | * Validate SSL details when creating HTTP client. |
||
124 | * |
||
125 | * @var bool |
||
126 | */ |
||
127 | private $validateSSL; |
||
128 | |||
129 | /** |
||
130 | * Fraudnet Header Id. |
||
131 | * |
||
132 | * @var string |
||
133 | */ |
||
134 | private $fraudnetId; |
||
135 | |||
136 | /** |
||
137 | * Set PayPal API Credentials. |
||
138 | * |
||
139 | * @param array $credentials |
||
140 | * |
||
141 | * @throws Exception |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | public function setApiCredentials($credentials) |
||
162 | |||
163 | /** |
||
164 | * Set other/override PayPal API parameters. |
||
165 | * |
||
166 | * @param array $options |
||
167 | * |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function addOptions(array $options) |
||
176 | |||
177 | /** |
||
178 | * Function to set currency. |
||
179 | * |
||
180 | * @param string $currency |
||
181 | * |
||
182 | * @throws Exception |
||
183 | * |
||
184 | * @return $this |
||
185 | */ |
||
186 | public function setCurrency($currency = 'USD') |
||
199 | |||
200 | /** |
||
201 | * Function to set billing type. |
||
202 | * |
||
203 | * @param string $billingType |
||
204 | * |
||
205 | * @throws Exception |
||
206 | * |
||
207 | * @return $this |
||
208 | */ |
||
209 | public function setBillingType($billingType = 'MerchantInitiatedBilling') |
||
221 | |||
222 | /** |
||
223 | * Retrieve PayPal IPN Response. |
||
224 | * |
||
225 | * @param array $post |
||
226 | * |
||
227 | * @throws Exception |
||
228 | * |
||
229 | * @return array |
||
230 | */ |
||
231 | public function verifyIPN($post) |
||
239 | |||
240 | /** |
||
241 | * Function to set fraudnet id. |
||
242 | * |
||
243 | * @param string $fraudnetId |
||
244 | * |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function setFraudnetId($fraudnetId) |
||
252 | |||
253 | /** |
||
254 | * Setup request data to be sent to PayPal. |
||
255 | * |
||
256 | * @param array $data |
||
257 | * |
||
258 | * @return Collection |
||
259 | */ |
||
260 | protected function setRequestData(array $data = []) |
||
270 | |||
271 | /** |
||
272 | * Function To Set PayPal API Configuration. |
||
273 | * |
||
274 | * @param array $config |
||
275 | * |
||
276 | * @throws Exception |
||
277 | */ |
||
278 | private function setConfig(array $config = []) |
||
291 | |||
292 | /** |
||
293 | * Set default values for configuration. |
||
294 | * |
||
295 | * @return void |
||
296 | */ |
||
297 | private function setDefaultValues() |
||
314 | |||
315 | /** |
||
316 | * Set API environment to be used by PayPal. |
||
317 | * |
||
318 | * @param array $credentials |
||
319 | * |
||
320 | * @return void |
||
321 | */ |
||
322 | private function setApiEnvironment($credentials) |
||
330 | |||
331 | /** |
||
332 | * Set configuration details for the provider. |
||
333 | * |
||
334 | * @param array $credentials |
||
335 | * |
||
336 | * @throws Exception |
||
337 | * |
||
338 | * @return void |
||
339 | */ |
||
340 | private function setApiProviderConfiguration($credentials) |
||
361 | |||
362 | /** |
||
363 | * Determines which API provider should be used. |
||
364 | * |
||
365 | * @param array $credentials |
||
366 | * |
||
367 | * @throws Exception |
||
368 | */ |
||
369 | private function setApiProvider($credentials) |
||
381 | |||
382 | /** |
||
383 | * Create request payload to be sent to PayPal. |
||
384 | * |
||
385 | * @param string $method |
||
386 | */ |
||
387 | private function createRequestPayload($method) |
||
402 | |||
403 | /** |
||
404 | * Parse PayPal NVP Response. |
||
405 | * |
||
406 | * @param string $method |
||
407 | * @param array|StreamInterface $response |
||
408 | * |
||
409 | * @return array |
||
410 | */ |
||
411 | private function retrieveData($method, $response) |
||
421 | } |
||
422 |