Overview
  • Namespace
  • Class

Namespaces

  • PayPal
    • Api
    • Auth
    • Cache
    • Common
    • Converter
    • Core
    • Exception
    • Handler
    • Log
    • Rest
    • Security
    • Transport
    • Validation

Classes

  • PayPal\Api\Address
  • PayPal\Api\Agreement
  • PayPal\Api\AgreementDetails
  • PayPal\Api\AgreementStateDescriptor
  • PayPal\Api\AgreementTransaction
  • PayPal\Api\AgreementTransactions
  • PayPal\Api\AlternatePayment
  • PayPal\Api\Amount
  • PayPal\Api\Authorization
  • PayPal\Api\BankAccount
  • PayPal\Api\BankAccountsList
  • PayPal\Api\BankToken
  • PayPal\Api\BaseAddress
  • PayPal\Api\Billing
  • PayPal\Api\BillingAgreementToken
  • PayPal\Api\BillingInfo
  • PayPal\Api\CancelNotification
  • PayPal\Api\Capture
  • PayPal\Api\CarrierAccount
  • PayPal\Api\CarrierAccountToken
  • PayPal\Api\CartBase
  • PayPal\Api\ChargeModel
  • PayPal\Api\Cost
  • PayPal\Api\CountryCode
  • PayPal\Api\CreateProfileResponse
  • PayPal\Api\Credit
  • PayPal\Api\CreditCard
  • PayPal\Api\CreditCardHistory
  • PayPal\Api\CreditCardList
  • PayPal\Api\CreditCardToken
  • PayPal\Api\CreditFinancingOffered
  • PayPal\Api\Currency
  • PayPal\Api\CurrencyConversion
  • PayPal\Api\CustomAmount
  • PayPal\Api\DetailedRefund
  • PayPal\Api\Details
  • PayPal\Api\Error
  • PayPal\Api\ErrorDetails
  • PayPal\Api\ExtendedBankAccount
  • PayPal\Api\ExternalFunding
  • PayPal\Api\FileAttachment
  • PayPal\Api\FlowConfig
  • PayPal\Api\FmfDetails
  • PayPal\Api\FundingDetail
  • PayPal\Api\FundingInstrument
  • PayPal\Api\FundingOption
  • PayPal\Api\FundingSource
  • PayPal\Api\FuturePayment
  • PayPal\Api\HyperSchema
  • PayPal\Api\Image
  • PayPal\Api\Incentive
  • PayPal\Api\InputFields
  • PayPal\Api\InstallmentInfo
  • PayPal\Api\InstallmentOption
  • PayPal\Api\Invoice
  • PayPal\Api\InvoiceAddress
  • PayPal\Api\InvoiceItem
  • PayPal\Api\InvoiceNumber
  • PayPal\Api\InvoiceSearchResponse
  • PayPal\Api\Item
  • PayPal\Api\ItemList
  • PayPal\Api\Links
  • PayPal\Api\Measurement
  • PayPal\Api\MerchantInfo
  • PayPal\Api\MerchantPreferences
  • PayPal\Api\Metadata
  • PayPal\Api\NameValuePair
  • PayPal\Api\Notification
  • PayPal\Api\OpenIdAddress
  • PayPal\Api\OpenIdError
  • PayPal\Api\OpenIdSession
  • PayPal\Api\OpenIdTokeninfo
  • PayPal\Api\OpenIdUserinfo
  • PayPal\Api\Order
  • PayPal\Api\OverrideChargeModel
  • PayPal\Api\Participant
  • PayPal\Api\Patch
  • PayPal\Api\PatchRequest
  • PayPal\Api\Payee
  • PayPal\Api\Payer
  • PayPal\Api\PayerInfo
  • PayPal\Api\Payment
  • PayPal\Api\PaymentCard
  • PayPal\Api\PaymentCardToken
  • PayPal\Api\PaymentDefinition
  • PayPal\Api\PaymentDetail
  • PayPal\Api\PaymentExecution
  • PayPal\Api\PaymentHistory
  • PayPal\Api\PaymentInstruction
  • PayPal\Api\PaymentOptions
  • PayPal\Api\PaymentSummary
  • PayPal\Api\PaymentTerm
  • PayPal\Api\Payout
  • PayPal\Api\PayoutBatch
  • PayPal\Api\PayoutBatchHeader
  • PayPal\Api\PayoutItem
  • PayPal\Api\PayoutItemDetails
  • PayPal\Api\PayoutSenderBatchHeader
  • PayPal\Api\Phone
  • PayPal\Api\Plan
  • PayPal\Api\PlanList
  • PayPal\Api\PotentialPayerInfo
  • PayPal\Api\Presentation
  • PayPal\Api\PrivateLabelCard
  • PayPal\Api\ProcessorResponse
  • PayPal\Api\RecipientBankingInstruction
  • PayPal\Api\RedirectUrls
  • PayPal\Api\Refund
  • PayPal\Api\RefundDetail
  • PayPal\Api\RefundRequest
  • PayPal\Api\RelatedResources
  • PayPal\Api\Sale
  • PayPal\Api\Search
  • PayPal\Api\ShippingAddress
  • PayPal\Api\ShippingCost
  • PayPal\Api\ShippingInfo
  • PayPal\Api\Tax
  • PayPal\Api\Template
  • PayPal\Api\TemplateData
  • PayPal\Api\Templates
  • PayPal\Api\TemplateSettings
  • PayPal\Api\TemplateSettingsMetadata
  • PayPal\Api\Terms
  • PayPal\Api\Transaction
  • PayPal\Api\TransactionBase
  • PayPal\Api\Transactions
  • PayPal\Api\VerifyWebhookSignature
  • PayPal\Api\VerifyWebhookSignatureResponse
  • PayPal\Api\Webhook
  • PayPal\Api\WebhookEvent
  • PayPal\Api\WebhookEventList
  • PayPal\Api\WebhookEventType
  • PayPal\Api\WebhookEventTypeList
  • PayPal\Api\WebhookList
  • PayPal\Api\WebProfile
  • PayPal\Auth\OAuthTokenCredential
  • PayPal\Cache\AuthorizationCache
  • PayPal\Common\ArrayUtil
  • PayPal\Common\PayPalModel
  • PayPal\Common\PayPalResourceModel
  • PayPal\Common\PayPalUserAgent
  • PayPal\Common\ReflectionUtil
  • PayPal\Converter\FormatConverter
  • PayPal\Core\PayPalConfigManager
  • PayPal\Core\PayPalConstants
  • PayPal\Core\PayPalCredentialManager
  • PayPal\Core\PayPalHttpConfig
  • PayPal\Core\PayPalHttpConnection
  • PayPal\Core\PayPalLoggingManager
  • PayPal\Handler\OauthHandler
  • PayPal\Handler\RestHandler
  • PayPal\Log\PayPalDefaultLogFactory
  • PayPal\Log\PayPalLogger
  • PayPal\Rest\ApiContext
  • PayPal\Security\Cipher
  • PayPal\Transport\PayPalRestCall
  • PayPal\Validation\ArgumentValidator
  • PayPal\Validation\JsonValidator
  • PayPal\Validation\NumericValidator
  • PayPal\Validation\UrlValidator

Interfaces

  • PayPal\Handler\IPayPalHandler
  • PayPal\Log\PayPalLogFactory
  • PayPal\Rest\IResource

Exceptions

  • PayPal\Exception\PayPalConfigurationException
  • PayPal\Exception\PayPalConnectionException
  • PayPal\Exception\PayPalInvalidCredentialException
  • PayPal\Exception\PayPalMissingCredentialException
  1 <?php
  2 /**
  3  * API handler for OAuth Token Request REST API calls
  4  */
  5 
  6 namespace PayPal\Handler;
  7 
  8 use PayPal\Common\PayPalUserAgent;
  9 use PayPal\Core\PayPalConstants;
 10 use PayPal\Core\PayPalHttpConfig;
 11 use PayPal\Exception\PayPalConfigurationException;
 12 use PayPal\Exception\PayPalInvalidCredentialException;
 13 use PayPal\Exception\PayPalMissingCredentialException;
 14 
 15 /**
 16  * Class OauthHandler
 17  */
 18 class OauthHandler implements IPayPalHandler
 19 {
 20     /**
 21      * Private Variable
 22      *
 23      * @var \Paypal\Rest\ApiContext $apiContext
 24      */
 25     private $apiContext;
 26 
 27     /**
 28      * Construct
 29      *
 30      * @param \Paypal\Rest\ApiContext $apiContext
 31      */
 32     public function __construct($apiContext)
 33     {
 34         $this->apiContext = $apiContext;
 35     }
 36 
 37     /**
 38      * @param PayPalHttpConfig $httpConfig
 39      * @param string                    $request
 40      * @param mixed                     $options
 41      * @return mixed|void
 42      * @throws PayPalConfigurationException
 43      * @throws PayPalInvalidCredentialException
 44      * @throws PayPalMissingCredentialException
 45      */
 46     public function handle($httpConfig, $request, $options)
 47     {
 48         $config = $this->apiContext->getConfig();
 49 
 50         $httpConfig->setUrl(
 51             rtrim(trim($this->_getEndpoint($config)), '/') .
 52             (isset($options['path']) ? $options['path'] : '')
 53         );
 54 
 55         $headers = array(
 56             "User-Agent"    => PayPalUserAgent::getValue(PayPalConstants::SDK_NAME, PayPalConstants::SDK_VERSION),
 57             "Authorization" => "Basic " . base64_encode($options['clientId'] . ":" . $options['clientSecret']),
 58             "Accept"        => "*/*"
 59         );
 60         $httpConfig->setHeaders($headers);
 61 
 62         // Add any additional Headers that they may have provided
 63         $headers = $this->apiContext->getRequestHeaders();
 64         foreach ($headers as $key => $value) {
 65             $httpConfig->addHeader($key, $value);
 66         }
 67     }
 68 
 69     /**
 70      * Get HttpConfiguration object for OAuth API
 71      *
 72      * @param array $config
 73      *
 74      * @return PayPalHttpConfig
 75      * @throws \PayPal\Exception\PayPalConfigurationException
 76      */
 77     private static function _getEndpoint($config)
 78     {
 79         if (isset($config['oauth.EndPoint'])) {
 80             $baseEndpoint = $config['oauth.EndPoint'];
 81         } elseif (isset($config['service.EndPoint'])) {
 82             $baseEndpoint = $config['service.EndPoint'];
 83         } elseif (isset($config['mode'])) {
 84             switch (strtoupper($config['mode'])) {
 85                 case 'SANDBOX':
 86                     $baseEndpoint = PayPalConstants::REST_SANDBOX_ENDPOINT;
 87                     break;
 88                 case 'LIVE':
 89                     $baseEndpoint = PayPalConstants::REST_LIVE_ENDPOINT;
 90                     break;
 91                 default:
 92                     throw new PayPalConfigurationException('The mode config parameter must be set to either sandbox/live');
 93             }
 94         } else {
 95             // Defaulting to Sandbox
 96             $baseEndpoint = PayPalConstants::REST_SANDBOX_ENDPOINT;
 97         }
 98 
 99         $baseEndpoint = rtrim(trim($baseEndpoint), '/') . "/v1/oauth2/token";
100 
101         return $baseEndpoint;
102     }
103 }
104 
API documentation generated by ApiGen