wp-user-avatar
/
third-party
/
vendor
/
stripe
/
stripe-php
/
lib
/
ApiOperations
/
NestedResource.php
All.php
2 months ago
Create.php
2 months ago
Delete.php
2 months ago
NestedResource.php
2 months ago
Request.php
2 months ago
Retrieve.php
2 months ago
Search.php
2 months ago
SingletonRetrieve.php
2 months ago
Update.php
2 months ago
NestedResource.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePressVendor\Stripe\ApiOperations; |
| 4 | |
| 5 | /** |
| 6 | * Trait for resources that have nested resources. |
| 7 | * |
| 8 | * This trait should only be applied to classes that derive from StripeObject. |
| 9 | */ |
| 10 | trait NestedResource |
| 11 | { |
| 12 | /** |
| 13 | * @param 'delete'|'get'|'post' $method |
| 14 | * @param string $url |
| 15 | * @param null|array $params |
| 16 | * @param null|array|string $options |
| 17 | * |
| 18 | * @return \Stripe\StripeObject |
| 19 | */ |
| 20 | protected static function _nestedResourceOperation($method, $url, $params = null, $options = null) |
| 21 | { |
| 22 | self::_validateParams($params); |
| 23 | list($response, $opts) = static::_staticRequest($method, $url, $params, $options); |
| 24 | $obj = \ProfilePressVendor\Stripe\Util\Util::convertToStripeObject($response->json, $opts); |
| 25 | $obj->setLastResponse($response); |
| 26 | return $obj; |
| 27 | } |
| 28 | /** |
| 29 | * @param string $id |
| 30 | * @param string $nestedPath |
| 31 | * @param null|string $nestedId |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | protected static function _nestedResourceUrl($id, $nestedPath, $nestedId = null) |
| 36 | { |
| 37 | $url = static::resourceUrl($id) . $nestedPath; |
| 38 | if (null !== $nestedId) { |
| 39 | $url .= "/{$nestedId}"; |
| 40 | } |
| 41 | return $url; |
| 42 | } |
| 43 | /** |
| 44 | * @param string $id |
| 45 | * @param string $nestedPath |
| 46 | * @param null|array $params |
| 47 | * @param null|array|string $options |
| 48 | * |
| 49 | * @throws \Stripe\Exception\ApiErrorException if the request fails |
| 50 | * |
| 51 | * @return \Stripe\StripeObject |
| 52 | */ |
| 53 | protected static function _createNestedResource($id, $nestedPath, $params = null, $options = null) |
| 54 | { |
| 55 | $url = static::_nestedResourceUrl($id, $nestedPath); |
| 56 | return self::_nestedResourceOperation('post', $url, $params, $options); |
| 57 | } |
| 58 | /** |
| 59 | * @param string $id |
| 60 | * @param string $nestedPath |
| 61 | * @param null|string $nestedId |
| 62 | * @param null|array $params |
| 63 | * @param null|array|string $options |
| 64 | * |
| 65 | * @throws \Stripe\Exception\ApiErrorException if the request fails |
| 66 | * |
| 67 | * @return \Stripe\StripeObject |
| 68 | */ |
| 69 | protected static function _retrieveNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) |
| 70 | { |
| 71 | $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); |
| 72 | return self::_nestedResourceOperation('get', $url, $params, $options); |
| 73 | } |
| 74 | /** |
| 75 | * @param string $id |
| 76 | * @param string $nestedPath |
| 77 | * @param null|string $nestedId |
| 78 | * @param null|array $params |
| 79 | * @param null|array|string $options |
| 80 | * |
| 81 | * @throws \Stripe\Exception\ApiErrorException if the request fails |
| 82 | * |
| 83 | * @return \Stripe\StripeObject |
| 84 | */ |
| 85 | protected static function _updateNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) |
| 86 | { |
| 87 | $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); |
| 88 | return self::_nestedResourceOperation('post', $url, $params, $options); |
| 89 | } |
| 90 | /** |
| 91 | * @param string $id |
| 92 | * @param string $nestedPath |
| 93 | * @param null|string $nestedId |
| 94 | * @param null|array $params |
| 95 | * @param null|array|string $options |
| 96 | * |
| 97 | * @throws \Stripe\Exception\ApiErrorException if the request fails |
| 98 | * |
| 99 | * @return \Stripe\StripeObject |
| 100 | */ |
| 101 | protected static function _deleteNestedResource($id, $nestedPath, $nestedId, $params = null, $options = null) |
| 102 | { |
| 103 | $url = static::_nestedResourceUrl($id, $nestedPath, $nestedId); |
| 104 | return self::_nestedResourceOperation('delete', $url, $params, $options); |
| 105 | } |
| 106 | /** |
| 107 | * @param string $id |
| 108 | * @param string $nestedPath |
| 109 | * @param null|array $params |
| 110 | * @param null|array|string $options |
| 111 | * |
| 112 | * @throws \Stripe\Exception\ApiErrorException if the request fails |
| 113 | * |
| 114 | * @return \Stripe\StripeObject |
| 115 | */ |
| 116 | protected static function _allNestedResources($id, $nestedPath, $params = null, $options = null) |
| 117 | { |
| 118 | $url = static::_nestedResourceUrl($id, $nestedPath); |
| 119 | return self::_nestedResourceOperation('get', $url, $params, $options); |
| 120 | } |
| 121 | } |
| 122 |