Added stripe package (#1085)
[openemr.git] / vendor / stripe / stripe-php / lib / OAuth.php
blobb2bd43da97fa3f78edcf42098f705019c7c38ba5
1 <?php
3 namespace Stripe;
5 abstract class OAuth
7 /**
8 * Generates a URL to Stripe's OAuth form.
10 * @param array|null $params
11 * @param array|null $opts
13 * @return string The URL to Stripe's OAuth form.
15 public static function authorizeUrl($params = null, $opts = null)
17 if (!$params) {
18 $params = array();
21 $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase;
23 $params['client_id'] = self::_getClientId($params);
24 if (!array_key_exists('response_type', $params)) {
25 $params['response_type'] = 'code';
27 $query = Util\Util::urlEncode($params);
29 return $base . '/oauth/authorize?' . $query;
32 /**
33 * Use an authoriztion code to connect an account to your platform and
34 * fetch the user's credentials.
36 * @param array|null $params
37 * @param array|null $opts
39 * @return StripeObject Object containing the response from the API.
41 public static function token($params = null, $opts = null)
43 $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase;
44 $requestor = new ApiRequestor(null, $base);
45 list($response, $apiKey) = $requestor->request(
46 'post',
47 '/oauth/token',
48 $params,
49 null
51 return Util\Util::convertToStripeObject($response->json, $opts);
54 /**
55 * Disconnects an account from your platform.
57 * @param array|null $params
58 * @param array|null $opts
60 * @return StripeObject Object containing the response from the API.
62 public static function deauthorize($params = null, $opts = null)
64 if (!$params) {
65 $params = array();
68 $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase;
69 $requestor = new ApiRequestor(null, $base);
70 $params['client_id'] = self::_getClientId($params);
71 list($response, $apiKey) = $requestor->request(
72 'post',
73 '/oauth/deauthorize',
74 $params,
75 null
77 return Util\Util::convertToStripeObject($response->json, $opts);
80 private static function _getClientId($params = null)
82 $clientId = ($params && array_key_exists('client_id', $params)) ? $params['client_id'] : null;
83 if ($clientId === null) {
84 $clientId = Stripe::getClientId();
86 if ($clientId === null) {
87 $msg = 'No client_id provided. (HINT: set your client_id using '
88 . '"Stripe::setClientId(<CLIENT-ID>)". You can find your client_ids '
89 . 'in your Stripe dashboard at '
90 . 'https://dashboard.stripe.com/account/applications/settings, '
91 . 'after registering your account as a platform. See '
92 . 'https://stripe.com/docs/connect/standard-accounts for details, '
93 . 'or email support@stripe.com if you have any questions.';
94 throw new Error\Authentication($msg);
96 return $clientId;