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 namespace PayPal\Api;
  3 
  4 
  5 use PayPal\Core\PayPalConstants;
  6 use PayPal\Rest\ApiContext;
  7 
  8 class OpenIdSession
  9 {
 10 
 11     /**
 12      * Returns the PayPal URL to which the user must be redirected to
 13      * start the authentication / authorization process.
 14      *
 15      * @param string $redirectUri Uri on merchant website to where
 16      *                                  the user must be redirected to post paypal login
 17      * @param array $scope The access privilges that you are requesting for
 18      *                                  from the user. Pass empty array for all scopes.
 19      * @param string $clientId client id from developer portal
 20      *                                  See https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#attributes for more
 21      * @param null $nonce
 22      * @param null $state
 23      * @param ApiContext $apiContext Optional API Context
 24      * @return string Authorization URL
 25      */
 26     public static function getAuthorizationUrl($redirectUri, $scope, $clientId, $nonce = null, $state = null, $apiContext = null)
 27     {
 28         $apiContext = $apiContext ? $apiContext : new ApiContext();
 29         $config = $apiContext->getConfig();
 30 
 31         if ($apiContext->get($clientId)) {
 32             $clientId = $apiContext->get($clientId);
 33         }
 34 
 35         $clientId = $clientId ? $clientId : $apiContext->getCredential()->getClientId();
 36 
 37         $scope = count($scope) != 0 ? $scope : array('openid', 'profile', 'address', 'email', 'phone',
 38             'https://uri.paypal.com/services/paypalattributes', 'https://uri.paypal.com/services/expresscheckout');
 39         if (!in_array('openid', $scope)) {
 40             $scope[] = 'openid';
 41         }
 42 
 43         $params = array(
 44             'client_id' => $clientId,
 45             'response_type' => 'code',
 46             'scope' => implode(" ", $scope),
 47             'redirect_uri' => $redirectUri
 48         );
 49 
 50         if ($nonce) {
 51             $params['nonce'] = $nonce;
 52         }
 53         if ($state) {
 54             $params['state'] = $state;
 55         }
 56         return sprintf("%s/signin/authorize?%s", self::getBaseUrl($config), http_build_query($params));
 57     }
 58 
 59 
 60     /**
 61      * Returns the URL to which the user must be redirected to
 62      * logout from the OpenID provider (i.e. PayPal)
 63      *
 64      * @param string     $redirectUri   Uri on merchant website to where
 65      *                                  the user must be redirected to post logout
 66      * @param string     $idToken       id_token from the TokenInfo object
 67      * @param ApiContext $apiContext    Optional API Context
 68      * @return string logout URL
 69      */
 70     public static function getLogoutUrl($redirectUri, $idToken, $apiContext = null)
 71     {
 72 
 73         if (is_null($apiContext)) {
 74             $apiContext = new ApiContext();
 75         }
 76         $config = $apiContext->getConfig();
 77 
 78         $params = array(
 79             'id_token' => $idToken,
 80             'redirect_uri' => $redirectUri,
 81             'logout' => 'true'
 82         );
 83         return sprintf("%s/webapps/auth/protocol/openidconnect/v1/endsession?%s", self::getBaseUrl($config), http_build_query($params));
 84     }
 85 
 86     /**
 87      * Gets the base URL for the Redirect URI
 88      *
 89      * @param $config
 90      * @return null|string
 91      */
 92     private static function getBaseUrl($config)
 93     {
 94 
 95         if (array_key_exists('openid.RedirectUri', $config)) {
 96             return $config['openid.RedirectUri'];
 97         } else if (array_key_exists('mode', $config)) {
 98             switch (strtoupper($config['mode'])) {
 99                 case 'SANDBOX':
100                     return PayPalConstants::OPENID_REDIRECT_SANDBOX_URL;
101                 case 'LIVE':
102                     return PayPalConstants::OPENID_REDIRECT_LIVE_URL;
103             }
104         }
105         return null;
106     }
107 }
108 
API documentation generated by ApiGen