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 the Price resource and APIs #2010

Merged
merged 1 commit into from
Apr 29, 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.88.0
STRIPE_MOCK_VERSION: 0.89.0

deploy:
- provider: NuGet
Expand Down
15 changes: 15 additions & 0 deletions src/Stripe.net/Constants/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,21 @@ public static class Events
/// </summary>
public const string PlanUpdated = "plan.updated";

/// <summary>
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
/// Occurs whenever a price is created.
/// </summary>
public const string PriceCreated = "price.created";

/// <summary>
/// Occurs whenever a price is deleted.
/// </summary>
public const string PriceDeleted = "price.deleted";

/// <summary>
/// Occurs whenever a price is updated.
/// </summary>
public const string PriceUpdated = "price.updated";

/// <summary>
/// Occurs whenever a product is created.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Stripe.net/Entities/InvoiceItems/InvoiceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public Invoice Invoice
[JsonProperty("plan")]
public Plan Plan { get; set; }

/// <summary>
/// The price associated with the invoice item.
/// </summary>
[JsonProperty("price")]
public Price Price { get; set; }

/// <summary>
/// Whether the invoice item was created automatically as a proration adjustment when the
/// customer switched plans.
Expand Down
6 changes: 6 additions & 0 deletions src/Stripe.net/Entities/Invoices/InvoiceLineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class InvoiceLineItem : StripeEntity<InvoiceLineItem>, IHasId, IHasMetada
[JsonProperty("plan")]
public Plan Plan { get; set; }

/// <summary>
/// The price associated with the invoice line item.
/// </summary>
[JsonProperty("price")]
public Price Price { get; set; }

[JsonProperty("proration")]
public bool Proration { get; set; }

Expand Down
162 changes: 162 additions & 0 deletions src/Stripe.net/Entities/Prices/Price.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class Price : StripeEntity<Price>, IHasId, IHasMetadata, IHasObject
{
/// <summary>
/// Unique identifier for the object.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// String representing the object’s type. Objects of the same type share the same value.
/// </summary>
[JsonProperty("object")]
public string Object { get; set; }

/// <summary>
/// Whether the price can be used for new purchases.
/// </summary>
[JsonProperty("active")]
public bool Active { get; set; }

/// <summary>
/// Describes how to compute the price per period. Either <c>per_unit</c> or <c>tiered</c>.
/// <c>per_unit</c> indicates that the fixed amount (specified in <see cref="UnitAmount"/>
/// or <see cref="UnitAmountDecimal"/> will be charged per unit in <c>quantity</c> (for
/// prices with <see cref="PriceRecurring.UsageType"/> set to <c>licensed</c>), or per unit
/// of total usage (for prices with <see cref="PriceRecurring.UsageType"/> set to
/// <c>metered</c>). <c>tiered</c> indicates that the unit pricing will be computed using a
/// tiering strategy as defined using the <see cref="Tiers"/> and <see cref="TiersMode"/>
/// attributes.
/// </summary>
[JsonProperty("billing_scheme")]
public string BillingScheme { get; set; }

/// <summary>
/// Time at which the object was created. Measured in seconds since the Unix epoch.
/// </summary>
[JsonProperty("created")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime Created { get; set; }

/// <summary>
/// Three-letter ISO currency code, in lowercase. Must be a supported currency.
/// </summary>
[JsonProperty("currency")]
public string Currency { get; set; }

/// <summary>
/// Whether this object is deleted or not.
/// </summary>
[JsonProperty("deleted", NullValueHandling=NullValueHandling.Ignore)]
public bool? Deleted { get; set; }

/// <summary>
/// Has the value <c>true</c> if the object exists in live mode or the value
/// <c>false</c> if the object exists in test mode.
/// </summary>
[JsonProperty("livemode")]
public bool Livemode { get; set; }

/// <summary>
/// A lookup key used to retrieve prices dynamically from a static string.
/// </summary>
[JsonProperty("lookup_key")]
public string LookupKey { get; set; }

/// <summary>
/// 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.
/// </summary>
[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// A brief description of the price, hidden from customers.
/// </summary>
[JsonProperty("nickname")]
public string Nickname { get; set; }

#region Expandable Product

/// <summary>
/// ID of the product linked to this price.
/// </summary>
[JsonIgnore]
public string ProductId
{
get => this.InternalProduct?.Id;
set => this.InternalProduct = SetExpandableFieldId(value, this.InternalProduct);
}

/// <summary>
/// (Expanded) The product linked to this price (if it was expanded).
/// </summary>
[JsonIgnore]
public Product Product
{
get => this.InternalProduct?.ExpandedObject;
set => this.InternalProduct = SetExpandableFieldObject(value, this.InternalProduct);
}

[JsonProperty("product")]
[JsonConverter(typeof(ExpandableFieldConverter<Product>))]
internal ExpandableField<Product> InternalProduct { get; set; }
#endregion

/// <summary>
/// The recurring components of a price such as its interval.
/// </summary>
[JsonProperty("recurring")]
public PriceRecurring Recurring { get; set; }

/// <summary>
/// Each element represents a pricing tier. This parameter requires <see cref="BillingScheme"/>
/// to be set to <c>tiered</c>.
/// </summary>
[JsonProperty("tiers")]
public List<PriceTier> Tiers { get; set; }

/// <summary>
/// Defines if the tiering price should be <c>graduated</c> or <c>volume</c> based. In
/// volume-based tiering, the maximum quantity within a period determines the per unit
/// price, in <c>graduated</c> tiering pricing can successively change as the quantity
/// grows.
/// </summary>
[JsonProperty("tiers_mode")]
public string TiersMode { get; set; }

/// <summary>
/// Apply a transformation to the reported usage or set quantity before computing the
/// billed price. Cannot be combined with <see cref="Tiers"/>.
/// </summary>
[JsonProperty("transform_quantity")]
public PriceTransformQuantity TransformQuantity { get; set; }

/// <summary>
/// One of <c>one_time</c> or <c>recurring</c> depending on whether the price is for a
/// one-time purchase or a recurring (subscription) purchase.
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

/// <summary>
/// The amount in cents to be charged on the interval specified.
/// </summary>
[JsonProperty("unit_amount")]
public long? UnitAmount { get; set; }

/// <summary>
/// Same as <see cref="UnitAmount"/>, but contains a decimal value with at most 12 decimal
/// places.
/// </summary>
[JsonProperty("unit_amount_decimal")]
public decimal? UnitAmountDecimal { get; set; }
}
}
48 changes: 48 additions & 0 deletions src/Stripe.net/Entities/Prices/PriceRecurring.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Stripe
{
using Newtonsoft.Json;

public class PriceRecurring : StripeEntity<PriceRecurring>
{
/// <summary>
/// Specifies a usage aggregation strategy for prices where <see cref="UsageType"/> is
/// <c>metered</c>. Allowed values are <c>sum</c> for summing up all usage during a period,
/// <c>last_during_period</c> for picking the last usage record reported within a period,
/// <c>last_ever</c> for picking the last usage record ever (across period bounds) or
/// <c>max</c> which picks the usage record with the maximum reported usage during a
/// period. Defaults to <c>sum</c>.
/// </summary>
[JsonProperty("aggregate_usage")]
public string AggregateUsage { get; set; }

/// <summary>
/// he frequency at which a subscription is billed. One of <c>day</c>, <c>week</c>,
/// <c>month</c> or <c>year</c>.
/// </summary>
[JsonProperty("interval")]
public string Interval { get; set; }

/// <summary>
/// The number of intervals (specified in the <see cref="Interval"/> property) between
/// subscription billings.
/// </summary>
[JsonProperty("interval_count")]
public long IntervalCount { get; set; }

/// <summary>
/// Default number of trial days when subscribing a customer to this price using
/// <c>trial_from_price=true</c>.
/// </summary>
[JsonProperty("trial_period_days")]
public long? TrialPeriodDays { get; set; }

/// <summary>
/// Configures how the quantity per period should be determined, can be either
/// <c>metered</c> or <c>licensed</c>. <c>licensed</c> will automatically bill the quantity
/// set for a price when adding it to a subscription, <c>metered</c> will aggregate the
/// total usage based on usage records. Defaults to <c>licensed</c>.
/// </summary>
[JsonProperty("usage_type")]
public string UsageType { get; set; }
}
}
40 changes: 40 additions & 0 deletions src/Stripe.net/Entities/Prices/PriceTier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Stripe
{
using System;
using Newtonsoft.Json;

public class PriceTier : StripeEntity<PriceTier>
{
/// <summary>
/// Price for the entire tier.
/// </summary>
[JsonProperty("flat_amount")]
public long? FlatAmount { get; set; }

/// <summary>
/// Same as <see cref="FlatAmount"/>, but contains a decimal value with at most 12 decimal
/// places.
/// </summary>
[JsonProperty("flat_amount_decimal")]
public decimal? FlatAmountDecimal { get; set; }

/// <summary>
/// Per unit price for units relevant to the tier.
/// </summary>
[JsonProperty("unit_amount")]
public long? UnitAmount { get; set; }

/// <summary>
/// Same as <see cref="UnitAmount"/>, but contains a decimal value with at most 12 decimal
/// places.
/// </summary>
[JsonProperty("unit_amount_decimal")]
public decimal? UnitAmountDecimal { get; set; }

/// <summary>
/// Up to and including to this quantity will be contained in the tier.
/// </summary>
[JsonProperty("up_to")]
public long? UpTo { get; set; }
}
}
19 changes: 19 additions & 0 deletions src/Stripe.net/Entities/Prices/PriceTransformQuantity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Stripe
{
using Newtonsoft.Json;

public class PriceTransformQuantity : StripeEntity<PriceTransformQuantity>
{
/// <summary>
/// Divide usage by this number.
/// </summary>
[JsonProperty("divide_by")]
public long DivideBy { get; set; }

/// <summary>
/// After division, either round the result <c>up</c> or <c>down</c>.
/// </summary>
[JsonProperty("round")]
public string Round { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/Stripe.net/Entities/SubscriptionItems/SubscriptionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class SubscriptionItem : StripeEntity<SubscriptionItem>, IHasId, IHasMeta
[JsonProperty("plan")]
public Plan Plan { get; set; }

/// <summary>
/// The price associated with the subscription item.
/// </summary>
[JsonProperty("price")]
public Price Price { get; set; }

[JsonProperty("quantity")]
public long Quantity { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ namespace Stripe

public class SubscriptionSchedulePhase : StripeEntity<SubscriptionSchedulePhase>
{
/// <summary>
/// A list of prices and quantities that will generate invoice items appended to the next
/// invoice.
/// </summary>
[JsonProperty("add_invoice_items")]
public List<SubscriptionSchedulePhaseAddInvoiceItem> AddInvoiceItems { get; set; }

/// <summary>
/// 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
Expand Down
Loading