SubscriptionItemService.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. /**
  5. * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  6. * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  7. */
  8. class SubscriptionItemService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of your subscription items for a given subscription.
  12. *
  13. * @param null|array $params
  14. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  15. *
  16. * @throws \Stripe\Exception\ApiErrorException if the request fails
  17. *
  18. * @return \Stripe\Collection<\Stripe\SubscriptionItem>
  19. */
  20. public function all($params = null, $opts = null)
  21. {
  22. return $this->requestCollection('get', '/v1/subscription_items', $params, $opts);
  23. }
  24. /**
  25. * For the specified subscription item, returns a list of summary objects. Each
  26. * object in the list provides usage information that’s been summarized from
  27. * multiple usage records and over a subscription billing period (e.g., 15 usage
  28. * records in the month of September).
  29. *
  30. * The list is sorted in reverse-chronological order (newest first). The first list
  31. * item represents the most current usage period that hasn’t ended yet. Since new
  32. * usage records can still be added, the returned summary information for the
  33. * subscription item’s ID should be seen as unstable until the subscription billing
  34. * period ends.
  35. *
  36. * @param string $parentId
  37. * @param null|array $params
  38. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  39. *
  40. * @throws \Stripe\Exception\ApiErrorException if the request fails
  41. *
  42. * @return \Stripe\Collection<\Stripe\UsageRecordSummary>
  43. */
  44. public function allUsageRecordSummaries($parentId, $params = null, $opts = null)
  45. {
  46. return $this->requestCollection('get', $this->buildPath('/v1/subscription_items/%s/usage_record_summaries', $parentId), $params, $opts);
  47. }
  48. /**
  49. * Adds a new item to an existing subscription. No existing items will be changed
  50. * or replaced.
  51. *
  52. * @param null|array $params
  53. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  54. *
  55. * @throws \Stripe\Exception\ApiErrorException if the request fails
  56. *
  57. * @return \Stripe\SubscriptionItem
  58. */
  59. public function create($params = null, $opts = null)
  60. {
  61. return $this->request('post', '/v1/subscription_items', $params, $opts);
  62. }
  63. /**
  64. * Creates a usage record for a specified subscription item and date, and fills it
  65. * with a quantity.
  66. *
  67. * Usage records provide <code>quantity</code> information that Stripe uses to
  68. * track how much a customer is using your service. With usage information and the
  69. * pricing model set up by the <a
  70. * href="https://stripe.com/docs/billing/subscriptions/metered-billing">metered
  71. * billing</a> plan, Stripe helps you send accurate invoices to your customers.
  72. *
  73. * The default calculation for usage is to add up all the <code>quantity</code>
  74. * values of the usage records within a billing period. You can change this default
  75. * behavior with the billing plan’s <code>aggregate_usage</code> <a
  76. * href="/docs/api/plans/create#create_plan-aggregate_usage">parameter</a>. When
  77. * there is more than one usage record with the same timestamp, Stripe adds the
  78. * <code>quantity</code> values together. In most cases, this is the desired
  79. * resolution, however, you can change this behavior with the <code>action</code>
  80. * parameter.
  81. *
  82. * The default pricing model for metered billing is <a
  83. * href="/docs/api/plans/object#plan_object-billing_scheme">per-unit pricing</a>.
  84. * For finer granularity, you can configure metered billing to have a <a
  85. * href="https://stripe.com/docs/billing/subscriptions/tiers">tiered pricing</a>
  86. * model.
  87. *
  88. * @param string $parentId
  89. * @param null|array $params
  90. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  91. *
  92. * @throws \Stripe\Exception\ApiErrorException if the request fails
  93. *
  94. * @return \Stripe\UsageRecord
  95. */
  96. public function createUsageRecord($parentId, $params = null, $opts = null)
  97. {
  98. return $this->request('post', $this->buildPath('/v1/subscription_items/%s/usage_records', $parentId), $params, $opts);
  99. }
  100. /**
  101. * Deletes an item from the subscription. Removing a subscription item from a
  102. * subscription will not cancel the subscription.
  103. *
  104. * @param string $id
  105. * @param null|array $params
  106. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  107. *
  108. * @throws \Stripe\Exception\ApiErrorException if the request fails
  109. *
  110. * @return \Stripe\SubscriptionItem
  111. */
  112. public function delete($id, $params = null, $opts = null)
  113. {
  114. return $this->request('delete', $this->buildPath('/v1/subscription_items/%s', $id), $params, $opts);
  115. }
  116. /**
  117. * Retrieves the subscription item with the given ID.
  118. *
  119. * @param string $id
  120. * @param null|array $params
  121. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  122. *
  123. * @throws \Stripe\Exception\ApiErrorException if the request fails
  124. *
  125. * @return \Stripe\SubscriptionItem
  126. */
  127. public function retrieve($id, $params = null, $opts = null)
  128. {
  129. return $this->request('get', $this->buildPath('/v1/subscription_items/%s', $id), $params, $opts);
  130. }
  131. /**
  132. * Updates the plan or quantity of an item on a current subscription.
  133. *
  134. * @param string $id
  135. * @param null|array $params
  136. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  137. *
  138. * @throws \Stripe\Exception\ApiErrorException if the request fails
  139. *
  140. * @return \Stripe\SubscriptionItem
  141. */
  142. public function update($id, $params = null, $opts = null)
  143. {
  144. return $this->request('post', $this->buildPath('/v1/subscription_items/%s', $id), $params, $opts);
  145. }
  146. }