TestClock.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\TestHelpers;
  4. /**
  5. * A test clock enables deterministic control over objects in testmode. With a test clock, you can create
  6. * objects at a frozen time in the past or future, and advance to a specific future time to observe webhooks and state changes. After the clock advances,
  7. * you can either validate the current state of your scenario (and test your assumptions), change the current state of your scenario (and test more complex scenarios), or keep advancing forward in time.
  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 int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  12. * @property int $deletes_after Time at which this clock is scheduled to auto delete.
  13. * @property int $frozen_time Time at which all objects belonging to this clock are frozen.
  14. * @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.
  15. * @property null|string $name The custom name supplied at creation.
  16. * @property string $status The status of the Test Clock.
  17. */
  18. class TestClock extends \Stripe\ApiResource
  19. {
  20. const OBJECT_NAME = 'test_helpers.test_clock';
  21. const STATUS_ADVANCING = 'advancing';
  22. const STATUS_INTERNAL_FAILURE = 'internal_failure';
  23. const STATUS_READY = 'ready';
  24. /**
  25. * Creates a new test clock that can be attached to new customers and quotes.
  26. *
  27. * @param null|array $params
  28. * @param null|array|string $options
  29. *
  30. * @throws \Stripe\Exception\ApiErrorException if the request fails
  31. *
  32. * @return \Stripe\TestHelpers\TestClock the created resource
  33. */
  34. public static function create($params = null, $options = null)
  35. {
  36. self::_validateParams($params);
  37. $url = static::classUrl();
  38. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  39. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  40. $obj->setLastResponse($response);
  41. return $obj;
  42. }
  43. /**
  44. * Deletes a test clock.
  45. *
  46. * @param null|array $params
  47. * @param null|array|string $opts
  48. *
  49. * @throws \Stripe\Exception\ApiErrorException if the request fails
  50. *
  51. * @return \Stripe\TestHelpers\TestClock the deleted resource
  52. */
  53. public function delete($params = null, $opts = null)
  54. {
  55. self::_validateParams($params);
  56. $url = $this->instanceUrl();
  57. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  58. $this->refreshFrom($response, $opts);
  59. return $this;
  60. }
  61. /**
  62. * Returns a list of your test clocks.
  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\TestHelpers\TestClock> 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 a test clock.
  78. *
  79. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  80. * @param null|array|string $opts
  81. *
  82. * @throws \Stripe\Exception\ApiErrorException if the request fails
  83. *
  84. * @return \Stripe\TestHelpers\TestClock
  85. */
  86. public static function retrieve($id, $opts = null)
  87. {
  88. $opts = \Stripe\Util\RequestOptions::parse($opts);
  89. $instance = new static($id, $opts);
  90. $instance->refresh();
  91. return $instance;
  92. }
  93. /**
  94. * @param null|array $params
  95. * @param null|array|string $opts
  96. *
  97. * @throws \Stripe\Exception\ApiErrorException if the request fails
  98. *
  99. * @return \Stripe\TestHelpers\TestClock the advanced test clock
  100. */
  101. public function advance($params = null, $opts = null)
  102. {
  103. $url = $this->instanceUrl() . '/advance';
  104. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  105. $this->refreshFrom($response, $opts);
  106. return $this;
  107. }
  108. }