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 | * Default currency for PayPal. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | private $currency; |
||
59 | |||
60 | /** |
||
61 | * Additional options for PayPal API request. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | private $options; |
||
66 | |||
67 | /** |
||
68 | * Default payment action for PayPal. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | private $paymentAction; |
||
73 | |||
74 | /** |
||
75 | * Default locale for PayPal. |
||
76 | * |
||
77 | * @var string |
||
78 | */ |
||
79 | private $locale; |
||
80 | |||
81 | /** |
||
82 | * PayPal API Endpoint. |
||
83 | * |
||
84 | * @var string |
||
85 | */ |
||
86 | private $apiUrl; |
||
87 | |||
88 | /** |
||
89 | * IPN notification url for PayPal. |
||
90 | * |
||
91 | * @var string |
||
92 | */ |
||
93 | private $notifyUrl; |
||
94 | |||
95 | /** |
||
96 | * Http Client request body parameter name. |
||
97 | * |
||
98 | * @var string |
||
99 | */ |
||
100 | private $httpBodyParam; |
||
101 | |||
102 | /** |
||
103 | * Validate SSL details when creating HTTP client. |
||
104 | * |
||
105 | * @var bool |
||
106 | */ |
||
107 | private $validateSSL; |
||
108 | |||
109 | /** |
||
110 | * Function To Set PayPal API Configuration. |
||
111 | * |
||
112 | * @param array $config |
||
113 | * |
||
114 | * @throws \Exception |
||
115 | */ |
||
116 | private function setConfig(array $config = []) |
||
129 | |||
130 | /** |
||
131 | * Set default values for configuration. |
||
132 | * |
||
133 | * @return void |
||
134 | */ |
||
135 | private function setDefaultValues() |
||
152 | |||
153 | /** |
||
154 | * Set PayPal API Credentials. |
||
155 | * |
||
156 | * @param array $credentials |
||
157 | * |
||
158 | * @throws \Exception |
||
159 | * |
||
160 | * @return void |
||
161 | */ |
||
162 | public function setApiCredentials($credentials) |
||
176 | |||
177 | /** |
||
178 | * Set API environment to be used by PayPal. |
||
179 | * |
||
180 | * @param array $credentials |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | private function setApiEnvironment($credentials) |
||
192 | |||
193 | /** |
||
194 | * Set configuration details for the provider. |
||
195 | * |
||
196 | * @param array $credentials |
||
197 | * |
||
198 | * @throws \Exception |
||
199 | * |
||
200 | * @return void |
||
201 | */ |
||
202 | private function setApiProviderConfiguration($credentials) |
||
223 | |||
224 | /** |
||
225 | * Determines which API provider should be used. |
||
226 | * |
||
227 | * @param array $credentials |
||
228 | * |
||
229 | * @throws \Exception |
||
230 | */ |
||
231 | private function setApiProvider($credentials) |
||
241 | |||
242 | /** |
||
243 | * Setup request data to be sent to PayPal. |
||
244 | * |
||
245 | * @param array $data |
||
246 | * |
||
247 | * @return \Illuminate\Support\Collection |
||
248 | */ |
||
249 | protected function setRequestData(array $data = []) |
||
259 | |||
260 | /** |
||
261 | * Set other/override PayPal API parameters. |
||
262 | * |
||
263 | * @param array $options |
||
264 | * |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function addOptions(array $options) |
||
273 | |||
274 | /** |
||
275 | * Function to set currency. |
||
276 | * |
||
277 | * @param string $currency |
||
278 | * |
||
279 | * @throws \Exception |
||
280 | * |
||
281 | * @return $this |
||
282 | */ |
||
283 | public function setCurrency($currency = 'USD') |
||
296 | |||
297 | /** |
||
298 | * Retrieve PayPal IPN Response. |
||
299 | * |
||
300 | * @param array $post |
||
301 | * |
||
302 | * @return array |
||
303 | */ |
||
304 | public function verifyIPN($post) |
||
312 | |||
313 | /** |
||
314 | * Create request payload to be sent to PayPal. |
||
315 | * |
||
316 | * @param string $method |
||
317 | */ |
||
318 | private function createRequestPayload($method) |
||
333 | |||
334 | /** |
||
335 | * Parse PayPal NVP Response. |
||
336 | * |
||
337 | * @param string $method |
||
338 | * @param array|\Psr\Http\Message\StreamInterface $response |
||
339 | * |
||
340 | * @return array |
||
341 | */ |
||
342 | private function retrieveData($method, $response) |
||
352 | } |
||
353 |