| Conditions | 3 |
| Paths | 12 |
| Total Lines | 27 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function getDataUserIdToken(string $clientId) |
||
| 19 | { |
||
| 20 | try { |
||
| 21 | $ch = curl_init(); |
||
| 22 | curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/oauth2/token'); |
||
| 23 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 24 | curl_setopt($ch, CURLOPT_POST, 1); |
||
| 25 | curl_setopt( |
||
| 26 | $ch, |
||
| 27 | CURLOPT_POSTFIELDS, |
||
| 28 | "grant_type=client_credentials&response_type=id_token&target_customer_id=" . $clientId |
||
| 29 | ); |
||
| 30 | curl_setopt($ch, CURLOPT_USERPWD, $this->clientId . ':' . $this->clientSecret); |
||
| 31 | $headers[] = 'Content-Type: application/x-www-form-urlencoded'; |
||
|
|
|||
| 32 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||
| 33 | $result = curl_exec($ch); |
||
| 34 | curl_close($ch); |
||
| 35 | } catch (Exception $e) { |
||
| 36 | $this->logger->error('Error on PayPal::getDataUserIdToken = ' . $e->getMessage()); |
||
| 37 | return null; |
||
| 38 | } |
||
| 39 | $result = json_decode($result, true); |
||
| 40 | |||
| 41 | if (array_key_exists('id_token', $result)) { |
||
| 42 | return $result['id_token']; |
||
| 43 | } |
||
| 44 | return null; |
||
| 45 | } |
||
| 47 |