WebhookEndpoint.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * You can configure <a href="https://docs.stripe.com/webhooks/">webhook endpoints</a> via the API to be
  6. * notified about events that happen in your Stripe account or connected
  7. * accounts.
  8. *
  9. * Most users configure webhooks from <a href="https://dashboard.stripe.com/webhooks">the dashboard</a>, which provides a user interface for registering and testing your webhook endpoints.
  10. *
  11. * Related guide: <a href="https://docs.stripe.com/webhooks/configure">Setting up webhooks</a>
  12. *
  13. * @property string $id Unique identifier for the object.
  14. * @property string $object String representing the object's type. Objects of the same type share the same value.
  15. * @property null|string $api_version The API version events are rendered as for this webhook endpoint.
  16. * @property null|string $application The ID of the associated Connect application.
  17. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  18. * @property null|string $description An optional description of what the webhook is used for.
  19. * @property string[] $enabled_events The list of events to enable for this endpoint. <code>['*']</code> indicates that all events are enabled, except those that require explicit selection.
  20. * @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.
  21. * @property \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.
  22. * @property null|string $secret The endpoint's secret, used to generate <a href="https://docs.stripe.com/webhooks/signatures">webhook signatures</a>. Only returned at creation.
  23. * @property string $status The status of the webhook. It can be <code>enabled</code> or <code>disabled</code>.
  24. * @property string $url The URL of the webhook endpoint.
  25. */
  26. class WebhookEndpoint extends ApiResource
  27. {
  28. const OBJECT_NAME = 'webhook_endpoint';
  29. use ApiOperations\Update;
  30. /**
  31. * A webhook endpoint must have a <code>url</code> and a list of
  32. * <code>enabled_events</code>. You may optionally specify the Boolean
  33. * <code>connect</code> parameter. If set to true, then a Connect webhook endpoint
  34. * that notifies the specified <code>url</code> about events from all connected
  35. * accounts is created; otherwise an account webhook endpoint that notifies the
  36. * specified <code>url</code> only about events from your account is created. You
  37. * can also create webhook endpoints in the <a
  38. * href="https://dashboard.stripe.com/account/webhooks">webhooks settings</a>
  39. * section of the Dashboard.
  40. *
  41. * @param null|array $params
  42. * @param null|array|string $options
  43. *
  44. * @throws \Stripe\Exception\ApiErrorException if the request fails
  45. *
  46. * @return \Stripe\WebhookEndpoint the created resource
  47. */
  48. public static function create($params = null, $options = null)
  49. {
  50. self::_validateParams($params);
  51. $url = static::classUrl();
  52. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  53. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  54. $obj->setLastResponse($response);
  55. return $obj;
  56. }
  57. /**
  58. * You can also delete webhook endpoints via the <a
  59. * href="https://dashboard.stripe.com/account/webhooks">webhook endpoint
  60. * management</a> page of the Stripe dashboard.
  61. *
  62. * @param null|array $params
  63. * @param null|array|string $opts
  64. *
  65. * @throws \Stripe\Exception\ApiErrorException if the request fails
  66. *
  67. * @return \Stripe\WebhookEndpoint the deleted resource
  68. */
  69. public function delete($params = null, $opts = null)
  70. {
  71. self::_validateParams($params);
  72. $url = $this->instanceUrl();
  73. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  74. $this->refreshFrom($response, $opts);
  75. return $this;
  76. }
  77. /**
  78. * Returns a list of your webhook endpoints.
  79. *
  80. * @param null|array $params
  81. * @param null|array|string $opts
  82. *
  83. * @throws \Stripe\Exception\ApiErrorException if the request fails
  84. *
  85. * @return \Stripe\Collection<\Stripe\WebhookEndpoint> of ApiResources
  86. */
  87. public static function all($params = null, $opts = null)
  88. {
  89. $url = static::classUrl();
  90. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  91. }
  92. /**
  93. * Retrieves the webhook endpoint with the given ID.
  94. *
  95. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  96. * @param null|array|string $opts
  97. *
  98. * @throws \Stripe\Exception\ApiErrorException if the request fails
  99. *
  100. * @return \Stripe\WebhookEndpoint
  101. */
  102. public static function retrieve($id, $opts = null)
  103. {
  104. $opts = \Stripe\Util\RequestOptions::parse($opts);
  105. $instance = new static($id, $opts);
  106. $instance->refresh();
  107. return $instance;
  108. }
  109. /**
  110. * Updates the webhook endpoint. You may edit the <code>url</code>, the list of
  111. * <code>enabled_events</code>, and the status of your endpoint.
  112. *
  113. * @param string $id the ID of the resource to update
  114. * @param null|array $params
  115. * @param null|array|string $opts
  116. *
  117. * @throws \Stripe\Exception\ApiErrorException if the request fails
  118. *
  119. * @return \Stripe\WebhookEndpoint the updated resource
  120. */
  121. public static function update($id, $params = null, $opts = null)
  122. {
  123. self::_validateParams($params);
  124. $url = static::resourceUrl($id);
  125. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  126. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  127. $obj->setLastResponse($response);
  128. return $obj;
  129. }
  130. }