1
|
|
|
<?php namespace Arcanedev\Stripe; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class StripeOAuth |
5
|
|
|
* |
6
|
|
|
* @package Arcanedev\Stripe |
7
|
|
|
* @author ARCANEDEV <[email protected]> |
8
|
|
|
*/ |
9
|
|
|
abstract class StripeOAuth |
10
|
|
|
{ |
11
|
|
|
/* ----------------------------------------------------------------- |
12
|
|
|
| Main Methods |
13
|
|
|
| ----------------------------------------------------------------- |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Generates a URL to Stripe's OAuth form. |
18
|
|
|
* |
19
|
|
|
* @param array|null $params |
20
|
|
|
* @param array|null $options |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
2 |
|
public static function authorizeUrl($params = null, $options = null) |
25
|
|
|
{ |
26
|
2 |
|
if ( ! $params) |
27
|
|
|
$params = []; |
28
|
|
|
|
29
|
2 |
|
$params['client_id'] = self::getClientId($params); |
30
|
|
|
|
31
|
2 |
|
if ( ! array_key_exists('response_type', $params)) |
32
|
2 |
|
$params['response_type'] = 'code'; |
33
|
|
|
|
34
|
2 |
|
$base = ($options && array_key_exists('connect_base', $options)) |
35
|
|
|
? $options['connect_base'] |
36
|
2 |
|
: Stripe::$connectBase; |
37
|
|
|
|
38
|
2 |
|
return $base.'/oauth/authorize?'.str_url_queries($params); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Use an authorization code to connect an account to your platform and fetch the user's credentials. |
43
|
|
|
* |
44
|
|
|
* @param array|null $params |
45
|
|
|
* @param array|null $options |
46
|
|
|
* |
47
|
|
|
* @return \Arcanedev\Stripe\StripeObject |
48
|
|
|
*/ |
49
|
6 |
|
public static function token($params = null, $options = null) |
50
|
|
|
{ |
51
|
6 |
|
$base = ($options && array_key_exists('connect_base', $options)) |
52
|
|
|
? $options['connect_base'] |
53
|
6 |
|
: Stripe::$connectBase; |
54
|
|
|
|
55
|
|
|
/** @var \Arcanedev\Stripe\Http\Response $response */ |
56
|
6 |
|
list($response, $apiKey) = Http\Requestor::make(null, $base)->request( |
57
|
6 |
|
'post', |
58
|
6 |
|
'/oauth/token', |
59
|
6 |
|
$params, |
60
|
6 |
|
null |
61
|
|
|
); |
62
|
|
|
|
63
|
2 |
|
return Utilities\Util::convertToStripeObject($response->getJson(), $options); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Disconnects an account from your platform. |
68
|
|
|
* |
69
|
|
|
* @param array|null $params |
70
|
|
|
* @param array|null $options |
71
|
|
|
* |
72
|
|
|
* @return \Arcanedev\Stripe\StripeObject |
73
|
|
|
*/ |
74
|
4 |
|
public static function deauthorize($params = null, $options = null) |
75
|
|
|
{ |
76
|
4 |
|
if ( ! $params) |
77
|
|
|
$params = []; |
78
|
|
|
|
79
|
4 |
|
$base = ($options && array_key_exists('connect_base', $options)) |
80
|
|
|
? $options['connect_base'] |
81
|
4 |
|
: Stripe::$connectBase; |
82
|
|
|
|
83
|
4 |
|
$params['client_id'] = self::getClientId($params); |
84
|
|
|
|
85
|
4 |
|
list($response, $apiKey) = Http\Requestor::make(null, $base)->request( |
86
|
4 |
|
'post', |
87
|
4 |
|
'/oauth/deauthorize', |
88
|
4 |
|
$params, |
89
|
4 |
|
null |
90
|
|
|
); |
91
|
|
|
|
92
|
4 |
|
return Utilities\Util::convertToStripeObject($response->getJson(), $options); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/* ----------------------------------------------------------------- |
96
|
|
|
| Other Methods |
97
|
|
|
| ----------------------------------------------------------------- |
98
|
|
|
*/ |
99
|
|
|
|
100
|
6 |
|
private static function getClientId($params = null) |
101
|
|
|
{ |
102
|
6 |
|
$clientId = ($params && array_key_exists('client_id', $params)) ? $params['client_id'] : null; |
103
|
|
|
|
104
|
6 |
|
if ($clientId === null) |
105
|
6 |
|
$clientId = Stripe::getClientId(); |
106
|
|
|
|
107
|
6 |
|
if ($clientId === null) { |
108
|
|
|
throw new Exceptions\AuthenticationException( |
109
|
|
|
'No client_id provided. (HINT: set your client_id using ' |
110
|
|
|
. '"Stripe::setClientId(<CLIENT-ID>)". You can find your client_ids ' |
111
|
|
|
. 'in your Stripe dashboard at ' |
112
|
|
|
. 'https://dashboard.stripe.com/account/applications/settings, ' |
113
|
|
|
. 'after registering your account as a platform. See ' |
114
|
|
|
. 'https://stripe.com/docs/connect/standard-accounts for details, ' |
115
|
|
|
. 'or email [email protected] if you have any questions.' |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
6 |
|
return $clientId; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.