mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
🎨 Minor code formatting
This commit is contained in:
parent
faff0baa43
commit
290aed8ad8
2 changed files with 20 additions and 20 deletions
|
@ -5,7 +5,7 @@
|
||||||
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
|
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare( strict_types = 1 );
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
|
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
|
||||||
|
|
||||||
|
@ -70,12 +70,11 @@ class PayPalBearer implements Bearer {
|
||||||
/**
|
/**
|
||||||
* PayPalBearer constructor.
|
* PayPalBearer constructor.
|
||||||
*
|
*
|
||||||
* @param Cache $cache The cache.
|
* @param Cache $cache The cache.
|
||||||
* @param string $host The host.
|
* @param string $host The host.
|
||||||
* @param string $key The key.
|
* @param string $key The key.
|
||||||
* @param string $secret The secret.
|
* @param string $secret The secret.
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
* @param ContainerInterface $settings The settings.
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Cache $cache,
|
Cache $cache,
|
||||||
|
@ -97,12 +96,13 @@ class PayPalBearer implements Bearer {
|
||||||
/**
|
/**
|
||||||
* Returns a bearer token.
|
* Returns a bearer token.
|
||||||
*
|
*
|
||||||
* @return Token
|
|
||||||
* @throws RuntimeException When request fails.
|
* @throws RuntimeException When request fails.
|
||||||
|
* @return Token
|
||||||
*/
|
*/
|
||||||
public function bearer(): Token {
|
public function bearer() : Token {
|
||||||
try {
|
try {
|
||||||
$bearer = Token::from_json( (string) $this->cache->get( self::CACHE_KEY ) );
|
$bearer = Token::from_json( (string) $this->cache->get( self::CACHE_KEY ) );
|
||||||
|
|
||||||
return ( $bearer->is_valid() ) ? $bearer : $this->newBearer();
|
return ( $bearer->is_valid() ) ? $bearer : $this->newBearer();
|
||||||
} catch ( RuntimeException $error ) {
|
} catch ( RuntimeException $error ) {
|
||||||
return $this->newBearer();
|
return $this->newBearer();
|
||||||
|
@ -112,8 +112,8 @@ class PayPalBearer implements Bearer {
|
||||||
/**
|
/**
|
||||||
* Creates a new bearer token.
|
* Creates a new bearer token.
|
||||||
*
|
*
|
||||||
* @return Token
|
|
||||||
* @throws RuntimeException When request fails.
|
* @throws RuntimeException When request fails.
|
||||||
|
* @return Token
|
||||||
*/
|
*/
|
||||||
private function newBearer(): Token {
|
private function newBearer(): Token {
|
||||||
$key = $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ? $this->settings->get( 'client_id' ) : $this->key;
|
$key = $this->settings->has( 'client_id' ) && $this->settings->get( 'client_id' ) ? $this->settings->get( 'client_id' ) : $this->key;
|
||||||
|
@ -127,10 +127,7 @@ class PayPalBearer implements Bearer {
|
||||||
'Authorization' => 'Basic ' . base64_encode( $key . ':' . $secret ),
|
'Authorization' => 'Basic ' . base64_encode( $key . ':' . $secret ),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$response = $this->request(
|
$response = $this->request( $url, $args );
|
||||||
$url,
|
|
||||||
$args
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
||||||
$error = new RuntimeException(
|
$error = new RuntimeException(
|
||||||
|
@ -148,6 +145,7 @@ class PayPalBearer implements Bearer {
|
||||||
|
|
||||||
$token = Token::from_json( $response['body'] );
|
$token = Token::from_json( $response['body'] );
|
||||||
$this->cache->set( self::CACHE_KEY, $token->as_json() );
|
$this->cache->set( self::CACHE_KEY, $token->as_json() );
|
||||||
|
|
||||||
return $token;
|
return $token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
||||||
/**
|
/**
|
||||||
* ConnectManualRestEndpoint constructor.
|
* ConnectManualRestEndpoint constructor.
|
||||||
*
|
*
|
||||||
* @param string $live_host The API host for the live mode.
|
* @param string $live_host The API host for the live mode.
|
||||||
* @param string $sandbox_host The API host for the sandbox mode.
|
* @param string $sandbox_host The API host for the sandbox mode.
|
||||||
* @param LoggerInterface $logger The logger.
|
* @param LoggerInterface $logger The logger.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $live_host,
|
string $live_host,
|
||||||
|
@ -159,14 +159,16 @@ class ConnectManualRestEndpoint extends RestEndpoint {
|
||||||
* Retrieves the payee object with the merchant data
|
* Retrieves the payee object with the merchant data
|
||||||
* by creating a minimal PayPal order.
|
* by creating a minimal PayPal order.
|
||||||
*
|
*
|
||||||
* @param string $client_id The client ID.
|
|
||||||
* @param string $client_secret The client secret.
|
|
||||||
* @param bool $use_sandbox Whether to use the sandbox mode.
|
|
||||||
* @return stdClass The payee object.
|
|
||||||
* @throws Exception When failed to retrieve payee.
|
* @throws Exception When failed to retrieve payee.
|
||||||
*
|
*
|
||||||
* phpcs:disable Squiz.Commenting
|
* phpcs:disable Squiz.Commenting
|
||||||
* phpcs:disable Generic.Commenting
|
* phpcs:disable Generic.Commenting
|
||||||
|
*
|
||||||
|
* @param string $client_secret The client secret.
|
||||||
|
* @param bool $use_sandbox Whether to use the sandbox mode.
|
||||||
|
* @param string $client_id The client ID.
|
||||||
|
*
|
||||||
|
* @return stdClass The payee object.
|
||||||
*/
|
*/
|
||||||
private function request_payee(
|
private function request_payee(
|
||||||
string $client_id,
|
string $client_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue