composer package updates
[openemr.git] / vendor / stripe / stripe-php / lib / ApiOperations / Request.php
blobc6b06585ad2c39796d172400e4ad50941f898875
1 <?php
3 namespace Stripe\ApiOperations;
5 /**
6 * Trait for resources that need to make API requests.
8 * This trait should only be applied to classes that derive from StripeObject.
9 */
10 trait Request
12 /**
13 * @param array|null|mixed $params The list of parameters to validate
15 * @throws \Stripe\Error\Api if $params exists and is not an array
17 protected static function _validateParams($params = null)
19 if ($params && !is_array($params)) {
20 $message = "You must pass an array as the first argument to Stripe API "
21 . "method calls. (HINT: an example call to create a charge "
22 . "would be: \"Stripe\\Charge::create(['amount' => 100, "
23 . "'currency' => 'usd', 'source' => 'tok_1234'])\")";
24 throw new \Stripe\Error\Api($message);
28 /**
29 * @param string $method HTTP method ('get', 'post', etc.)
30 * @param string $url URL for the request
31 * @param array $params list of parameters for the request
32 * @param array|string|null $options
34 * @return array tuple containing (the JSON response, $options)
36 protected function _request($method, $url, $params = [], $options = null)
38 $opts = $this->_opts->merge($options);
39 list($resp, $options) = static::_staticRequest($method, $url, $params, $opts);
40 $this->setLastResponse($resp);
41 return [$resp->json, $options];
44 /**
45 * @param string $method HTTP method ('get', 'post', etc.)
46 * @param string $url URL for the request
47 * @param array $params list of parameters for the request
48 * @param array|string|null $options
50 * @return array tuple containing (the JSON response, $options)
52 protected static function _staticRequest($method, $url, $params, $options)
54 $opts = \Stripe\Util\RequestOptions::parse($options);
55 $requestor = new \Stripe\ApiRequestor($opts->apiKey, static::baseUrl());
56 list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers);
57 $opts->discardNonPersistentHeaders();
58 return [$response, $opts];