Subscription.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Subscription
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property float $application_fee_percent
  9. * @property string $billing
  10. * @property int $billing_cycle_anchor
  11. * @property bool $cancel_at_period_end
  12. * @property int $canceled_at
  13. * @property int $created
  14. * @property int current_period_end
  15. * @property int current_period_start
  16. * @property string $customer
  17. * @property int $days_until_due
  18. * @property Discount $discount
  19. * @property int $ended_at
  20. * @property Collection $items
  21. * @property boolean $livemode
  22. * @property StripeObject $metadata
  23. * @property Plan $plan
  24. * @property int $quantity
  25. * @property int $start
  26. * @property string $status
  27. * @property float $tax_percent
  28. * @property int $trial_end
  29. * @property int $trial_start
  30. *
  31. * @package Stripe
  32. */
  33. class Subscription extends ApiResource
  34. {
  35. const OBJECT_NAME = "subscription";
  36. use ApiOperations\All;
  37. use ApiOperations\Create;
  38. use ApiOperations\Delete {
  39. delete as protected _delete;
  40. }
  41. use ApiOperations\Retrieve;
  42. use ApiOperations\Update;
  43. /**
  44. * These constants are possible representations of the status field.
  45. *
  46. * @link https://stripe.com/docs/api#subscription_object-status
  47. */
  48. const STATUS_ACTIVE = 'active';
  49. const STATUS_CANCELED = 'canceled';
  50. const STATUS_PAST_DUE = 'past_due';
  51. const STATUS_TRIALING = 'trialing';
  52. const STATUS_UNPAID = 'unpaid';
  53. public static function getSavedNestedResources()
  54. {
  55. static $savedNestedResources = null;
  56. if ($savedNestedResources === null) {
  57. $savedNestedResources = new Util\Set([
  58. 'source',
  59. ]);
  60. }
  61. return $savedNestedResources;
  62. }
  63. /**
  64. * @param array|null $params
  65. *
  66. * @return Subscription The deleted subscription.
  67. */
  68. public function cancel($params = null, $opts = null)
  69. {
  70. return $this->_delete($params, $opts);
  71. }
  72. /**
  73. * @return Subscription The updated subscription.
  74. */
  75. public function deleteDiscount()
  76. {
  77. $url = $this->instanceUrl() . '/discount';
  78. list($response, $opts) = $this->_request('delete', $url);
  79. $this->refreshFrom(['discount' => null], $opts, true);
  80. }
  81. }