Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/PayPal/paypal/rest-api-sdk-php/lib/PayPal/Handler/OauthHandler.php
Строк: 143
<?php
/**
 * API handler for OAuth Token Request REST API calls
 */

namespace PayPalHandler;

use 
PayPalCommonPayPalUserAgent;
use 
PayPalCorePayPalConstants;
use 
PayPalCorePayPalHttpConfig;
use 
PayPalExceptionPayPalConfigurationException;
use 
PayPalExceptionPayPalInvalidCredentialException;
use 
PayPalExceptionPayPalMissingCredentialException;

/**
 * Class OauthHandler
 */
class OauthHandler implements IPayPalHandler
{
    
/**
     * Private Variable
     *
     * @var PaypalRestApiContext $apiContext
     */
    
private $apiContext;

    
/**
     * Construct
     *
     * @param PaypalRestApiContext $apiContext
     */
    
public function __construct($apiContext)
    {
        
$this->apiContext $apiContext;
    }

    
/**
     * @param PayPalHttpConfig $httpConfig
     * @param string                    $request
     * @param mixed                     $options
     * @return mixed|void
     * @throws PayPalConfigurationException
     * @throws PayPalInvalidCredentialException
     * @throws PayPalMissingCredentialException
     */
    
public function handle($httpConfig$request$options)
    {
        
$config $this->apiContext->getConfig();

        
$httpConfig->setUrl(
            
rtrim(trim($this->_getEndpoint($config)), '/') .
            (isset(
$options['path']) ? $options['path'] : '')
        );

        
$headers = array(
            
"User-Agent"    => PayPalUserAgent::getValue(PayPalConstants::SDK_NAMEPayPalConstants::SDK_VERSION),
            
"Authorization" => "Basic " base64_encode($options['clientId'] . ":" $options['clientSecret']),
            
"Accept"        => "*/*"
        
);
        
$httpConfig->setHeaders($headers);

        
// Add any additional Headers that they may have provided
        
$headers $this->apiContext->getRequestHeaders();
        foreach (
$headers as $key => $value) {
            
$httpConfig->addHeader($key$value);
        }
    }

    
/**
     * Get HttpConfiguration object for OAuth API
     *
     * @param array $config
     *
     * @return PayPalHttpConfig
     * @throws PayPalExceptionPayPalConfigurationException
     */
    
private static function _getEndpoint($config)
    {
        if (isset(
$config['oauth.EndPoint'])) {
            
$baseEndpoint $config['oauth.EndPoint'];
        } elseif (isset(
$config['service.EndPoint'])) {
            
$baseEndpoint $config['service.EndPoint'];
        } elseif (isset(
$config['mode'])) {
            switch (
strtoupper($config['mode'])) {
                case 
'SANDBOX':
                    
$baseEndpoint PayPalConstants::REST_SANDBOX_ENDPOINT;
                    break;
                case 
'LIVE':
                    
$baseEndpoint PayPalConstants::REST_LIVE_ENDPOINT;
                    break;
                default:
                    throw new 
PayPalConfigurationException('The mode config parameter must be set to either sandbox/live');
            }
        } else {
            
// Defaulting to Sandbox
            
$baseEndpoint PayPalConstants::REST_SANDBOX_ENDPOINT;
        }

        
$baseEndpoint rtrim(trim($baseEndpoint), '/') . "/v1/oauth2/token";

        return 
$baseEndpoint;
    }
}
Онлайн: 1
Реклама