SubscriptionService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  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. * @param null|array $params
  57. * @param null|array|\Stripe\Util\RequestOptions $opts
  58. *
  59. * @throws \Stripe\Exception\ApiErrorException if the request fails
  60. *
  61. * @return \Stripe\Subscription
  62. */
  63. public function create($params = null, $opts = null)
  64. {
  65. return $this->request('post', '/v1/subscriptions', $params, $opts);
  66. }
  67. /**
  68. * Removes the currently applied discount on a subscription.
  69. *
  70. * @param string $id
  71. * @param null|array $params
  72. * @param null|array|\Stripe\Util\RequestOptions $opts
  73. *
  74. * @throws \Stripe\Exception\ApiErrorException if the request fails
  75. *
  76. * @return \Stripe\Subscription
  77. */
  78. public function deleteDiscount($id, $params = null, $opts = null)
  79. {
  80. return $this->request('delete', $this->buildPath('/v1/subscriptions/%s/discount', $id), $params, $opts);
  81. }
  82. /**
  83. * Retrieves the subscription with the given ID.
  84. *
  85. * @param string $id
  86. * @param null|array $params
  87. * @param null|array|\Stripe\Util\RequestOptions $opts
  88. *
  89. * @throws \Stripe\Exception\ApiErrorException if the request fails
  90. *
  91. * @return \Stripe\Subscription
  92. */
  93. public function retrieve($id, $params = null, $opts = null)
  94. {
  95. return $this->request('get', $this->buildPath('/v1/subscriptions/%s', $id), $params, $opts);
  96. }
  97. /**
  98. * Updates an existing subscription on a customer to match the specified
  99. * parameters. When changing plans or quantities, we will optionally prorate the
  100. * price we charge next month to make up for any price changes. To preview how the
  101. * proration will be calculated, use the <a href="#upcoming_invoice">upcoming
  102. * invoice</a> endpoint.
  103. *
  104. * @param string $id
  105. * @param null|array $params
  106. * @param null|array|\Stripe\Util\RequestOptions $opts
  107. *
  108. * @throws \Stripe\Exception\ApiErrorException if the request fails
  109. *
  110. * @return \Stripe\Subscription
  111. */
  112. public function update($id, $params = null, $opts = null)
  113. {
  114. return $this->request('post', $this->buildPath('/v1/subscriptions/%s', $id), $params, $opts);
  115. }
  116. }