Completed
Push — master ( ee6765...e79130 )
by Georgio
01:42
created

Stripe   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 4
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getAuthorizationEndpoint() 0 4 1
A getAccessTokenEndpoint() 0 4 1
A getAuthorizationMethod() 0 4 1
A parseAccessTokenResponse() 0 19 4
1
<?php
2
3
namespace OAuth\OAuth2\Service;
4
5
use OAuth\OAuth2\Token\StdOAuth2Token;
6
use OAuth\Common\Http\Exception\TokenResponseException;
7
use OAuth\Common\Http\Uri\Uri;
8
use OAuth\Common\Consumer\CredentialsInterface;
9
use OAuth\Common\Http\Client\ClientInterface;
10
use OAuth\Common\Storage\TokenStorageInterface;
11
use OAuth\Common\Http\Uri\UriInterface;
12
13
class Stripe extends AbstractService
14
{
15
    const SCOPE_READONLY = 'read_only';
16
    const SCOPE_READWRITE = 'read_write';
17
18
    public function __construct(
19
        CredentialsInterface $credentials,
20
        ClientInterface $httpClient,
21
        TokenStorageInterface $storage,
22
        $scopes = array(),
23
        UriInterface $baseApiUri = null
24
    ) {
25
        parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
26
27
        if (null === $baseApiUri) {
28
            $this->baseApiUri = new Uri('https://connect.stripe.com/');
29
        }
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getAuthorizationEndpoint()
36
    {
37
        return new Uri('https://connect.stripe.com/oauth/authorize');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getAccessTokenEndpoint()
44
    {
45
        return new Uri('https://connect.stripe.com/oauth/token');
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function getAuthorizationMethod()
52
    {
53
        return static::AUTHORIZATION_METHOD_QUERY_STRING;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function parseAccessTokenResponse($responseBody)
60
    {
61
        $data = json_decode($responseBody, true);
62
63
        if (null === $data || ! is_array($data)) {
64
            throw new TokenResponseException('Unable to parse response.');
65
        } elseif (isset($data['error'])) {
66
            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
67
        }
68
69
        $token = new StdOAuth2Token();
70
        $token->setAccessToken($data['access_token']);
71
72
        unset($data['access_token']);
73
74
        $token->setExtraParams($data);
75
76
        return $token;
77
    }
78
}
79