diff options
Diffstat (limited to 'vendor/stripe/stripe-php/lib/ApiOperations')
7 files changed, 417 insertions, 0 deletions
diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/All.php b/vendor/stripe/stripe-php/lib/ApiOperations/All.php new file mode 100644 index 0000000..ff2955d --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/All.php @@ -0,0 +1,37 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for listable resources. Adds a `all()` static method to the class. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait All +{ + /** + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\Collection of ApiResources + */ + public static function all($params = null, $opts = null) + { + self::_validateParams($params); + $url = static::classUrl(); + + list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); + $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); + if (!($obj instanceof \Stripe\Collection)) { + throw new \Stripe\Exception\UnexpectedValueException( + 'Expected type ' . \Stripe\Collection::class . ', got "' . \get_class($obj) . '" instead.' + ); + } + $obj->setLastResponse($response); + $obj->setFilters($params); + + return $obj; + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/Create.php b/vendor/stripe/stripe-php/lib/ApiOperations/Create.php new file mode 100644 index 0000000..c435132 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/Create.php @@ -0,0 +1,31 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for creatable resources. Adds a `create()` static method to the class. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait Create +{ + /** + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return static the created resource + */ + public static function create($params = null, $options = null) + { + self::_validateParams($params); + $url = static::classUrl(); + + list($response, $opts) = static::_staticRequest('post', $url, $params, $options); + $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); + $obj->setLastResponse($response); + + return $obj; + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/Delete.php b/vendor/stripe/stripe-php/lib/ApiOperations/Delete.php new file mode 100644 index 0000000..c6082ff --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/Delete.php @@ -0,0 +1,30 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for deletable resources. Adds a `delete()` method to the class. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait Delete +{ + /** + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return static the deleted resource + */ + public function delete($params = null, $opts = null) + { + self::_validateParams($params); + + $url = $this->instanceUrl(); + list($response, $opts) = $this->_request('delete', $url, $params, $opts); + $this->refreshFrom($response, $opts); + + return $this; + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/NestedResource.php b/vendor/stripe/stripe-php/lib/ApiOperations/NestedResource.php new file mode 100644 index 0000000..180cacd --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/NestedResource.php @@ -0,0 +1,135 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for resources that have nested resources. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait NestedResource +{ + /** + * @param string $method + * @param string $url + * @param null|array $params + * @param null|array|string $options + * + * @return \Stripe\StripeObject + */ + protected static function _nestedResourceOperation($method, $url, $params = null, $options = null) + { + self::_validateParams($params); + + list($response, $opts) = static::_staticRequest($method, $url, $params, $options); + $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); + $obj->setLastResponse($response); + + return $obj; + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|string $nestedId + * + * @return string + */ + protected static function _nestedResourceUrl($id, $nestedPath, $nestedId = null) + { + $url = static::resourceUrl($id) . $nestedPath; + if (null !== $nestedId) { + $url .= "/{$nestedId}"; + } + + return $url; + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\StripeObject + */ + protected static function _createNestedResource($id, $nestedPath, $params = null, $options = null) + { + $url = static::_nestedResourceUrl($id, $nestedPath); + + return self::_nestedResourceOperation('post', $url, $params, $options); + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|string $nestedId + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\StripeObject + */ + protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) + { + $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); + + return self::_nestedResourceOperation('get', $url, $params, $options); + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|string $nestedId + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\StripeObject + */ + protected static function _updateNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) + { + $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); + + return self::_nestedResourceOperation('post', $url, $params, $options); + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|string $nestedId + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\StripeObject + */ + protected static function _deleteNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) + { + $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); + + return self::_nestedResourceOperation('delete', $url, $params, $options); + } + + /** + * @param string $id + * @param string $nestedPath + * @param null|array $params + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\StripeObject + */ + protected static function _allNestedResources($id, $nestedPath, $params = null, $options = null) + { + $url = static::_nestedResourceUrl($id, $nestedPath); + + return self::_nestedResourceOperation('get', $url, $params, $options); + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/Request.php b/vendor/stripe/stripe-php/lib/ApiOperations/Request.php new file mode 100644 index 0000000..24c3741 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/Request.php @@ -0,0 +1,102 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for resources that need to make API requests. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait Request +{ + /** + * @param null|array|mixed $params The list of parameters to validate + * + * @throws \Stripe\Exception\InvalidArgumentException if $params exists and is not an array + */ + protected static function _validateParams($params = null) + { + if ($params && !\is_array($params)) { + $message = 'You must pass an array as the first argument to Stripe API ' + . 'method calls. (HINT: an example call to create a charge ' + . "would be: \"Stripe\\Charge::create(['amount' => 100, " + . "'currency' => 'usd', 'source' => 'tok_1234'])\")"; + + throw new \Stripe\Exception\InvalidArgumentException($message); + } + } + + /** + * @param string $method HTTP method ('get', 'post', etc.) + * @param string $url URL for the request + * @param array $params list of parameters for the request + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return array tuple containing (the JSON response, $options) + */ + protected function _request($method, $url, $params = [], $options = null) + { + $opts = $this->_opts->merge($options); + list($resp, $options) = static::_staticRequest($method, $url, $params, $opts); + $this->setLastResponse($resp); + + return [$resp->json, $options]; + } + + /** + * @param string $method HTTP method ('get', 'post', etc.) + * @param string $url URL for the request + * @param callable $readBodyChunk function that will receive chunks of data from a successful request body + * @param array $params list of parameters for the request + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return array tuple containing (the JSON response, $options) + */ + protected function _requestStream($method, $url, $readBodyChunk, $params = [], $options = null) + { + $opts = $this->_opts->merge($options); + static::_staticStreamingRequest($method, $url, $readBodyChunk, $params, $opts); + } + + /** + * @param string $method HTTP method ('get', 'post', etc.) + * @param string $url URL for the request + * @param array $params list of parameters for the request + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return array tuple containing (the JSON response, $options) + */ + protected static function _staticRequest($method, $url, $params, $options) + { + $opts = \Stripe\Util\RequestOptions::parse($options); + $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl(); + $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl); + list($response, $opts->apiKey) = $requestor->request($method, $url, $params, $opts->headers); + $opts->discardNonPersistentHeaders(); + + return [$response, $opts]; + } + + /** + * @param string $method HTTP method ('get', 'post', etc.) + * @param string $url URL for the request + * @param callable $readBodyChunk function that will receive chunks of data from a successful request body + * @param array $params list of parameters for the request + * @param null|array|string $options + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + */ + protected static function _staticStreamingRequest($method, $url, $readBodyChunk, $params, $options) + { + $opts = \Stripe\Util\RequestOptions::parse($options); + $baseUrl = isset($opts->apiBase) ? $opts->apiBase : static::baseUrl(); + $requestor = new \Stripe\ApiRequestor($opts->apiKey, $baseUrl); + $requestor->requestStream($method, $url, $readBodyChunk, $params, $opts->headers); + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php b/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php new file mode 100644 index 0000000..5170afb --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/Retrieve.php @@ -0,0 +1,30 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for retrievable resources. Adds a `retrieve()` static method to the + * class. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait Retrieve +{ + /** + * @param array|string $id the ID of the API resource to retrieve, + * or an options array containing an `id` key + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return static + */ + public static function retrieve($id, $opts = null) + { + $opts = \Stripe\Util\RequestOptions::parse($opts); + $instance = new static($id, $opts); + $instance->refresh(); + + return $instance; + } +} diff --git a/vendor/stripe/stripe-php/lib/ApiOperations/Update.php b/vendor/stripe/stripe-php/lib/ApiOperations/Update.php new file mode 100644 index 0000000..688f080 --- /dev/null +++ b/vendor/stripe/stripe-php/lib/ApiOperations/Update.php @@ -0,0 +1,52 @@ +<?php + +namespace Stripe\ApiOperations; + +/** + * Trait for updatable resources. Adds an `update()` static method and a + * `save()` method to the class. + * + * This trait should only be applied to classes that derive from StripeObject. + */ +trait Update +{ + /** + * @param string $id the ID of the resource to update + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return static the updated resource + */ + public static function update($id, $params = null, $opts = null) + { + self::_validateParams($params); + $url = static::resourceUrl($id); + + list($response, $opts) = static::_staticRequest('post', $url, $params, $opts); + $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); + $obj->setLastResponse($response); + + return $obj; + } + + /** + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return static the saved resource + */ + public function save($opts = null) + { + $params = $this->serializeParameters(); + if (\count($params) > 0) { + $url = $this->instanceUrl(); + list($response, $opts) = $this->_request('post', $url, $params, $opts); + $this->refreshFrom($response, $opts); + } + + return $this; + } +} |