SubscriptionService.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. class SubscriptionService extends \Stripe\Service\AbstractService
  5. {
  6. /**
  7. * By default, returns a list of subscriptions that have not been canceled. In
  8. * order to list canceled subscriptions, specify <code>status=canceled</code>.
  9. *
  10. * @param null|array $params
  11. * @param null|array|\Stripe\Util\RequestOptions $opts
  12. *
  13. * @throws \Stripe\Exception\ApiErrorException if the request fails
  14. *
  15. * @return \Stripe\Collection<\Stripe\Subscription>
  16. */
  17. public function all($params = null, $opts = null)
  18. {
  19. return $this->requestCollection('get', '/v1/subscriptions', $params, $opts);
  20. }
  21. /**
  22. * Cancels a customer’s subscription immediately. The customer will not be charged
  23. * again for the subscription.
  24. *
  25. * Note, however, that any pending invoice items that you’ve created will still be
  26. * charged for at the end of the period, unless manually <a
  27. * href="#delete_invoiceitem">deleted</a>. If you’ve set the subscription to cancel
  28. * at the end of the period, any pending prorations will also be left in place and
  29. * collected at the end of the period. But if the subscription is set to cancel
  30. * immediately, pending prorations will be removed.
  31. *
  32. * By default, upon subscription cancellation, Stripe will stop automatic
  33. * collection of all finalized invoices for the customer. This is intended to
  34. * prevent unexpected payment attempts after the customer has canceled a
  35. * subscription. However, you can resume automatic collection of the invoices
  36. * manually after subscription cancellation to have us proceed. Or, you could check
  37. * for unpaid invoices before allowing the customer to cancel the subscription at
  38. * all.
  39. *
  40. * @param string $id
  41. * @param null|array $params
  42. * @param null|array|\Stripe\Util\RequestOptions $opts
  43. *
  44. * @throws \Stripe\Exception\ApiErrorException if the request fails
  45. *
  46. * @return \Stripe\Subscription
  47. */
  48. public function cancel($id, $params = null, $opts = null)
  49. {
  50. return $this->request('delete', $this->buildPath('/v1/subscriptions/%s', $id), $params, $opts);
  51. }
  52. /**
  53. * Creates a new subscription on an existing customer. Each customer can have up to
  54. * 500 active or scheduled subscriptions.
  55. *
  56. * When you create a subscription with
  57. * <code>collection_method=charge_automatically</code>, the first invoice is
  58. * finalized as part of the request. The <code>payment_behavior</code> parameter
  59. * determines the exact behavior of the initial payment.
  60. *
  61. * To start subscriptions where the first invoice always begins in a
  62. * <code>draft</code> status, use <a
  63. * href="/docs/billing/subscriptions/subscription-schedules#managing">subscription
  64. * schedules</a> instead. Schedules provide the flexibility to model more complex
  65. * billing configurations that change over time.
  66. *
  67. * @param null|array $params
  68. * @param null|array|\Stripe\Util\RequestOptions $opts
  69. *
  70. * @throws \Stripe\Exception\ApiErrorException if the request fails
  71. *
  72. * @return \Stripe\Subscription
  73. */
  74. public function create($params = null, $opts = null)
  75. {
  76. return $this->request('post', '/v1/subscriptions', $params, $opts);
  77. }
  78. /**
  79. * Removes the currently applied discount on a subscription.
  80. *
  81. * @param string $id
  82. * @param null|array $params
  83. * @param null|array|\Stripe\Util\RequestOptions $opts
  84. *
  85. * @throws \Stripe\Exception\ApiErrorException if the request fails
  86. *
  87. * @return \Stripe\Subscription
  88. */
  89. public function deleteDiscount($id, $params = null, $opts = null)
  90. {
  91. return $this->request('delete', $this->buildPath('/v1/subscriptions/%s/discount', $id), $params, $opts);
  92. }
  93. /**
  94. * Retrieves the subscription with the given ID.
  95. *
  96. * @param string $id
  97. * @param null|array $params
  98. * @param null|array|\Stripe\Util\RequestOptions $opts
  99. *
  100. * @throws \Stripe\Exception\ApiErrorException if the request fails
  101. *
  102. * @return \Stripe\Subscription
  103. */
  104. public function retrieve($id, $params = null, $opts = null)
  105. {
  106. return $this->request('get', $this->buildPath('/v1/subscriptions/%s', $id), $params, $opts);
  107. }
  108. /**
  109. * Updates an existing subscription on a customer to match the specified
  110. * parameters. When changing plans or quantities, we will optionally prorate the
  111. * price we charge next month to make up for any price changes. To preview how the
  112. * proration will be calculated, use the <a href="#upcoming_invoice">upcoming
  113. * invoice</a> endpoint.
  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\Subscription
  122. */
  123. public function update($id, $params = null, $opts = null)
  124. {
  125. return $this->request('post', $this->buildPath('/v1/subscriptions/%s', $id), $params, $opts);
  126. }
  127. }