All.php
6 years ago
Create.php
6 years ago
Delete.php
6 years ago
NestedResource.php
6 years ago
Request.php
6 years ago
Retrieve.php
6 years ago
Update.php
6 years ago
Update.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Stripe\ApiOperations; |
| 4 | |
| 5 | /** |
| 6 | * Trait for updatable resources. Adds an `update()` static method and a |
| 7 | * `save()` method to the class. |
| 8 | * |
| 9 | * This trait should only be applied to classes that derive from StripeObject. |
| 10 | */ |
| 11 | trait Update |
| 12 | { |
| 13 | /** |
| 14 | * @param string $id The ID of the resource to update. |
| 15 | * @param array|null $params |
| 16 | * @param array|string|null $opts |
| 17 | * |
| 18 | * @return static The updated resource. |
| 19 | */ |
| 20 | public static function update($id, $params = null, $opts = null) |
| 21 | { |
| 22 | self::_validateParams($params); |
| 23 | $url = static::resourceUrl($id); |
| 24 | |
| 25 | list($response, $opts) = static::_staticRequest('post', $url, $params, $opts); |
| 26 | $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts); |
| 27 | $obj->setLastResponse($response); |
| 28 | return $obj; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @param array|string|null $opts |
| 33 | * |
| 34 | * @return static The saved resource. |
| 35 | */ |
| 36 | public function save($opts = null) |
| 37 | { |
| 38 | $params = $this->serializeParameters(); |
| 39 | if (count($params) > 0) { |
| 40 | $url = $this->instanceUrl(); |
| 41 | list($response, $opts) = $this->_request('post', $url, $params, $opts); |
| 42 | $this->refreshFrom($response, $opts); |
| 43 | } |
| 44 | return $this; |
| 45 | } |
| 46 | } |
| 47 |