3 namespace Stripe\ApiOperations
;
6 * Trait for resources that have nested resources.
8 * This trait should only be applied to classes that derive from StripeObject.
13 * @param string $method
15 * @param array|null $params
16 * @param array|string|null $options
18 * @return \Stripe\StripeObject
20 protected static function _nestedResourceOperation($method, $url, $params = null, $options = null)
22 self
::_validateParams($params);
24 list($response, $opts) = static::_staticRequest($method, $url, $params, $options);
25 $obj = \Stripe\Util\Util
::convertToStripeObject($response->json
, $opts);
26 $obj->setLastResponse($response);
32 * @param string $nestedPath
33 * @param string|null $nestedId
37 protected static function _nestedResourceUrl($id, $nestedPath, $nestedId = null)
39 $url = static::resourceUrl($id) . $nestedPath;
40 if ($nestedId !== null) {
48 * @param string $nestedPath
49 * @param array|null $params
50 * @param array|string|null $options
52 * @return \Stripe\StripeObject
54 protected static function _createNestedResource($id, $nestedPath, $params = null, $options = null)
56 $url = static::_nestedResourceUrl($id, $nestedPath);
57 return self
::_nestedResourceOperation('post', $url, $params, $options);
62 * @param string $nestedPath
63 * @param array|null $params
64 * @param array|string|null $options
66 * @return \Stripe\StripeObject
68 protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
70 $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
71 return self
::_nestedResourceOperation('get', $url, $params, $options);
76 * @param string $nestedPath
77 * @param array|null $params
78 * @param array|string|null $options
80 * @return \Stripe\StripeObject
82 protected static function _updateNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
84 $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
85 return self
::_nestedResourceOperation('post', $url, $params, $options);
90 * @param string $nestedPath
91 * @param array|null $params
92 * @param array|string|null $options
94 * @return \Stripe\StripeObject
96 protected static function _deleteNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null)
98 $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId);
99 return self
::_nestedResourceOperation('delete', $url, $params, $options);
104 * @param string $nestedPath
105 * @param array|null $params
106 * @param array|string|null $options
108 * @return \Stripe\StripeObject
110 protected static function _allNestedResources($id, $nestedPath, $params = null, $options = null)
112 $url = static::_nestedResourceUrl($id, $nestedPath);
113 return self
::_nestedResourceOperation('get', $url, $params, $options);