romeritoCL /
paypal-playground
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Service\Paypal; |
||||
| 4 | |||||
| 5 | use Exception; |
||||
| 6 | use PayPal\Api\OpenIdUserinfo; |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * Class VaultService.php |
||||
| 10 | * @package App\Service\Paypal |
||||
| 11 | */ |
||||
| 12 | class VaultService extends IdentityService |
||||
| 13 | { |
||||
| 14 | /** |
||||
| 15 | * @param string $clientId |
||||
| 16 | * @return string | null |
||||
| 17 | */ |
||||
| 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'; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||||
| 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); |
||||
|
0 ignored issues
–
show
It seems like
$result can also be of type true; however, parameter $json of json_decode() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 40 | |||||
| 41 | if (array_key_exists('id_token', $result)) { |
||||
| 42 | return $result['id_token']; |
||||
| 43 | } |
||||
| 44 | return null; |
||||
| 45 | } |
||||
| 46 | } |
||||
| 47 |