Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Paypal.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.38 KiB


001  <?php
002  namespace OAuth\OAuth2\Service;
003   
004  use OAuth\OAuth2\Token\StdOAuth2Token;
005  use OAuth\Common\Http\Exception\TokenResponseException;
006  use OAuth\Common\Http\Uri\Uri;
007  use OAuth\Common\Consumer\Credentials;
008  use OAuth\Common\Http\Client\ClientInterface;
009  use OAuth\Common\Storage\TokenStorageInterface;
010  use OAuth\Common\Http\Uri\UriInterface;
011   
012  /**
013   * PayPal service.
014   *
015   * @author Flávio Heleno <flaviohbatista@gmail.com>
016   * @link https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/
017   */
018  class Paypal extends AbstractService
019  {
020      /**
021       * Defined scopes
022       * @link https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#attributes
023       */
024   
025      const SCOPE_OPENID           = 'openid';
026      const SCOPE_PROFILE          = 'profile';
027      const SCOPE_PAYPALATTRIBUTES = 'https://uri.paypal.com/services/paypalattributes';
028      const SCOPE_EMAIL            = 'email';
029      const SCOPE_ADDRESS          = 'address';
030      const SCOPE_PHONE            = 'phone';
031      const SCOPE_EXPRESSCHECKOUT  = 'https://uri.paypal.com/services/expresscheckout';
032   
033      public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
034      {
035          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
036          if( null === $baseApiUri ) {
037              $this->baseApiUri = new Uri('https://api.paypal.com/v1/');
038          }
039      }
040   
041      /**
042       * @return \OAuth\Common\Http\Uri\UriInterface
043       */
044      public function getAuthorizationEndpoint()
045      {
046          return new Uri('https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize');
047      }
048   
049      /**
050       * @return \OAuth\Common\Http\Uri\UriInterface
051       */
052      public function getAccessTokenEndpoint()
053      {
054          return new Uri('https://api.paypal.com/v1/identity/openidconnect/tokenservice');
055      }
056   
057      /**
058       * Returns a class constant from ServiceInterface defining the authorization method used for the API
059       * Header is the sane default.
060       *
061       * @return int
062       */
063      protected function getAuthorizationMethod()
064      {
065          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
066      }
067   
068      /**
069       * @param string $responseBody
070       * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
071       * @throws \OAuth\Common\Http\Exception\TokenResponseException
072       */
073      protected function parseAccessTokenResponse($responseBody)
074      {
075          $data = json_decode( $responseBody, true );
076   
077          if( null === $data || !is_array($data) ) {
078              throw new TokenResponseException('Unable to parse response.');
079          } elseif( isset($data['message'] ) ) {
080              throw new TokenResponseException('Error in retrieving token: "' . $data['message'] . '"');
081          } elseif( isset($data['name'] ) ) {
082              throw new TokenResponseException('Error in retrieving token: "' . $data['name'] . '"');
083          }
084   
085          $token = new StdOAuth2Token();
086   
087          $token->setAccessToken( $data['access_token'] );
088          $token->setLifeTime( $data['expires_in'] );
089   
090          if( isset($data['refresh_token'] ) ) {
091              $token->setRefreshToken( $data['refresh_token'] );
092              unset($data['refresh_token']);
093          }
094   
095          unset( $data['access_token'] );
096          unset( $data['expires_in'] );
097          $token->setExtraParams( $data );
098   
099          return $token;
100      }
101  }
102