Skip to content

Commit 2b6a117

Browse files
authored
Merge pull request #1214 from stripe/remi-invoice-upcoming-add-invoiceitems
Upcoming now has `invoice_items` and subscription_billing_cycle_anchor`
2 parents 83d2416 + b26d42d commit 2b6a117

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using FluentAssertions;
4+
using Xunit;
5+
6+
namespace Stripe.Tests.Xunit
7+
{
8+
public class retrieving_upcoming_invoice
9+
{
10+
public StripeInvoice InvoiceUpcoming { get; }
11+
12+
public retrieving_upcoming_invoice()
13+
{
14+
var customerService = new StripeCustomerService(Cache.ApiKey);
15+
var invoiceItemService = new StripeInvoiceItemService(Cache.ApiKey);
16+
var invoiceService = new StripeInvoiceService(Cache.ApiKey);
17+
18+
var CustomerCreateOptions = new StripeCustomerCreateOptions
19+
{
20+
SourceToken = "tok_visa",
21+
};
22+
var Customer = customerService.Create(CustomerCreateOptions);
23+
24+
var InvoiceItemCreateOptions = new StripeInvoiceItemCreateOptions
25+
{
26+
Amount = 1000,
27+
Currency = "usd",
28+
CustomerId = Customer.Id
29+
};
30+
var InvoiceItem = invoiceItemService.Create(InvoiceItemCreateOptions);
31+
32+
var UpcomingInvoiceOptions = new StripeUpcomingInvoiceOptions
33+
{
34+
InvoiceItems = new List<StripeInvoiceUpcomingInvoiceItemOption> {
35+
new StripeInvoiceUpcomingInvoiceItemOption {
36+
Amount = 1001,
37+
Currency = "usd",
38+
},
39+
new StripeInvoiceUpcomingInvoiceItemOption {
40+
Amount = 1002,
41+
InvoiceItemId = InvoiceItem.Id,
42+
},
43+
},
44+
};
45+
InvoiceUpcoming = invoiceService.Upcoming(Customer.Id, UpcomingInvoiceOptions);
46+
}
47+
48+
[Fact]
49+
public void invoice_upcoming_has_correct_information()
50+
{
51+
InvoiceUpcoming.Should().NotBeNull();
52+
InvoiceUpcoming.StripeInvoiceLineItems.Should().NotBeNull();
53+
InvoiceUpcoming.StripeInvoiceLineItems.Data.Count.Should().Be(2);
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Stripe
5+
{
6+
public class StripeInvoiceUpcomingInvoiceItemOption : INestedOptions
7+
{
8+
[JsonProperty("amount")]
9+
public int Amount { get; set; }
10+
11+
[JsonProperty("currency")]
12+
public string Currency { get; set; }
13+
14+
[JsonProperty("description")]
15+
public string Description { get; set; }
16+
17+
[JsonProperty("discountable")]
18+
public bool Discountable { get; set; }
19+
20+
[JsonProperty("invoiceitem")]
21+
public string InvoiceItemId { get; set; }
22+
23+
[JsonProperty("metadata")]
24+
public Dictionary<string, string> Metadata { get; set; }
25+
}
26+
}

src/Stripe.net/Services/Invoices/StripeUpcomingInvoiceOptions.cs

+19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ public class StripeUpcomingInvoiceOptions : StripeBaseOptions
1010
[JsonProperty("coupon")]
1111
public string CouponId { get; set; }
1212

13+
[JsonProperty("invoice_items")]
14+
public List<StripeInvoiceUpcomingInvoiceItemOption> InvoiceItems { get; set; }
15+
16+
/// <summary>
17+
/// A future date to anchor the subscription’s <see href="https://stripe.com/docs/subscriptions/billing-cycle">billing cycle</see>. This is used to determine 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.
18+
/// </summary>
19+
public DateTime? SubscriptionBillingCycleAnchor { get; set; }
20+
21+
[JsonProperty("subscription_billing_cycle_anchor")]
22+
internal long? SubscriptionBillingCycleAnchorInternal
23+
{
24+
get
25+
{
26+
if (!SubscriptionBillingCycleAnchor.HasValue) return null;
27+
28+
return EpochTime.ConvertDateTimeToEpoch(SubscriptionBillingCycleAnchor.Value);
29+
}
30+
}
31+
1332
[JsonProperty("subscription")]
1433
public string SubscriptionId { get; set; }
1534

0 commit comments

Comments
 (0)