Skip to content

Commit

Permalink
add TokenHandling to onBoarding-Class
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Jan 1, 2023
1 parent 51540f6 commit 625ff36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ public function setTokenResponse($tokenResponse)
/**
* use this if you want to store the auth response for later reuse
* see also setTokenResponse
* @return array the token response from the auth call
* @return string|null the token response from the auth call
*/
public function getTokenResponse()
{
if (!$this->tokenResponse) {
if (is_null($this->tokenResponse)) {
$tokenResponse = file_get_contents($this->tokenCacheFilename);
if ($tokenResponse) {
$this->tokenResponse = $tokenResponse;
Expand Down
21 changes: 12 additions & 9 deletions src/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ class Onboarding extends Client
* so you initialize the client with the technical oxid account credentials
* Onboarding constructor.
* @param LoggerInterface $logger
* @param $endpoint string the base API url
* @param $oxidClientId string the client id from the technical oxid account
* @param $oxidClientSecret string the client secret from the technical oxid account
* @param $oxidPartnerId string for getting credentials and informations for successful onboarding
* @param $sellerId string for getting informations for successful onboarding
* @param bool $debug set to true to debug request sent to paypal on the console
* @param string $endpoint the base API url
* @param string $oxidClientId the client id from the technical oxid account
* @param string $oxidClientSecret the client secret from the technical oxid account
* @param string $oxidPartnerId for getting credentials and information for successful onboarding
* @param string $sellerId for getting information for successful onboarding
* @param string $tokenCacheFilename the filename for the cached token
* @param bool $debug set to true to debug request sent to PayPal on the console
*/
public function __construct(
LoggerInterface $logger,
Expand All @@ -40,14 +41,14 @@ public function __construct(
$oxidClientSecret,
$oxidPartnerId,
$sellerId,
$tokenCacheFilename,
$debug = false
) {
$this->partnerId = $oxidPartnerId;
$this->sellerId = $sellerId;
parent::__construct($logger, $endpoint, $oxidClientId, $oxidClientSecret, '', $debug);
parent::__construct($logger, $endpoint, $oxidClientId, $oxidClientSecret, $tokenCacheFilename, '', $debug);
}


/**
* Auth after seller used on browser to login into the paypal account
* the parameters are usually provided in a callback on client side e.g.:
Expand Down Expand Up @@ -80,7 +81,9 @@ public function authAfterWebLogin($authCode, $sharedId, $sellerNonce)
]
]);

$this->tokenResponse = json_decode('' . $res->getBody(), true);
$rawTokenResponse = json_decode('' . $res->getBody(), true);

$this->setTokenResponse($rawTokenResponse['access_token']);
}

public function getCredentials()
Expand Down

0 comments on commit 625ff36

Please sign in to comment.