Feature.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Entitlements;
  4. /**
  5. * A feature represents a monetizable ability or functionality in your system.
  6. * Features can be assigned to products, and when those products are purchased, Stripe will create an entitlement to the feature for the purchasing customer.
  7. *
  8. * @property string $id Unique identifier for the object.
  9. * @property string $object String representing the object's type. Objects of the same type share the same value.
  10. * @property bool $active Inactive features cannot be attached to new products and will not be returned from the features list endpoint.
  11. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  12. * @property string $lookup_key A unique key you provide as your own system identifier. This may be up to 80 characters.
  13. * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  14. * @property string $name The feature's name, for your own purpose, not meant to be displayable to the customer.
  15. */
  16. class Feature extends \Stripe\ApiResource
  17. {
  18. const OBJECT_NAME = 'entitlements.feature';
  19. use \Stripe\ApiOperations\Update;
  20. /**
  21. * Creates a feature.
  22. *
  23. * @param null|array $params
  24. * @param null|array|string $options
  25. *
  26. * @throws \Stripe\Exception\ApiErrorException if the request fails
  27. *
  28. * @return \Stripe\Entitlements\Feature the created resource
  29. */
  30. public static function create($params = null, $options = null)
  31. {
  32. self::_validateParams($params);
  33. $url = static::classUrl();
  34. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  35. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  36. $obj->setLastResponse($response);
  37. return $obj;
  38. }
  39. /**
  40. * Retrieve a list of features.
  41. *
  42. * @param null|array $params
  43. * @param null|array|string $opts
  44. *
  45. * @throws \Stripe\Exception\ApiErrorException if the request fails
  46. *
  47. * @return \Stripe\Collection<\Stripe\Entitlements\Feature> of ApiResources
  48. */
  49. public static function all($params = null, $opts = null)
  50. {
  51. $url = static::classUrl();
  52. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  53. }
  54. /**
  55. * Retrieves a feature.
  56. *
  57. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  58. * @param null|array|string $opts
  59. *
  60. * @throws \Stripe\Exception\ApiErrorException if the request fails
  61. *
  62. * @return \Stripe\Entitlements\Feature
  63. */
  64. public static function retrieve($id, $opts = null)
  65. {
  66. $opts = \Stripe\Util\RequestOptions::parse($opts);
  67. $instance = new static($id, $opts);
  68. $instance->refresh();
  69. return $instance;
  70. }
  71. /**
  72. * Update a feature’s metadata or permanently deactivate it.
  73. *
  74. * @param string $id the ID of the resource to update
  75. * @param null|array $params
  76. * @param null|array|string $opts
  77. *
  78. * @throws \Stripe\Exception\ApiErrorException if the request fails
  79. *
  80. * @return \Stripe\Entitlements\Feature the updated resource
  81. */
  82. public static function update($id, $params = null, $opts = null)
  83. {
  84. self::_validateParams($params);
  85. $url = static::resourceUrl($id);
  86. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  87. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  88. $obj->setLastResponse($response);
  89. return $obj;
  90. }
  91. }