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 all commits
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
COVERALLS_REPO_TOKEN:
secure: T0PmP8uyzCseacBCDRBlti2y9Tz5DL6fknea0MKWvbPYrzADmLY2/5kOTfYIsPUk
# If you bump this, don't forget to bump `MinimumMockVersion` in `StripeMockFixture.cs` as well.
STRIPE_MOCK_VERSION: 0.78.0
STRIPE_MOCK_VERSION: 0.79.0

deploy:
- provider: NuGet
Expand Down
12 changes: 12 additions & 0 deletions src/Stripe.net/Constants/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,18 @@ public static class Events
/// </summary>
public const string CustomerSubscriptionDeleted = "customer.subscription.deleted";

/// <summary>
/// Occurs whenever a customer's subscription's pending update is
/// applied, and the subscription is updated.
/// </summary>
public const string CustomerSubscriptionPendingUpdateApplied = "customer.subscription.pending_update_applied";

/// <summary>
/// Occurs whenever a customer's subscription's pending update expires
/// before the related invoice is paid.
/// </summary>
public const string CustomerSubscriptionPendingUpdateExpired = "customer.subscription.pending_update_expired";

/// <summary>
/// Occurs three days before the trial period of a subscription is scheduled to end.
/// </summary>
Expand Down
23 changes: 23 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,25 @@ 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
/// <see cref="CancelAtPeriodEnd" /> flag set to true,
/// <see cref="CancelAtPeriodEnd" /> 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
/// <see cref="CancelAtPeriodEnd" />, <see cref="CanceledAt" /> 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 +297,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 <see cref="LatestInvoice" /> 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
52 changes: 52 additions & 0 deletions src/Stripe.net/Entities/Subscriptions/SubscriptionPendingUpdate.cs
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 <c>year</c> intervals,
/// 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 List<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.TrialPeriodDays"/> 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 <see cref="TrialEnd"/> 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
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/Subscriptions/SubscriptionCreateOptions.cs
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
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/Subscriptions/SubscriptionUpdateOptions.cs
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
4 changes: 0 additions & 4 deletions src/StripeTests/Entities/Charges/ChargeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void DeserializeWithExpansions()
"application_fee",
"balance_transaction",
"customer",
"dispute",
"invoice",
"on_behalf_of",
"order",
Expand Down Expand Up @@ -59,9 +58,6 @@ public void DeserializeWithExpansions()
Assert.NotNull(charge.Customer);
Assert.Equal("customer", charge.Customer.Object);

Assert.NotNull(charge.Dispute);
Assert.Equal("dispute", charge.Dispute.Object);

Assert.NotNull(charge.Invoice);
Assert.Equal("invoice", charge.Invoice.Object);

Expand Down
2 changes: 1 addition & 1 deletion src/StripeTests/StripeMockFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class StripeMockFixture : IDisposable
/// If you bump this, don't forget to bump <c>STRIPE_MOCK_VERSION</c> in <c>appveyor.yml</c>
/// as well.
/// </remarks>
private const string MockMinimumVersion = "0.78.0";
private const string MockMinimumVersion = "0.79.0";

private readonly string port;

Expand Down