Create.php 836 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Stripe\ApiOperations;
  3. /**
  4. * Trait for creatable resources. Adds a `create()` static method to the class.
  5. *
  6. * This trait should only be applied to classes that derive from StripeObject.
  7. */
  8. trait Create
  9. {
  10. /**
  11. * @param null|array $params
  12. * @param null|array|string $options
  13. *
  14. * @throws \Stripe\Exception\ApiErrorException if the request fails
  15. *
  16. * @return static the created resource
  17. */
  18. public static function create($params = null, $options = null)
  19. {
  20. self::_validateParams($params);
  21. $url = static::classUrl();
  22. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  23. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  24. $obj->setLastResponse($response);
  25. return $obj;
  26. }
  27. }