Passed
Push — main ( e868ec...9f95cc )
by smiley
12:00
created

Stripe   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 35
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Stripe
4
 *
5
 * @created      09.08.2018
6
 * @author       Smiley <[email protected]>
7
 * @copyright    2018 Smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\OAuth\Providers;
12
13
use chillerlan\HTTP\Utils\MessageUtil;
14
use chillerlan\OAuth\Core\{CSRFToken, OAuth2Provider, ProviderException, TokenRefresh};
15
use Psr\Http\Message\ResponseInterface;
16
use function sprintf;
17
18
/**
19
 * @see https://stripe.com/docs/api
20
 * @see https://stripe.com/docs/connect/authentication
21
 * @see https://stripe.com/docs/connect/oauth-reference
22
 * @see https://stripe.com/docs/connect/standard-accounts
23
 * @see https://gist.github.com/amfeng/3507366
24
 */
25
class Stripe extends OAuth2Provider implements CSRFToken, TokenRefresh{
26
27
	public const SCOPE_READ_WRITE     = 'read_write';
28
	public const SCOPE_READ_ONLY      = 'read_only';
29
30
	protected string  $authURL        = 'https://connect.stripe.com/oauth/authorize';
31
	protected string  $accessTokenURL = 'https://connect.stripe.com/oauth/token';
32
	protected string  $apiURL         = 'https://api.stripe.com/v1';
33
	protected ?string $revokeURL      = 'https://connect.stripe.com/oauth/deauthorize';
34
	protected ?string $userRevokeURL  = 'https://dashboard.stripe.com/account/applications';
35
	protected ?string $apiDocs        = 'https://stripe.com/docs/api';
36
	protected ?string $applicationURL = 'https://dashboard.stripe.com/apikeys';
37
38
	protected array $defaultScopes    = [
39
		self::SCOPE_READ_ONLY,
40
	];
41
42
	/**
43
	 * @inheritDoc
44
	 */
45
	public function me():ResponseInterface{
46
		$response = $this->request('/accounts');
47
		$status   = $response->getStatusCode();
48
49
		if($status === 200){
50
			return $response;
51
		}
52
53
		$json = MessageUtil::decodeJSON($response);
54
55
		if(isset($json->error, $json->error_description)){
56
			throw new ProviderException($json->error_description);
57
		}
58
59
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
60
	}
61
62
}
63