Skip to content

Commit

Permalink
Merge pull request #1896 from stripe/remi-add-creditnote-preview-lines
Browse files Browse the repository at this point in the history
Add support for `CreditNoteLineItem`
  • Loading branch information
remi-stripe authored Jan 14, 2020
2 parents aafa6ab + 69d2f3b commit 1d12aca
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 16 deletions.
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
92 changes: 92 additions & 0 deletions src/Stripe.net/Entities/CreditNoteLineItems/CreditNoteLineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteLineItem : StripeEntity<CreditNoteLineItem>, IHasId, 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>
/// The integer amount representing the gross amount being credited for this line item,
/// excluding (exclusive) tax and discounts.
/// </summary>
[JsonProperty("amount")]
public long Amount { get; set; }

/// <summary>
/// Description of the item being credited.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// The integer amount representing the discount being credited for this line item.
/// </summary>
[JsonProperty("discount_amount")]
public long DiscountAmount { get; set; }

/// <summary>
/// ID of the invoice line item being credited.
/// </summary>
[JsonProperty("invoice_line_item")]
public string InvoiceLineItem { 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>
/// The number of units of product being credited.
/// </summary>
[JsonProperty("quantity")]
public long Quantity { get; set; }

/// <summary>
/// The amount of tax calculated per tax rate for this line item.
/// </summary>
[JsonProperty("tax_amounts")]
public List<CreditNoteTaxAmount> TaxAmounts { get; set; }

/// <summary>
/// Tax rates applied to the invoice.
/// </summary>
[JsonProperty("tax_rates")]
public List<TaxRate> TaxRates { get; set; }

/// <summary>
/// The type of the credit note line item, one of <c>custom_line_item</c> or
/// <c>invoice_line_item`</c>.
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

/// <summary>
/// The cost of each unit of product being credited.
/// </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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public CustomerBalanceTransaction CustomerBalanceTransaction
internal ExpandableField<CustomerBalanceTransaction> InternalCustomerBalanceTransaction { get; set; }
#endregion

/// <summary>
/// The integer amount representing the amount of the discount that was credited.
/// </summary>
[JsonProperty("discount_amount")]
public long DiscountAmount { get; set; }

#region Expandable Invoice

/// <summary>
Expand All @@ -110,6 +116,12 @@ public Invoice Invoice
internal ExpandableField<Invoice> InternalInvoice { get; set; }
#endregion

/// <summary>
/// Line items that make up the credit note.
/// </summary>
[JsonProperty("lines")]
public StripeList<CreditNoteLineItem> Lines { 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.
Expand All @@ -136,6 +148,12 @@ public Invoice Invoice
[JsonProperty("number")]
public string Number { get; set; }

/// <summary>
/// Amount that was credited outside of Stripe.
/// </summary>
[JsonProperty("out_of_band_amount")]
public long OutOfBandAmount { get; set; }

/// <summary>
/// The link to download the PDF of the credit note.
/// </summary>
Expand Down Expand Up @@ -179,6 +197,26 @@ public Refund Refund
[JsonProperty("status")]
public string Status { get; set; }

/// <summary>
/// The integer amount in **%s** representing the amount of the credit note, excluding tax
/// and discount.
/// </summary>
[JsonProperty("subtotal")]
public long Subtotal { get; set; }

/// <summary>
/// The aggregate amounts calculated per tax rate for all line items.
/// </summary>
[JsonProperty("tax_amounts")]
public List<CreditNoteTaxAmount> TaxAmounts { get; set; }

/// <summary>
/// The integer amount in **%s** representing the total amount of the credit note, including
/// tax and discount.
/// </summary>
[JsonProperty("total")]
public long Total { get; set; }

/// <summary>
/// Type of this credit note, one of <c>post_payment</c> or <c>pre_payment</c>.
/// </summary>
Expand Down
44 changes: 44 additions & 0 deletions src/Stripe.net/Entities/CreditNotes/CreditNoteTaxAmount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Stripe
{
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteTaxAmount : StripeEntity<CreditNoteTaxAmount>
{
/// <summary>
/// The amount, in cents, of the tax.
/// </summary>
[JsonProperty("amount")]
public long Amount { get; set; }

/// <summary>
/// Whether this tax amount is inclusive or exclusive.
/// </summary>
[JsonProperty("inclusive")]
public bool Inclusive { get; set; }

#region Expandable TaxRate

/// <summary>
/// The ID of the tax rate that was applied to get this tax amount.
/// </summary>
[JsonIgnore]
public string TaxRateId
{
get => this.InternalTaxRate?.Id;
set => this.InternalTaxRate = SetExpandableFieldId(value, this.InternalTaxRate);
}

[JsonIgnore]
public TaxRate TaxRate
{
get => this.InternalTaxRate?.ExpandedObject;
set => this.InternalTaxRate = SetExpandableFieldObject(value, this.InternalTaxRate);
}

[JsonProperty("tax_rate")]
[JsonConverter(typeof(ExpandableFieldConverter<TaxRate>))]
internal ExpandableField<TaxRate> InternalTaxRate { get; set; }
#endregion
}
}
1 change: 1 addition & 0 deletions src/Stripe.net/Infrastructure/Public/StripeTypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static class StripeTypeRegistry
{ "country_spec", typeof(CountrySpec) },
{ "coupon", typeof(Coupon) },
{ "credit_note", typeof(CreditNote) },
{ "credit_note_line_item", typeof(CreditNoteLineItem) },
{ "customer", typeof(Customer) },
{ "customer_balance_transaction", typeof(CustomerBalanceTransaction) },
{ "discount", typeof(Discount) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class CreditNoteCreateOptions : BaseOptions, IHasMetadata
[JsonProperty("invoice")]
public string Invoice { get; set; }

/// <summary>
/// Line items that make up the credit note.
/// </summary>
[JsonProperty("lines")]
public List<CreditNoteLineOptions> Lines { get; set; }

/// <summary>
/// Credit note memo.
/// </summary>
Expand Down
73 changes: 73 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteLineOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace Stripe
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class CreditNoteLineOptions : INestedOptions, IHasMetadata
{
/// <summary>
/// The line item amount to credit. Only valid when <see cref="Type"/> is
/// <c>invoice_line_item</c> and the referenced invoice line item does not have a quantity,
/// only an amount.
/// </summary>
[JsonProperty("amount")]
public long? Amount { get; set; }

/// <summary>
/// The description of the credit note line item. Only valid when the <see cref="Type"/> is
/// <c>custom_line_item</c>.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// The invoice line item to credit. Only valid when the <see cref="Type"/> is
/// <c>invoice_line_item</c>.
/// </summary>
[JsonProperty("invoice_line_item")]
public string InvoiceLineItem { get; set; }

/// <summary>
/// A set of key/value pairs that you can attach to a charge object. It can be useful for
/// storing additional information about the customer in a structured format. It's often a
/// good idea to store an email address in metadata for tracking later.
/// </summary>
[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// The line item quantity to credit.
/// </summary>
[JsonProperty("quantity")]
public long? Quantity { get; set; }

/// <summary>
/// The tax rates which apply to the credit note line item. Only valid when the
/// <see cref="Type"/> is <c>custom_line_item</c>.
/// </summary>
[JsonProperty("tax_rates")]
public List<string> TaxRates { get; set; }

/// <summary>
/// Type of the credit note line item, one of <c>custom_line_item</c> or
/// <c>invoice_line_item</c>.
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

/// <summary>
/// The integer unit amount of the credit note line item. This will be multiplied by the
/// quantity to get the full amount to credit for this line item. Only valid
/// when <see cref="Type"/> is <c>custom_line_item</c>.
/// </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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteListLineItemsOptions : ListOptions
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteListPreviewLineItemsOptions : ListOptions, IHasMetadata
{
/// <summary>
/// Credit note amount.
/// </summary>
[JsonProperty("amount")]
public long? Amount { get; set; }

/// <summary>
/// Amount to credit the customer balance.
/// </summary>
[JsonProperty("credit_amount")]
public long? CreditAmount { get; set; }

/// <summary>
/// ID of the invoice.
/// </summary>
[JsonProperty("invoice")]
public string Invoice { get; set; }

/// <summary>
/// Credit note memo.
/// </summary>
[JsonProperty("memo")]
public string Memo { 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>
/// The integer amount representing the amount that is credited outside of Stripe.
/// </summary>
[JsonProperty("out_of_band_amount")]
public long? OutOfBandAmount { get; set; }

/// <summary>
/// Reason for issuing this credit note, one of <c>duplicate</c>, <c>fraudulent</c>,
/// <c>order_change</c>, or <c>product_unsatisfactory</c>.
/// </summary>
[JsonProperty("reason")]
public string Reason { get; set; }

/// <summary>
/// ID of an existing refund to link this credit note to.
/// </summary>
[JsonProperty("refund")]
public string Refund { get; set; }

/// <summary>
/// Amount to refund. If set, a refund will be created for the charge associated with the
/// invoice.
/// </summary>
[JsonProperty("refund_amount")]
public long? RefundAmount { get; set; }
}
}
Loading

0 comments on commit 1d12aca

Please sign in to comment.