Completed
Pull Request — master (#11)
by
unknown
01:23
created

Stripe::getBaseDeauthorizationUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AdamPaterson\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Grant\AbstractGrant;
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
8
use League\OAuth2\Client\Token\AccessToken;
9
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Stripe extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    /**
17
     * @var string
18
     */
19
    public $urlAuthorize = 'https://connect.stripe.com/oauth/authorize';
20
21
    /**
22
     * Get authorization url to begin OAuth flow
23
     *
24
     * @return string
25
     */
26 3
    public function getBaseAuthorizationUrl()
27
    {
28 3
        return $this->urlAuthorize;
29
    }
30
31
    /**
32
     * Get access token url to retrieve token
33
     *
34
     * @param array $params
35
     *
36
     * @return string
37
     */
38 15
    public function getBaseAccessTokenUrl(array $params)
39
    {
40 15
        return 'https://connect.stripe.com/oauth/token';
41
    }
42
43
    /**
44
     * Get provider url to fetch user details
45
     *
46
     * @param AccessToken $token
47
     *
48
     * @return string
49
     */
50 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
51
    {
52 6
        return 'https://api.stripe.com/v1/account';
53
    }
54
55
    /**
56
     * Get deauthorization url to end OAuth flow
57
     *
58
     * @return string
59
     */
60
    public function getBaseDeauthorizationUrl()
61
    {
62
        return 'https://connect.stripe.com/oauth/deauthorize';
63
    }
64
65
    /**
66
     * Get the default scopes used by this provider.
67
     *
68
     * @return array
69
     */
70 3
    protected function getDefaultScopes()
71
    {
72 3
        return ['read_only'];
73
    }
74
75
    /**
76
     * Check a provider response for errors.
77
     *
78
     * @param ResponseInterface $response
79
     * @param array|string $data
80
     *
81
     * @throws IdentityProviderException
82
     */
83 12
    protected function checkResponse(ResponseInterface $response, $data)
84
    {
85 12
        if ($response->getStatusCode() >= 400) {
86 3
            throw new IdentityProviderException(
87 3
                $data['error'] ?: $response->getReasonPhrase(),
88 3
                $response->getStatusCode(),
89 1
                $response
0 ignored issues
show
Documentation introduced by
$response is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a array|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90 2
            );
91
        }
92 9
    }
93
94
    /**
95
     * Generate a user object from a successful user details request.
96
     *
97
     * @param array $response
98
     * @param AccessToken $token
99
     *
100
     * @return StripeResourceOwner
101
     */
102 3
    protected function createResourceOwner(array $response, AccessToken $token)
103
    {
104 3
        return new StripeResourceOwner($response);
105
    }
106
107 9
    protected function createAccessToken(array $response, AbstractGrant $grant)
108
    {
109 9
        $accessToken = parent::createAccessToken($response, $grant);
110
111
        // create the parent access token and add properties from response
112 9
        foreach ($response as $k => $v) {
113 9
            if (!property_exists($accessToken, $k)) {
114 9
                $accessToken->$k = $v;
115 6
            }
116 6
        }
117
118 9
        return $accessToken;
119
    }
120
121
    /**
122
     * @param string $stripeUserId stripe account ID
123
     *
124
     * @return mixed
125
     */
126
    public function deauthorize($stripeUserId)
127
    {
128
        $request = $this->createRequest(
129
            self::METHOD_POST,
130
            $this->getBaseDeauthorizationUrl(),
131
            null,
132
            [
133
                'body' => $this->buildQueryString([
134
                    'stripe_user_id' => $stripeUserId,
135
                    'client_id' => $this->clientId,
136
                    'client_secret' => $this->clientSecret,
137
                ]),
138
            ]
139
        );
140
141
        return $this->getParsedResponse($request);
142
    }
143
}
144