Subscription.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Subscription
  5. *
  6. * @package Stripe
  7. */
  8. class Subscription extends ApiResource
  9. {
  10. /**
  11. * These constants are possible representations of the status field.
  12. *
  13. * @link https://stripe.com/docs/api#subscription_object-status
  14. */
  15. const STATUS_ACTIVE = 'active';
  16. const STATUS_CANCELED = 'canceled';
  17. const STATUS_PAST_DUE = 'past_due';
  18. const STATUS_TRIALING = 'trialing';
  19. const STATUS_UNPAID = 'unpaid';
  20. /**
  21. * @param string $id The ID of the subscription to retrieve.
  22. * @param array|string|null $opts
  23. *
  24. * @return Subscription
  25. */
  26. public static function retrieve($id, $opts = null)
  27. {
  28. return self::_retrieve($id, $opts);
  29. }
  30. /**
  31. * @param array|null $params
  32. * @param array|string|null $opts
  33. *
  34. * @return Collection of Subscriptions
  35. */
  36. public static function all($params = null, $opts = null)
  37. {
  38. return self::_all($params, $opts);
  39. }
  40. /**
  41. * @param array|null $params
  42. * @param array|string|null $opts
  43. *
  44. * @return Subscription The created subscription.
  45. */
  46. public static function create($params = null, $opts = null)
  47. {
  48. return self::_create($params, $opts);
  49. }
  50. /**
  51. * @param string $id The ID of the subscription to retrieve.
  52. * @param array|null $params
  53. * @param array|string|null $options
  54. *
  55. * @return Subscription The updated subscription.
  56. */
  57. public static function update($id, $params = null, $options = null)
  58. {
  59. return self::_update($id, $params, $options);
  60. }
  61. /**
  62. * @param array|null $params
  63. *
  64. * @return Subscription The deleted subscription.
  65. */
  66. public function cancel($params = null, $opts = null)
  67. {
  68. return $this->_delete($params, $opts);
  69. }
  70. /**
  71. * @param array|string|null $opts
  72. *
  73. * @return Subscription The saved subscription.
  74. */
  75. public function save($opts = null)
  76. {
  77. return $this->_save($opts);
  78. }
  79. /**
  80. * @return Subscription The updated subscription.
  81. */
  82. public function deleteDiscount()
  83. {
  84. $url = $this->instanceUrl() . '/discount';
  85. list($response, $opts) = $this->_request('delete', $url);
  86. $this->refreshFrom(array('discount' => null), $opts, true);
  87. }
  88. }