From 75160b12821f7f4299cce7f0b69c83c1502ae071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 27 May 2024 13:08:29 +0200 Subject: 2024-02-19 upstream --- vendor/stripe/stripe-php/lib/Subscription.php | 256 ++++++++++++++------------ 1 file changed, 139 insertions(+), 117 deletions(-) (limited to 'vendor/stripe/stripe-php/lib/Subscription.php') diff --git a/vendor/stripe/stripe-php/lib/Subscription.php b/vendor/stripe/stripe-php/lib/Subscription.php index a768ac1..38a6850 100644 --- a/vendor/stripe/stripe-php/lib/Subscription.php +++ b/vendor/stripe/stripe-php/lib/Subscription.php @@ -1,117 +1,139 @@ -Creating - * Subscriptions. - * - * @property string $id Unique identifier for the object. - * @property string $object String representing the object's type. Objects of the same type share the same value. - * @property null|float $application_fee_percent A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice subtotal that will be transferred to the application owner's Stripe account. - * @property \Stripe\StripeObject $automatic_tax - * @property int $billing_cycle_anchor Determines the date of the first full invoice, and, for plans with month or year intervals, the day of the month for subsequent invoices. - * @property null|\Stripe\StripeObject $billing_thresholds Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period - * @property null|int $cancel_at A date in the future at which the subscription will automatically get canceled - * @property bool $cancel_at_period_end If the subscription has been canceled with the at_period_end flag set to true, cancel_at_period_end on the subscription will be true. You can use this attribute to determine whether a subscription that has a status of active is scheduled to be canceled at the end of the current period. - * @property null|int $canceled_at If the subscription has been canceled, the date of that cancellation. If the subscription was canceled with cancel_at_period_end, canceled_at will reflect the time of the most recent update request, not the end of the subscription period when the subscription is automatically moved to a canceled state. - * @property null|string $collection_method Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions. - * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. - * @property int $current_period_end End of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created. - * @property int $current_period_start Start of the current period that the subscription has been invoiced for. - * @property string|\Stripe\Customer $customer ID of the customer who owns the subscription. - * @property null|int $days_until_due Number of days a customer has to pay invoices generated by this subscription. This value will be null for subscriptions where collection_method=charge_automatically. - * @property null|string|\Stripe\PaymentMethod $default_payment_method ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over default_source. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source. - * @property null|string|\Stripe\Account|\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source $default_source ID of the default payment source for the subscription. It must belong to the customer associated with the subscription and be in a chargeable state. If default_payment_method is also set, default_payment_method will take precedence. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source. - * @property null|\Stripe\TaxRate[] $default_tax_rates The tax rates that will apply to any subscription item that does not have tax_rates set. Invoices created will have their default_tax_rates populated from the subscription. - * @property null|\Stripe\Discount $discount Describes the current discount applied to this subscription, if there is one. When billing, a discount applied to a subscription overrides a discount applied on a customer-wide basis. - * @property null|int $ended_at If the subscription has ended, the date the subscription ended. - * @property \Stripe\Collection $items List of subscription items, each with an attached price. - * @property null|string|\Stripe\Invoice $latest_invoice The most recent invoice this subscription has generated. - * @property bool $livemode Has the value true if the object exists in live mode or the value false if the object exists in test mode. - * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. - * @property null|int $next_pending_invoice_item_invoice Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at pending_invoice_item_interval. - * @property null|\Stripe\StripeObject $pause_collection If specified, payment collection for this subscription will be paused. - * @property null|\Stripe\StripeObject $pending_invoice_item_interval Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling Create an invoice for the given subscription at the specified interval. - * @property null|string|\Stripe\SetupIntent $pending_setup_intent You can use this SetupIntent to collect user authentication when creating a subscription without immediate payment or updating a subscription's payment method, allowing you to optimize for off-session payments. Learn more in the SCA Migration Guide. - * @property null|\Stripe\StripeObject $pending_update If specified, pending updates that will be applied to the subscription once the latest_invoice has been paid. - * @property null|string|\Stripe\SubscriptionSchedule $schedule The schedule attached to the subscription - * @property int $start_date Date when the subscription was first created. The date might differ from the created date due to backdating. - * @property string $status

Possible values are incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid.

For collection_method=charge_automatically a subscription moves into incomplete if the initial payment attempt fails. A subscription in this state can only have metadata and default_source updated. Once the first invoice is paid, the subscription moves into an active state. If the first invoice is not paid within 23 hours, the subscription transitions to incomplete_expired. This is a terminal state, the open invoice will be voided and no further invoices will be generated.

A subscription that is currently in a trial period is trialing and moves to active when the trial period is over.

If subscription collection_method=charge_automatically it becomes past_due when payment to renew it fails and canceled or unpaid (depending on your subscriptions settings) when Stripe has exhausted all payment retry attempts.

If subscription collection_method=send_invoice it becomes past_due when its invoice is not paid by the due date, and canceled or unpaid if it is still not paid by an additional deadline after that. Note that when a subscription has a status of unpaid, no subsequent invoices will be attempted (invoices will be created, but then immediately automatically closed). After receiving updated payment information from a customer, you may choose to reopen and pay their closed invoices.

- * @property null|int $trial_end If the subscription has a trial, the end of that trial. - * @property null|int $trial_start If the subscription has a trial, the beginning of that trial. - */ -class Subscription extends ApiResource -{ - const OBJECT_NAME = 'subscription'; - - use ApiOperations\All; - use ApiOperations\Create; - use ApiOperations\Retrieve; - use ApiOperations\Update; - - const PAYMENT_BEHAVIOR_ALLOW_INCOMPLETE = 'allow_incomplete'; - const PAYMENT_BEHAVIOR_ERROR_IF_INCOMPLETE = 'error_if_incomplete'; - const PAYMENT_BEHAVIOR_PENDING_IF_INCOMPLETE = 'pending_if_incomplete'; - - const PRORATION_BEHAVIOR_ALWAYS_INVOICE = 'always_invoice'; - const PRORATION_BEHAVIOR_CREATE_PRORATIONS = 'create_prorations'; - const PRORATION_BEHAVIOR_NONE = 'none'; - - const STATUS_ACTIVE = 'active'; - const STATUS_CANCELED = 'canceled'; - const STATUS_INCOMPLETE = 'incomplete'; - const STATUS_INCOMPLETE_EXPIRED = 'incomplete_expired'; - const STATUS_PAST_DUE = 'past_due'; - const STATUS_TRIALING = 'trialing'; - const STATUS_UNPAID = 'unpaid'; - - use ApiOperations\Delete { - delete as protected _delete; - } - - public static function getSavedNestedResources() - { - static $savedNestedResources = null; - if (null === $savedNestedResources) { - $savedNestedResources = new Util\Set([ - 'source', - ]); - } - - return $savedNestedResources; - } - - /** - * @param null|array $params - * @param null|array|string $opts - * - * @throws \Stripe\Exception\ApiErrorException if the request fails - * - * @return \Stripe\Subscription the deleted subscription - */ - public function cancel($params = null, $opts = null) - { - return $this->_delete($params, $opts); - } - - /** - * @param null|array $params - * @param null|array|string $opts - * - * @throws \Stripe\Exception\ApiErrorException if the request fails - * - * @return \Stripe\Subscription the updated subscription - */ - public function deleteDiscount($params = null, $opts = null) - { - $url = $this->instanceUrl() . '/discount'; - list($response, $opts) = $this->_request('delete', $url, $params, $opts); - $this->refreshFrom(['discount' => null], $opts, true); - } -} +Creating + * Subscriptions. + * + * @property string $id Unique identifier for the object. + * @property string $object String representing the object's type. Objects of the same type share the same value. + * @property null|string|\Stripe\StripeObject $application ID of the Connect Application that created the subscription. + * @property null|float $application_fee_percent A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice subtotal that will be transferred to the application owner's Stripe account. + * @property \Stripe\StripeObject $automatic_tax + * @property int $billing_cycle_anchor Determines the date of the first full invoice, and, for plans with month or year intervals, the day of the month for subsequent invoices. + * @property null|\Stripe\StripeObject $billing_thresholds Define thresholds at which an invoice will be sent, and the subscription advanced to a new billing period + * @property null|int $cancel_at A date in the future at which the subscription will automatically get canceled + * @property bool $cancel_at_period_end If the subscription has been canceled with the at_period_end flag set to true, cancel_at_period_end on the subscription will be true. You can use this attribute to determine whether a subscription that has a status of active is scheduled to be canceled at the end of the current period. + * @property null|int $canceled_at If the subscription has been canceled, the date of that cancellation. If the subscription was canceled with cancel_at_period_end, canceled_at will reflect the time of the most recent update request, not the end of the subscription period when the subscription is automatically moved to a canceled state. + * @property string $collection_method Either charge_automatically, or send_invoice. When charging automatically, Stripe will attempt to pay this subscription at the end of the cycle using the default source attached to the customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions. + * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch. + * @property int $current_period_end End of the current period that the subscription has been invoiced for. At the end of this period, a new invoice will be created. + * @property int $current_period_start Start of the current period that the subscription has been invoiced for. + * @property string|\Stripe\Customer $customer ID of the customer who owns the subscription. + * @property null|int $days_until_due Number of days a customer has to pay invoices generated by this subscription. This value will be null for subscriptions where collection_method=charge_automatically. + * @property null|string|\Stripe\PaymentMethod $default_payment_method ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over default_source. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source. + * @property null|string|\Stripe\Account|\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source $default_source ID of the default payment source for the subscription. It must belong to the customer associated with the subscription and be in a chargeable state. If default_payment_method is also set, default_payment_method will take precedence. If neither are set, invoices will use the customer's invoice_settings.default_payment_method or default_source. + * @property null|\Stripe\TaxRate[] $default_tax_rates The tax rates that will apply to any subscription item that does not have tax_rates set. Invoices created will have their default_tax_rates populated from the subscription. + * @property null|\Stripe\Discount $discount Describes the current discount applied to this subscription, if there is one. When billing, a discount applied to a subscription overrides a discount applied on a customer-wide basis. + * @property null|int $ended_at If the subscription has ended, the date the subscription ended. + * @property \Stripe\Collection<\Stripe\SubscriptionItem> $items List of subscription items, each with an attached price. + * @property null|string|\Stripe\Invoice $latest_invoice The most recent invoice this subscription has generated. + * @property bool $livemode Has the value true if the object exists in live mode or the value false if the object exists in test mode. + * @property \Stripe\StripeObject $metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. + * @property null|int $next_pending_invoice_item_invoice Specifies the approximate timestamp on which any pending invoice items will be billed according to the schedule provided at pending_invoice_item_interval. + * @property null|\Stripe\StripeObject $pause_collection If specified, payment collection for this subscription will be paused. + * @property null|\Stripe\StripeObject $payment_settings Payment settings passed on to invoices created by the subscription. + * @property null|\Stripe\StripeObject $pending_invoice_item_interval Specifies an interval for how often to bill for any pending invoice items. It is analogous to calling Create an invoice for the given subscription at the specified interval. + * @property null|string|\Stripe\SetupIntent $pending_setup_intent You can use this SetupIntent to collect user authentication when creating a subscription without immediate payment or updating a subscription's payment method, allowing you to optimize for off-session payments. Learn more in the SCA Migration Guide. + * @property null|\Stripe\StripeObject $pending_update If specified, pending updates that will be applied to the subscription once the latest_invoice has been paid. + * @property null|string|\Stripe\SubscriptionSchedule $schedule The schedule attached to the subscription + * @property int $start_date Date when the subscription was first created. The date might differ from the created date due to backdating. + * @property string $status

Possible values are incomplete, incomplete_expired, trialing, active, past_due, canceled, or unpaid.

For collection_method=charge_automatically a subscription moves into incomplete if the initial payment attempt fails. A subscription in this state can only have metadata and default_source updated. Once the first invoice is paid, the subscription moves into an active state. If the first invoice is not paid within 23 hours, the subscription transitions to incomplete_expired. This is a terminal state, the open invoice will be voided and no further invoices will be generated.

A subscription that is currently in a trial period is trialing and moves to active when the trial period is over.

If subscription collection_method=charge_automatically it becomes past_due when payment to renew it fails and canceled or unpaid (depending on your subscriptions settings) when Stripe has exhausted all payment retry attempts.

If subscription collection_method=send_invoice it becomes past_due when its invoice is not paid by the due date, and canceled or unpaid if it is still not paid by an additional deadline after that. Note that when a subscription has a status of unpaid, no subsequent invoices will be attempted (invoices will be created, but then immediately automatically closed). After receiving updated payment information from a customer, you may choose to reopen and pay their closed invoices.

+ * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this subscription belongs to. + * @property null|int $trial_end If the subscription has a trial, the end of that trial. + * @property null|int $trial_start If the subscription has a trial, the beginning of that trial. + */ +class Subscription extends ApiResource +{ + const OBJECT_NAME = 'subscription'; + + use ApiOperations\All; + use ApiOperations\Create; + use ApiOperations\Retrieve; + use ApiOperations\Search; + use ApiOperations\Update; + + const PAYMENT_BEHAVIOR_ALLOW_INCOMPLETE = 'allow_incomplete'; + const PAYMENT_BEHAVIOR_DEFAULT_INCOMPLETE = 'default_incomplete'; + const PAYMENT_BEHAVIOR_ERROR_IF_INCOMPLETE = 'error_if_incomplete'; + const PAYMENT_BEHAVIOR_PENDING_IF_INCOMPLETE = 'pending_if_incomplete'; + + const PRORATION_BEHAVIOR_ALWAYS_INVOICE = 'always_invoice'; + const PRORATION_BEHAVIOR_CREATE_PRORATIONS = 'create_prorations'; + const PRORATION_BEHAVIOR_NONE = 'none'; + + const STATUS_ACTIVE = 'active'; + const STATUS_CANCELED = 'canceled'; + const STATUS_INCOMPLETE = 'incomplete'; + const STATUS_INCOMPLETE_EXPIRED = 'incomplete_expired'; + const STATUS_PAST_DUE = 'past_due'; + const STATUS_TRIALING = 'trialing'; + const STATUS_UNPAID = 'unpaid'; + + use ApiOperations\Delete { + delete as protected _delete; + } + + public static function getSavedNestedResources() + { + static $savedNestedResources = null; + if (null === $savedNestedResources) { + $savedNestedResources = new Util\Set([ + 'source', + ]); + } + + return $savedNestedResources; + } + + /** + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\Subscription the deleted subscription + */ + public function cancel($params = null, $opts = null) + { + return $this->_delete($params, $opts); + } + + /** + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\Subscription the updated subscription + */ + public function deleteDiscount($params = null, $opts = null) + { + $url = $this->instanceUrl() . '/discount'; + list($response, $opts) = $this->_request('delete', $url, $params, $opts); + $this->refreshFrom(['discount' => null], $opts, true); + + return $this; + } + + /** + * @param null|array $params + * @param null|array|string $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return \Stripe\SearchResult the subscription search results + */ + public static function search($params = null, $opts = null) + { + $url = '/v1/subscriptions/search'; + + return self::_searchResource($url, $params, $opts); + } +} -- cgit v1.2.3