SubscriptionItemService.php 5.7 KB

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