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 CreditNote #1564

Merged
merged 3 commits into from
Apr 18, 2019
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
15 changes: 15 additions & 0 deletions src/Stripe.net/Constants/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ public static class Events
/// </summary>
public static string CouponUpdated => "coupon.updated";

/// <summary>
/// Occurs whenever a credit note is created.
/// </summary>
public static string CreditNoteCreated => "credit_note.created";

/// <summary>
/// Occurs whenever a credit note is updated.
/// </summary>
public static string CreditNoteUpdated => "credit_note.updated";

/// <summary>
/// Occurs whenever a credit note is voided.
/// </summary>
public static string CreditNoteVoided => "credit_note.voided";

/// <summary>
/// Occurs whenever a new customer is created.
/// </summary>
Expand Down
171 changes: 171 additions & 0 deletions src/Stripe.net/Entities/CreditNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNote : StripeEntity, 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>
/// Credit note amount.
/// </summary>
[JsonProperty("amount")]
public long Amount { 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; }

#region Expandable Customer

/// <summary>
/// ID of the customer associated with that credit note.
/// </summary>
[JsonIgnore]
public string CustomerId { get; set; }

[JsonIgnore]
public Customer Customer { get; set; }

[JsonProperty("customer")]
internal object InternalCustomer
{
get
{
return this.Customer ?? (object)this.CustomerId;
}

set
{
StringOrObject<Customer>.Map(value, s => this.CustomerId = s, o => this.Customer = o);
}
}
#endregion

#region Expandable Invoice

/// <summary>
/// ID of the invoice associated with that credit note.
/// </summary>
[JsonIgnore]
public string InvoiceId { get; set; }

[JsonIgnore]
public Invoice Invoice { get; set; }

[JsonProperty("invoice")]
internal object InternalInvoice
{
get
{
return this.Invoice ?? (object)this.InvoiceId;
}

set
{
StringOrObject<Invoice>.Map(value, s => this.InvoiceId = s, o => this.Invoice = o);
}
}
#endregion

/// <summary>
/// Has the value <code>true</code> if the object exists in live mode or the value
/// <code>false</code> if the object exists in test mode.
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
[JsonProperty("livemode")]
public bool Livemode { get; set; }

/// <summary>
/// Credit note memo.
/// </summary>
[JsonProperty("memo")]
public string Memo { get; set; }

/// <summary>
/// A set of key/value pairs that you can attach to an order object. It can be useful for
/// storing additional information about the order in a structured format.
/// </summary>
[JsonProperty("metadata")]
public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// Credit note number.
/// </summary>
[JsonProperty("number")]
public string Number { get; set; }

/// <summary>
/// The link to download the PDF of the credit note.
/// </summary>
[JsonProperty("pdf")]
public string Pdf { get; set; }

/// <summary>
/// Reason for issuing this credit note, one of <code>duplicate</code>,
/// <code>fraudulent</code>, <code>order_change</code>, or
/// <code>product_unsatisfactory</code>.
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
[JsonProperty("reason")]
public string Reason { get; set; }

#region Expandable Refund

/// <summary>
/// ID of the refund associated with that credit note.
/// </summary>
[JsonIgnore]
public string RefundId { get; set; }

[JsonIgnore]
public Refund Refund { get; set; }

[JsonProperty("refund")]
internal object InternalRefund
{
get
{
return this.Refund ?? (object)this.RefundId;
}

set
{
StringOrObject<Refund>.Map(value, s => this.RefundId = s, o => this.Refund = o);
}
}
#endregion

/// <summary>
/// Status of this credit note, one of <code>issued</code> or <code>void</code>.
/// </summary>
[JsonProperty("status")]
public string Status { get; set; }

/// <summary>
/// Type of this credit note, one of <code>post_payment</code> or <code>pre_payment</code>.
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Stripe.net/Infrastructure/StripeTypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal static class StripeTypeRegistry
{ "checkout.session", typeof(Checkout.Session) },
{ "country_spec", typeof(CountrySpec) },
{ "coupon", typeof(Coupon) },
{ "credit_note", typeof(CreditNote) },
{ "customer", typeof(Customer) },
{ "discount", typeof(Discount) },
{ "dispute", typeof(Dispute) },
Expand Down
62 changes: 62 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteCreateOptions : BaseOptions
{
/// <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 InvoiceId { 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>
/// ID of an existing refund to link this credit note to.
/// </summary>
[JsonProperty("refund")]
public string RefundId { 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; }

/// <summary>
/// Reason for issuing this credit note, one of <code>duplicate</code>,
/// <code>fraudulent</code>, <code>order_change</code>, or
/// <code>product_unsatisfactory</code>.
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
[JsonProperty("reason")]
public string Reason { get; set; }
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
}
}
14 changes: 14 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteListOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Stripe
{
using System;
using Newtonsoft.Json;

public class CreditNoteListOptions : ListOptions
{
/// <summary>
/// ID of the invoice.
/// </summary>
[JsonProperty("invoice")]
public string InvoiceId { get; set; }
}
}
80 changes: 80 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace Stripe
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public class CreditNoteService : Service<CreditNote>,
ICreatable<CreditNote, CreditNoteCreateOptions>,
IListable<CreditNote, CreditNoteListOptions>,
IRetrievable<CreditNote>,
IUpdatable<CreditNote, CreditNoteUpdateOptions>
{
public CreditNoteService()
: base(null)
{
}

public CreditNoteService(string apiKey)
: base(apiKey)
{
}

public override string BasePath => "/credit_notes";

public virtual CreditNote Create(CreditNoteCreateOptions options, RequestOptions requestOptions = null)
{
return this.CreateEntity(options, requestOptions);
}

public virtual Task<CreditNote> CreateAsync(CreditNoteCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.CreateEntityAsync(options, requestOptions, cancellationToken);
}

public virtual CreditNote Get(string creditNoteId, RequestOptions requestOptions = null)
{
return this.GetEntity(creditNoteId, null, requestOptions);
}

public virtual Task<CreditNote> GetAsync(string creditNoteId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetEntityAsync(creditNoteId, null, requestOptions, cancellationToken);
}

public virtual StripeList<CreditNote> List(CreditNoteListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntities(options, requestOptions);
}

public virtual Task<StripeList<CreditNote>> ListAsync(CreditNoteListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.ListEntitiesAsync(options, requestOptions, cancellationToken);
}

public virtual IEnumerable<CreditNote> ListAutoPaging(CreditNoteListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntitiesAutoPaging(options, requestOptions);
}

public virtual CreditNote Update(string creditNoteId, CreditNoteUpdateOptions options, RequestOptions requestOptions = null)
{
return this.UpdateEntity(creditNoteId, options, requestOptions);
}

public virtual Task<CreditNote> UpdateAsync(string creditNoteId, CreditNoteUpdateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.UpdateEntityAsync(creditNoteId, options, requestOptions, cancellationToken);
}

public virtual CreditNote VoidCreditNote(string creditNoteId, CreditNoteVoidOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<CreditNote>($"{this.InstanceUrl(creditNoteId)}/void", options, requestOptions);
}

public virtual Task<CreditNote> VoidCreditNoteAsync(string creditNoteId, CreditNoteVoidOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostRequestAsync<CreditNote>($"{this.InstanceUrl(creditNoteId)}/void", options, requestOptions, cancellationToken);
}
}
}
23 changes: 23 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteUpdateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Stripe
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class CreditNoteUpdateOptions : BaseOptions
{
/// <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; }
}
}
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/CreditNotes/CreditNoteVoidOptions.cs
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 CreditNoteVoidOptions : BaseOptions
{
}
}
Loading