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 namespace PayPal\Rest;
  4 
  5 use PayPal\Core\PayPalConfigManager;
  6 use PayPal\Core\PayPalCredentialManager;
  7 
  8 /**
  9  * Class ApiContext
 10  *
 11  * Call level parameters such as request id, credentials etc
 12  *
 13  * @package PayPal\Rest
 14  */
 15 class ApiContext
 16 {
 17 
 18     /**
 19      * Unique request id to be used for this call
 20      * The user can either generate one as per application
 21      * needs or let the SDK generate one
 22      *
 23      * @var null|string $requestId
 24      */
 25     private $requestId;
 26 
 27     /**
 28      * This is a placeholder for holding credential for the request
 29      * If the value is not set, it would get the value from @\PayPal\Core\PayPalCredentialManager
 30      *
 31      * @var \PayPal\Auth\OAuthTokenCredential
 32      */
 33     private $credential;
 34 
 35 
 36     /**
 37      * Construct
 38      *
 39      * @param \PayPal\Auth\OAuthTokenCredential $credential
 40      * @param string|null                       $requestId
 41      */
 42     public function __construct($credential = null, $requestId = null)
 43     {
 44         $this->requestId = $requestId;
 45         $this->credential = $credential;
 46     }
 47 
 48     /**
 49      * Get Credential
 50      *
 51      * @return \PayPal\Auth\OAuthTokenCredential
 52      */
 53     public function getCredential()
 54     {
 55         if ($this->credential == null) {
 56             return PayPalCredentialManager::getInstance()->getCredentialObject();
 57         }
 58         return $this->credential;
 59     }
 60 
 61     public function getRequestHeaders()
 62     {
 63         $result = PayPalConfigManager::getInstance()->get('http.headers');
 64         $headers = array();
 65         foreach ($result as $header => $value) {
 66             $headerName = ltrim($header, 'http.headers');
 67             $headers[$headerName] = $value;
 68         }
 69         return $headers;
 70     }
 71 
 72     public function addRequestHeader($name, $value)
 73     {
 74         // Determine if the name already has a 'http.headers' prefix. If not, add one.
 75         if (!(substr($name, 0, strlen('http.headers')) === 'http.headers')) {
 76             $name = 'http.headers.' . $name;
 77         }
 78         PayPalConfigManager::getInstance()->addConfigs(array($name => $value));
 79     }
 80 
 81     /**
 82      * Get Request ID
 83      *
 84      * @return string
 85      */
 86     public function getRequestId()
 87     {
 88         return $this->requestId;
 89     }
 90 
 91     /**
 92      * Sets the request ID
 93      *
 94      * @param string $requestId the PayPal-Request-Id value to use
 95      */
 96     public function setRequestId($requestId)
 97     {
 98         $this->requestId = $requestId;
 99     }
100 
101     /**
102      * Resets the requestId that can be used to set the PayPal-request-id
103      * header used for idempotency. In cases where you need to make multiple create calls
104      * using the same ApiContext object, you need to reset request Id.
105      * @deprecated Call setRequestId with a unique value.
106      *
107      * @return string
108      */
109     public function resetRequestId()
110     {
111         $this->requestId = $this->generateRequestId();
112         return $this->getRequestId();
113     }
114 
115     /**
116      * Sets Config
117      *
118      * @param array $config SDK configuration parameters
119      */
120     public function setConfig(array $config)
121     {
122         PayPalConfigManager::getInstance()->addConfigs($config);
123     }
124 
125     /**
126      * Gets Configurations
127      *
128      * @return array
129      */
130     public function getConfig()
131     {
132         return PayPalConfigManager::getInstance()->getConfigHashmap();
133     }
134 
135     /**
136      * Gets a specific configuration from key
137      *
138      * @param $searchKey
139      * @return mixed
140      */
141     public function get($searchKey)
142     {
143         return PayPalConfigManager::getInstance()->get($searchKey);
144     }
145 
146     /**
147      * Generates a unique per request id that
148      * can be used to set the PayPal-Request-Id header
149      * that is used for idempotency
150      * @deprecated
151      *
152      * @return string
153      */
154     private function generateRequestId()
155     {
156         static $pid = -1;
157         static $addr = -1;
158 
159         if ($pid == -1) {
160             $pid = getmypid();
161         }
162 
163         if ($addr == -1) {
164             if (array_key_exists('SERVER_ADDR', $_SERVER)) {
165                 $addr = ip2long($_SERVER['SERVER_ADDR']);
166             } else {
167                 $addr = php_uname('n');
168             }
169         }
170 
171         return $addr . $pid . $_SERVER['REQUEST_TIME'] . mt_rand(0, 0xffff);
172     }
173 }
174 
API documentation generated by ApiGen