friendship ended with social-app. php is my new best friend
1<?php 2/** 3 * Class Stripe 4 * 5 * @created 09.08.2018 6 * @author Smiley <smiley@chillerlan.net> 7 * @copyright 2018 Smiley 8 * @license MIT 9 * 10 * @noinspection PhpUnused 11 */ 12declare(strict_types=1); 13 14namespace chillerlan\OAuth\Providers; 15 16use chillerlan\OAuth\Core\{ 17 AccessToken, AuthenticatedUser, CSRFToken, OAuth2Provider, TokenInvalidate, TokenInvalidateTrait, TokenRefresh, UserInfo, 18}; 19 20/** 21 * Stripe OAuth2 22 * 23 * @link https://stripe.com/docs/api 24 * @link https://stripe.com/docs/connect/authentication 25 * @link https://stripe.com/docs/connect/oauth-reference 26 * @link https://stripe.com/docs/connect/standard-accounts 27 * @link https://gist.github.com/amfeng/3507366 28 */ 29class Stripe extends OAuth2Provider implements CSRFToken, TokenRefresh, TokenInvalidate, UserInfo{ 30 use TokenInvalidateTrait; 31 32 public const IDENTIFIER = 'STRIPE'; 33 34 public const SCOPE_READ_WRITE = 'read_write'; 35 public const SCOPE_READ_ONLY = 'read_only'; 36 37 public const DEFAULT_SCOPES = [ 38 self::SCOPE_READ_ONLY, 39 ]; 40 41 protected string $authorizationURL = 'https://connect.stripe.com/oauth/authorize'; 42 protected string $accessTokenURL = 'https://connect.stripe.com/oauth/token'; 43 protected string $revokeURL = 'https://connect.stripe.com/oauth/deauthorize'; 44 protected string $apiURL = 'https://api.stripe.com/v1'; 45 protected string|null $userRevokeURL = 'https://dashboard.stripe.com/account/applications'; 46 protected string|null $apiDocs = 'https://stripe.com/docs/api'; 47 protected string|null $applicationURL = 'https://dashboard.stripe.com/apikeys'; 48 49 /** @codeCoverageIgnore */ 50 public function me():AuthenticatedUser{ 51 $json = $this->getMeResponseData('/accounts'); 52 53 $userdata = [ 54 'data' => $json, 55 'id' => $json['data'][0]['id'], 56 ]; 57 58 return new AuthenticatedUser($userdata); 59 } 60 61 /** 62 * @return array<string, scalar|bool|null> 63 */ 64 protected function getInvalidateAccessTokenBodyParams(AccessToken $token, string $type):array{ 65 $params = $token->extraParams; 66 67 if(!isset($params['stripe_user_id'])){ 68 throw new ProviderException('"stripe_user_id" not found in token'); 69 } 70 71 return [ 72 'client_id' => $this->options->key, 73 'stripe_user_id' => $params['stripe_user_id'], 74 ]; 75 } 76 77}