SubscriptionSchedule.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * A subscription schedule allows you to create and manage the lifecycle of a subscription by predefining expected changes.
  6. *
  7. * Related guide: <a href="https://stripe.com/docs/billing/subscriptions/subscription-schedules">Subscription schedules</a>
  8. *
  9. * @property string $id Unique identifier for the object.
  10. * @property string $object String representing the object's type. Objects of the same type share the same value.
  11. * @property null|string|\Stripe\Application $application ID of the Connect Application that created the schedule.
  12. * @property null|int $canceled_at Time at which the subscription schedule was canceled. Measured in seconds since the Unix epoch.
  13. * @property null|int $completed_at Time at which the subscription schedule was completed. Measured in seconds since the Unix epoch.
  14. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  15. * @property null|\Stripe\StripeObject $current_phase Object representing the start and end dates for the current phase of the subscription schedule, if it is <code>active</code>.
  16. * @property string|\Stripe\Customer $customer ID of the customer who owns the subscription schedule.
  17. * @property \Stripe\StripeObject $default_settings
  18. * @property string $end_behavior Behavior of the subscription schedule and underlying subscription when it ends. Possible values are <code>release</code> or <code>cancel</code> with the default being <code>release</code>. <code>release</code> will end the subscription schedule and keep the underlying subscription running. <code>cancel</code> will end the subscription schedule and cancel the underlying subscription.
  19. * @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.
  20. * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  21. * @property \Stripe\StripeObject[] $phases Configuration for the subscription schedule's phases.
  22. * @property null|int $released_at Time at which the subscription schedule was released. Measured in seconds since the Unix epoch.
  23. * @property null|string $released_subscription ID of the subscription once managed by the subscription schedule (if it is released).
  24. * @property string $status The present status of the subscription schedule. Possible values are <code>not_started</code>, <code>active</code>, <code>completed</code>, <code>released</code>, and <code>canceled</code>. You can read more about the different states in our <a href="https://stripe.com/docs/billing/subscriptions/subscription-schedules">behavior guide</a>.
  25. * @property null|string|\Stripe\Subscription $subscription ID of the subscription managed by the subscription schedule.
  26. * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this subscription schedule belongs to.
  27. */
  28. class SubscriptionSchedule extends ApiResource
  29. {
  30. const OBJECT_NAME = 'subscription_schedule';
  31. use ApiOperations\Update;
  32. const END_BEHAVIOR_CANCEL = 'cancel';
  33. const END_BEHAVIOR_NONE = 'none';
  34. const END_BEHAVIOR_RELEASE = 'release';
  35. const END_BEHAVIOR_RENEW = 'renew';
  36. const STATUS_ACTIVE = 'active';
  37. const STATUS_CANCELED = 'canceled';
  38. const STATUS_COMPLETED = 'completed';
  39. const STATUS_NOT_STARTED = 'not_started';
  40. const STATUS_RELEASED = 'released';
  41. /**
  42. * Creates a new subscription schedule object. Each customer can have up to 500
  43. * active or scheduled subscriptions.
  44. *
  45. * @param null|array $params
  46. * @param null|array|string $options
  47. *
  48. * @throws \Stripe\Exception\ApiErrorException if the request fails
  49. *
  50. * @return \Stripe\SubscriptionSchedule the created resource
  51. */
  52. public static function create($params = null, $options = null)
  53. {
  54. self::_validateParams($params);
  55. $url = static::classUrl();
  56. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  57. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  58. $obj->setLastResponse($response);
  59. return $obj;
  60. }
  61. /**
  62. * Retrieves the list of your subscription schedules.
  63. *
  64. * @param null|array $params
  65. * @param null|array|string $opts
  66. *
  67. * @throws \Stripe\Exception\ApiErrorException if the request fails
  68. *
  69. * @return \Stripe\Collection<\Stripe\SubscriptionSchedule> of ApiResources
  70. */
  71. public static function all($params = null, $opts = null)
  72. {
  73. $url = static::classUrl();
  74. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  75. }
  76. /**
  77. * Retrieves the details of an existing subscription schedule. You only need to
  78. * supply the unique subscription schedule identifier that was returned upon
  79. * subscription schedule creation.
  80. *
  81. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  82. * @param null|array|string $opts
  83. *
  84. * @throws \Stripe\Exception\ApiErrorException if the request fails
  85. *
  86. * @return \Stripe\SubscriptionSchedule
  87. */
  88. public static function retrieve($id, $opts = null)
  89. {
  90. $opts = \Stripe\Util\RequestOptions::parse($opts);
  91. $instance = new static($id, $opts);
  92. $instance->refresh();
  93. return $instance;
  94. }
  95. /**
  96. * Updates an existing subscription schedule.
  97. *
  98. * @param string $id the ID of the resource to update
  99. * @param null|array $params
  100. * @param null|array|string $opts
  101. *
  102. * @throws \Stripe\Exception\ApiErrorException if the request fails
  103. *
  104. * @return \Stripe\SubscriptionSchedule the updated resource
  105. */
  106. public static function update($id, $params = null, $opts = null)
  107. {
  108. self::_validateParams($params);
  109. $url = static::resourceUrl($id);
  110. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  111. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  112. $obj->setLastResponse($response);
  113. return $obj;
  114. }
  115. /**
  116. * @param null|array $params
  117. * @param null|array|string $opts
  118. *
  119. * @throws \Stripe\Exception\ApiErrorException if the request fails
  120. *
  121. * @return \Stripe\SubscriptionSchedule the canceled subscription schedule
  122. */
  123. public function cancel($params = null, $opts = null)
  124. {
  125. $url = $this->instanceUrl() . '/cancel';
  126. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  127. $this->refreshFrom($response, $opts);
  128. return $this;
  129. }
  130. /**
  131. * @param null|array $params
  132. * @param null|array|string $opts
  133. *
  134. * @throws \Stripe\Exception\ApiErrorException if the request fails
  135. *
  136. * @return \Stripe\SubscriptionSchedule the released subscription schedule
  137. */
  138. public function release($params = null, $opts = null)
  139. {
  140. $url = $this->instanceUrl() . '/release';
  141. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  142. $this->refreshFrom($response, $opts);
  143. return $this;
  144. }
  145. }