-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License version 3.0 | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @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\Customer; | ||
|
||
use Db; | ||
use DbQuery; | ||
use Exception; | ||
use PrestaShop\Module\PrestashopCheckout\Customer\ValueObject\CustomerId; | ||
use PrestaShop\Module\PrestashopCheckout\PayPal\Customer\ValueObject\PayPalCustomerId; | ||
|
||
class PayPalCustomerRepository | ||
{ | ||
/** | ||
* @var Db | ||
*/ | ||
private $db; | ||
|
||
/** | ||
* @param Db $db | ||
*/ | ||
public function __construct(Db $db) | ||
{ | ||
$this->db = $db; | ||
} | ||
|
||
/** | ||
* @param CustomerId $customerId | ||
* | ||
* @return PayPalCustomerId|null | ||
* | ||
* @throws Exception | ||
*/ | ||
public function findPayPalCustomerIdByCustomerId(CustomerId $customerId) | ||
Check failure on line 51 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 51 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
try { | ||
$query = new DbQuery(); | ||
$query->select('`paypal_customer_id`'); | ||
$query->from('pscheckout_customer'); | ||
$query->where('`id_customer` = ' . (int) $customerId->getValue()); | ||
$customerIdPayPal = $this->db->getValue($query); | ||
|
||
return $customerIdPayPal ? new PayPalCustomerId($customerIdPayPal) : null; | ||
Check failure on line 60 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (8.0.0)
|
||
} catch (Exception $exception) { | ||
throw new Exception('Failed to find PayPal Customer ID', 0, $exception); | ||
} | ||
} | ||
|
||
/** | ||
* @param CustomerId $customerId | ||
* @param PayPalCustomerId $paypalCustomerId | ||
* | ||
* @return void | ||
* | ||
* @throws Exception | ||
*/ | ||
public function save(CustomerId $customerId, PayPalCustomerId $paypalCustomerId) | ||
Check failure on line 74 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 74 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 74 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (latest)
Check failure on line 74 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
try { | ||
$this->db->insert( | ||
'pscheckout_customer', | ||
[ | ||
'id_customer' => (int) $customerId->getValue(), | ||
'paypal_customer_id' => pSQL($paypalCustomerId->getValue()), | ||
Check failure on line 81 in src/PayPal/Customer/PayPalCustomerRepository.php GitHub Actions / PHPStan (8.0.0)
|
||
] | ||
); | ||
} catch (Exception $exception) { | ||
throw new Exception('Failed to save PayPal Customer ID', 0, $exception); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License version 3.0 | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @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 GuzzleHttp\Psr7\Request; | ||
use PrestaShop\Module\PrestashopCheckout\PayPal\Customer\ValueObject\PayPalCustomerId; | ||
|
||
class OAuthService | ||
{ | ||
private $httpClient; | ||
|
||
public function __construct($httpClient) | ||
{ | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
/** | ||
* @param PayPalCustomerId|null $customerId | ||
* | ||
* @return string | ||
* | ||
* @throws Exception | ||
*/ | ||
public function getUserIdToken(PayPalCustomerId $customerId = null) | ||
Check failure on line 43 in src/PayPal/OAuth/OAuthService.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 43 in src/PayPal/OAuth/OAuthService.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 43 in src/PayPal/OAuth/OAuthService.php GitHub Actions / PHPStan (latest)
Check failure on line 43 in src/PayPal/OAuth/OAuthService.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
try { | ||
$body = 'grant_type=client_credentials&response_type=id_token'; | ||
|
||
if ($customerId) { | ||
$body .= '&target_customer_id=' . $customerId->getValue(); | ||
Check failure on line 49 in src/PayPal/OAuth/OAuthService.php GitHub Actions / PHPStan (8.0.0)
|
||
} | ||
|
||
$request = new Request('POST', '', [], $body); | ||
$response = $this->httpClient->sendRequest($request); | ||
|
||
$data = json_decode($response->getBody()->getContents(), 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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License version 3.0 | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @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\Query; | ||
|
||
use PrestaShop\Module\PrestashopCheckout\Customer\ValueObject\CustomerId; | ||
|
||
class GetPayPalGetUserIdTokenQuery | ||
{ | ||
/** | ||
* @var CustomerId|null | ||
*/ | ||
private $customerId; | ||
|
||
/** | ||
* @param CustomerId|null $customerId | ||
*/ | ||
public function __construct(CustomerId $customerId = null) | ||
{ | ||
$this->customerId = $customerId; | ||
} | ||
|
||
/** | ||
* @return CustomerId|null | ||
*/ | ||
public function getCustomerId() | ||
{ | ||
return $this->customerId; | ||
} | ||
} |