Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PendingUpdate and ProrationBehavior on Subscription APIs. #1895

Merged
merged 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Stripe.net/Entities/Subscriptions/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,24 @@ public class Subscription : StripeEntity<Subscription>, IHasId, IHasMetadata, IH
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? CancelAt { get; set; }

/// <summary>
/// If the subscription has been canceled with the <c>AtPeriodEnd</c> flag
/// set to true, <c>CancelAtPeriodEnd</c> 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.
/// </summary>
[JsonProperty("cancel_at_period_end")]
public bool CancelAtPeriodEnd { get; set; }

/// <summary>
/// If the subscription has been canceled, the date of that
/// cancellation. If the subscription was canceled with
/// <c>CancelAtPeriodEnd</c>, <c>CanceledAt</c> will still reflect the
/// date of the initial cancellation request, not the end of the
/// subscription period when the subscription is automatically moved to
/// a canceled state.
/// </summary>
[JsonProperty("canceled_at")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? CanceledAt { get; set; }
Expand Down Expand Up @@ -281,6 +296,13 @@ public SetupIntent PendingSetupIntent
internal ExpandableField<SetupIntent> InternalPendingSetupIntent { get; set; }
#endregion

/// <summary>
/// If specified, deferred upgrade changes that will be applied to the
/// subscription once the latest_invoice has been paid.
/// </summary>
[JsonProperty("pending_update")]
public SubscriptionPendingUpdate PendingUpdate { get; set; }

/// <summary>
/// Plan the customer is subscribed to. Only set if the subscription contains a single plan.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class SubscriptionPendingUpdate : StripeEntity<SubscriptionPendingUpdate>
{
/// <summary>
/// If the update is applied, determines the date of the first full
/// invoice, and, for plans with <c>month</c> or year <c>intervals</c>,
/// the day of the month for subsequent invoices.
/// </summary>
[JsonProperty("billing_cycle_anchor")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? BillingCycleAnchor { get; set; }

/// <summary>
/// The point after which the changes reflected by this update will be
/// discarded and no longer applied.
/// </summary>
[JsonProperty("expires_at")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? ExpiresAt { get; set; }

/// <summary>
/// List of subscription items, each with an attached plan, that will
/// be set if the update is applied.
/// </summary>
[JsonProperty("subscription_items")]
public StripeList<SubscriptionItem> SubscriptionItems { get; set; }

/// <summary>
/// Unix timestamp representing the end of the trial period the
/// customer will get before being charged for the first time, if the
/// update is applied.
/// </summary>
[JsonProperty("trial_end")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime? TrialEnd { get; set; }

/// <summary>
/// Indicates if a <see cref="Plan" />’s <c>TrialPeriodDays</c> should
/// be applied to the subscription. Setting <see cref="TrialEnd" /> per
/// subscription is preferred, and this defaults to false. Setting this
/// flag to true together with trial_end is not allowed.
/// </summary>
[JsonProperty("trial_from_plan")]
public bool TrialFromPlan { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/Invoices/UpcomingInvoiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ public class UpcomingInvoiceOptions : BaseOptions
[JsonProperty("subscription_prorate")]
public bool? SubscriptionProrate { get; set; }

/// <summary>
/// Determines how to handle
/// <a href="https://stripe.com/docs/billing/subscriptions/billing-cycle#prorations">prorations</a>
/// when the billing cycle changes. The value defaults to
/// <c>create_prorations</c>, indicating that proration invoice items
/// should be created. Prorations can be disabled by setting the value
/// to <c>none</c>.
/// </summary>
[JsonProperty("subscription_proration_behavior")]
public string SubscriptionProrationBehavior { get; set; }

/// <summary>
/// If previewing an update to a subscription, and doing proration,
/// <c>subscription_proration_date</c> forces the proration to be calculated as though the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ public class SubscriptionItemCreateOptions : BaseOptions, IHasMetadata
[JsonProperty("prorate")]
public bool? Prorate { get; set; }

/// <summary>
/// Determines how to handle
/// <a href="https://stripe.com/docs/billing/subscriptions/billing-cycle#prorations">prorations</a>
/// when the billing cycle changes. The value defaults to
/// <c>create_prorations</c>, indicating that proration invoice items should
/// be created. Prorations can be disabled by setting the value to
/// <c>none</c>.
/// </summary>
[JsonProperty("proration_behavior")]
public string ProrationBehavior { get; set; }

/// <summary>
/// If set, the proration will be calculated as though the subscription was updated at the
/// given time. This can be used to apply the same proration that was previewed with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public class SubscriptionItemUpdateOptions : BaseOptions, IHasMetadata
[JsonProperty("prorate")]
public bool? Prorate { get; set; }

/// <summary>
/// Determines how to handle
/// <a href="https://stripe.com/docs/billing/subscriptions/billing-cycle#prorations">prorations</a>
/// when the billing cycle changes. The value defaults to
/// <c>create_prorations</c>, indicating that proration invoice items should
/// be created. Prorations can be disabled by setting the value to
/// <c>none</c>.
/// </summary>
[JsonProperty("proration_behavior")]
public string ProrationBehavior { get; set; }

/// <summary>
/// If set, the proration will be calculated as though the subscription was updated at the
/// given time. This can be used to apply the same proration that was previewed with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ public class SubscriptionCreateOptions : BaseOptions, IHasMetadata
[JsonProperty("prorate")]
public bool? Prorate { get; set; }

/// <summary>
/// Determines how to handle
/// <a href="https://stripe.com/docs/billing/subscriptions/billing-cycle#prorations">prorations</a>
/// when the billing cycle changes. The value defaults to
/// <c>create_prorations</c>, indicating that proration invoice items
/// should be created. Prorations can be disabled by setting the value
/// to <c>none</c>.
/// </summary>
[JsonProperty("proration_behavior")]
public string ProrationBehavior { get; set; }

[Obsolete("Use Items")]
[JsonProperty("quantity")]
public long? Quantity { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ public class SubscriptionUpdateOptions : BaseOptions, IHasMetadata
[JsonProperty("prorate")]
public bool? Prorate { get; set; }

/// <summary>
/// Determines how to handle
/// <a href="https://stripe.com/docs/billing/subscriptions/billing-cycle#prorations">prorations</a>
/// when the billing cycle changes. The value defaults to
/// <c>create_prorations</c>, indicating that proration invoice items
/// should be created. Prorations can be disabled by setting the value
/// to <c>none</c>.
/// </summary>
[JsonProperty("proration_behavior")]
public string ProrationBehavior { get; set; }

/// <summary>
/// If set, the proration will be calculated as though the subscription
/// was updated at the given time. This can be used to apply exactly
Expand Down