* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 */ namespace PrestaShop\Module\PrestashopCheckout\PayPal\OAuth; use Exception; use PrestaShop\Module\PrestashopCheckout\Http\CheckoutHttpClient; use PrestaShop\Module\PrestashopCheckout\PayPal\Customer\ValueObject\PayPalCustomerId; class OAuthService { private $httpClient; public function __construct(CheckoutHttpClient $httpClient) { $this->httpClient = $httpClient; } /** * @param PayPalCustomerId|null $customerId * * @return string * * @throws Exception */ public function getUserIdToken($merchantId, PayPalCustomerId $customerId = null) { try { $response = $this->httpClient->getUserIdToken($merchantId, $customerId); $data = json_decode($response->getBody(), true); if (empty($data['id_token'])) { throw new Exception('Failed to get PayPal User ID token from response.'); } return $data['id_token']; } catch (Exception $exception) { throw new Exception('Failed to get PayPal User ID token.', 0, $exception); } } }