woocommerce-paypal-payments/modules/ppcp-api-client/src/Authentication/ClientCredentials.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2024-08-06 09:25:28 +02:00
<?php
/**
* The client credentials.
*
* @package WooCommerce\PayPalCommerce\ApiClient\Authentication
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Authentication;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2024-08-06 11:35:28 +02:00
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
2024-08-06 09:25:28 +02:00
/**
* Class ClientCredentials
*/
class ClientCredentials {
/**
* The settings.
*
* @var Settings
*/
protected $settings;
/**
* ClientCredentials constructor.
*
* @param Settings $settings The settings.
*/
2024-08-06 11:35:28 +02:00
public function __construct( Settings $settings ) {
2024-08-06 09:25:28 +02:00
$this->settings = $settings;
}
2024-08-06 11:35:28 +02:00
/**
* Returns encoded client credentials.
*
* @return string
* @throws NotFoundException If setting does not found.
*/
2024-08-06 09:25:28 +02:00
public function credentials(): string {
2024-08-06 11:35:28 +02:00
$client_id = $this->settings->has( 'client_id' ) ? $this->settings->get( 'client_id' ) : '';
2024-08-06 09:25:28 +02:00
$client_secret = $this->settings->has( 'client_secret' ) ? $this->settings->get( 'client_secret' ) : '';
2024-08-06 11:35:28 +02:00
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
return 'Basic ' . base64_encode( $client_id . ':' . $client_secret );
2024-08-06 09:25:28 +02:00
}
}