Skip to content

Commit

Permalink
Add support for the new Invoice methods
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Nov 8, 2018
1 parent 4835ed0 commit 8398df4
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 17 deletions.
26 changes: 21 additions & 5 deletions src/Stripe.net/Entities/Invoices/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ internal object InternalCharge
}
#endregion

[JsonProperty("closed")]
public bool? Closed { get; set; }

[JsonProperty("currency")]
public string Currency { get; set; }

Expand All @@ -84,6 +81,22 @@ internal object InternalCustomer
[JsonProperty("date")]
public DateTime? Date { get; set; }

#region Expandable DefaultSource
public string DefaultSourceId { get; set; }

[JsonIgnore]
public IPaymentSource DefaultSource { get; set; }

[JsonProperty("default_source")]
internal object InternalDefaultSource
{
set
{
StringOrObject<IPaymentSource>.Map(value, s => this.DefaultSourceId = s, o => this.DefaultSource = o);
}
}
#endregion

[JsonProperty("description")]
public string Description { get; set; }

Expand All @@ -99,8 +112,8 @@ internal object InternalCustomer
[JsonProperty("ending_balance")]
public long? EndingBalance { get; set; }

[JsonProperty("forgiven")]
public bool? Forgiven { get; set; }
[JsonProperty("finalized_at")]
public DateTime? FinalizedAt { get; set; }

[JsonProperty("hosted_invoice_url")]
public string HostedInvoiceUrl { get; set; }
Expand Down Expand Up @@ -144,6 +157,9 @@ internal object InternalCustomer
[JsonProperty("statement_descriptor")]
public string StatementDescriptor { get; set; }

[JsonProperty("status")]
public string Status { get; set; }

#region Expandable Subscription
public string SubscriptionId { get; set; }

Expand Down
16 changes: 16 additions & 0 deletions src/Stripe.net/Entities/Subscriptions/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ internal object InternalCustomer
[JsonProperty("days_until_due")]
public long? DaysUntilDue { get; set; }

#region Expandable DefaultSource
public string DefaultSourceId { get; set; }

[JsonIgnore]
public IPaymentSource DefaultSource { get; set; }

[JsonProperty("default_source")]
internal object InternalDefaultSource
{
set
{
StringOrObject<IPaymentSource>.Map(value, s => this.DefaultSourceId = s, o => this.DefaultSource = o);
}
}
#endregion

[JsonProperty("discount")]
public Discount Discount { get; set; }

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

public static class StripeConfiguration
{
public static string StripeApiVersion = "2018-09-24";
public static string StripeApiVersion = "2018-11-08";

private static string apiKey;
private static string apiBase;
Expand Down
6 changes: 6 additions & 0 deletions src/Stripe.net/Services/Invoices/InvoiceCreateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class InvoiceCreateOptions : BaseOptions
[JsonProperty("application_fee")]
public long? ApplicationFee { get; set; }

[JsonProperty("auto_advance")]
public bool? AutoAdvance { get; set; }

/// <summary>
/// One of <see cref="Billing" />. When charging automatically, Stripe will attempt to pay
/// this invoice using the default source attached to the customer. When sending an invoice,
Expand All @@ -38,6 +41,9 @@ public class InvoiceCreateOptions : BaseOptions
[JsonProperty("days_until_due")]
public long? DaysUntilDue { get; set; }

[JsonProperty("default_source")]
public string DefaultSource { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

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

public class InvoiceFinalizeOptions : BaseOptions
{
[JsonProperty("auto_advance")]
public bool? AutoAdvance { 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 InvoiceMarkUncollectibleOptions : BaseOptions
{
}
}
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/Invoices/InvoiceSendOptions.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 InvoiceSendOptions : BaseOptions
{
}
}
50 changes: 50 additions & 0 deletions src/Stripe.net/Services/Invoices/InvoiceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ public virtual Invoice Create(InvoiceCreateOptions options, RequestOptions reque
return this.CreateEntityAsync(options, requestOptions, cancellationToken);
}

public virtual Invoice Delete(string invoiceId, RequestOptions requestOptions = null)
{
return this.DeleteEntity(invoiceId, null, requestOptions);
}

public virtual Task<Invoice> DeleteAsync(string invoiceId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.DeleteEntityAsync(invoiceId, null, requestOptions, cancellationToken);
}

public virtual Invoice FinalizeInvoice(string invoiceId, InvoiceFinalizeOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<Invoice>($"{this.InstanceUrl(invoiceId)}/finalize", options, requestOptions);
}

public virtual Task<Invoice> FinalizeInvoiceAsync(string invoiceId, InvoiceFinalizeOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostRequestAsync<Invoice>($"{this.InstanceUrl(invoiceId)}/finalize", options, requestOptions, cancellationToken);
}

public virtual Invoice Get(string invoiceId, RequestOptions requestOptions = null)
{
return this.GetEntity(invoiceId, null, requestOptions);
Expand Down Expand Up @@ -79,6 +99,16 @@ public virtual StripeList<InvoiceLineItem> ListUpcomingLineItems(UpcomingInvoice
return this.GetRequestAsync<StripeList<InvoiceLineItem>>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, true, cancellationToken);
}

public virtual Invoice MarkUncollectible(string invoiceId, InvoiceMarkUncollectibleOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<Invoice>($"{this.InstanceUrl(invoiceId)}/mark_uncollectible", options, requestOptions);
}

public virtual Task<Invoice> MarkUncollectibleAsync(string invoiceId, InvoiceMarkUncollectibleOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostRequestAsync<Invoice>($"{this.InstanceUrl(invoiceId)}/mark_uncollectible", options, requestOptions, cancellationToken);
}

public virtual Invoice Pay(string invoiceId, InvoicePayOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<Invoice>($"{this.InstanceUrl(invoiceId)}/pay", options, requestOptions);
Expand All @@ -89,6 +119,16 @@ public virtual Invoice Pay(string invoiceId, InvoicePayOptions options, RequestO
return this.PostRequestAsync<Invoice>($"{this.InstanceUrl(invoiceId)}/pay", options, requestOptions, cancellationToken);
}

public virtual Invoice SendInvoice(string invoiceId, InvoiceSendOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<Invoice>($"{this.InstanceUrl(invoiceId)}/send", options, requestOptions);
}

public virtual Task<Invoice> SendInvoiceAsync(string invoiceId, InvoiceSendOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostRequestAsync<Invoice>($"{this.InstanceUrl(invoiceId)}/send", options, requestOptions, cancellationToken);
}

public virtual Invoice Upcoming(UpcomingInvoiceOptions options, RequestOptions requestOptions = null)
{
return this.GetRequest<Invoice>($"{this.InstanceUrl("upcoming")}", options, requestOptions, false);
Expand All @@ -108,5 +148,15 @@ public virtual Invoice Update(string invoiceId, InvoiceUpdateOptions options, Re
{
return this.UpdateEntityAsync(invoiceId, options, requestOptions, cancellationToken);
}

public virtual Invoice VoidInvoice(string invoiceId, InvoiceVoidOptions options, RequestOptions requestOptions = null)
{
return this.PostRequest<Invoice>($"{this.InstanceUrl(invoiceId)}/void", options, requestOptions);
}

public virtual Task<Invoice> VoidInvoiceAsync(string invoiceId, InvoiceVoidOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostRequestAsync<Invoice>($"{this.InstanceUrl(invoiceId)}/void", options, requestOptions, cancellationToken);
}
}
}
6 changes: 6 additions & 0 deletions src/Stripe.net/Services/Invoices/InvoiceUpdateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ public class InvoiceUpdateOptions : BaseOptions
[JsonProperty("application_fee")]
public long? ApplicationFee { get; set; }

[JsonProperty("auto_advance")]
public bool? AutoAdvance { get; set; }

[JsonProperty("closed")]
public bool? Closed { get; set; }

[JsonProperty("default_source")]
public string DefaultSource { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

Expand Down
11 changes: 11 additions & 0 deletions src/Stripe.net/Services/Invoices/InvoiceVoidOptions.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 InvoiceVoidOptions : BaseOptions
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public abstract class SubscriptionSharedOptions : BaseOptions
[JsonProperty("days_until_due")]
public long? DaysUntilDue { get; set; }

[JsonProperty("default_source")]
public string DefaultSource { get; set; }

/// <summary>
/// A set of key/value pairs that you can attach to a subscription object. It can be useful for storing additional information about the subscription in a structured format.
/// </summary>
Expand Down
7 changes: 2 additions & 5 deletions src/StripeTests/Entities/PaymentIntents/PaymentIntentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public void Deserialize()
[Fact]
public void DeserializeWithExpansions()
{
// Do not test expanding `source` as it is not supported by stripe-mock
// and will be auto-expanded in a future API version.
string[] expansions =
{
"application",
"customer",
"source",
"transfer_data.destination",
};

Expand All @@ -40,10 +41,6 @@ public void DeserializeWithExpansions()
Assert.NotNull(intent.Customer);
Assert.Equal("customer", intent.Customer.Object);

Assert.NotNull(intent.Source);
Assert.IsType<Card>(intent.Source);
Assert.Equal("card", intent.Source.Object);

Assert.NotNull(intent.TransferData);
Assert.NotNull(intent.TransferData.Destination);
Assert.Equal("account", intent.TransferData.Destination.Object);
Expand Down
Loading

0 comments on commit 8398df4

Please sign in to comment.