Skip to content

Commit 02af378

Browse files
jhoon-stripepantera-stripe
authored andcommitted
Bump API version to 2018-02-06 and add support for Product & Plan API update
1 parent 00c48e9 commit 02af378

22 files changed

+197
-54
lines changed

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"problemMatcher": "$msCompile"
1313
},
1414
]
15-
}
15+
}

src/Stripe.Tests.XUnit/orders/_fixture.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public orders_fixture()
2121
var productService = new StripeProductService(Cache.ApiKey);
2222
var product = productService.Create(new StripeProductCreateOptions {
2323
Name = "T-shirt",
24+
Type = "good"
2425
});
2526

2627
var skuService = new StripeSkuService(Cache.ApiKey);

src/Stripe.Tests.XUnit/plans/_cache.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public static StripePlan GetPlan(string planName = "plan")
1212
// Avoids parallel calls to end up with the same options (and id) twice.
1313
lock(cacheLock)
1414
{
15-
if (Items.ContainsKey(planName)) return (StripePlan) Items[planName];
15+
if (Items.ContainsKey(planName))
16+
{
17+
return (StripePlan) Items[planName];
18+
}
1619

1720
var plan = new StripePlanService(ApiKey).Create(GetPlanCreateOptions(planName));
1821
Items.Add(planName, plan);
@@ -29,9 +32,14 @@ public static StripePlanCreateOptions GetPlanCreateOptions(string planName = "pl
2932
{
3033
Amount = 1000,
3134
Currency = "usd",
32-
Name = Guid.NewGuid().ToString(),
35+
Nickname = Guid.NewGuid().ToString(),
3336
Id = Guid.NewGuid().ToString(),
34-
Interval = StripePlanIntervals.Week
37+
Interval = StripePlanIntervals.Week,
38+
Product = new StripePlanProductCreateOptions
39+
{
40+
Name = "Test Product",
41+
StatementDescriptor = "TEST THIS PRODUCT"
42+
}
3543
};
3644
Items.Add($"{planName}_create_options", options);
3745

src/Stripe.Tests.XUnit/plans/_fixture.cs

+43-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ public plans_fixture()
2020
// Add a space at the end to ensure the ID is properly URL encoded
2121
// when passed in the URL for other methods
2222
Id = "test-plan-" + Guid.NewGuid().ToString() + " ",
23-
Name = "plan-name",
23+
Nickname = "plan-name",
2424
Amount = 5000,
2525
Currency = "usd",
2626
Interval = "month",
27+
Product = new StripePlanProductCreateOptions
28+
{
29+
Name = "Test Product",
30+
StatementDescriptor = "TEST THIS PRODUCT"
31+
},
2732
};
2833

2934
PlanUpdateOptions = new StripePlanUpdateOptions {
30-
Name = "plan-name-2"
35+
Nickname = "plan-name-2"
3136
};
3237

3338
var service = new StripePlanService(Cache.ApiKey);
@@ -40,4 +45,40 @@ public plans_fixture()
4045

4146
public void Dispose() { }
4247
}
48+
49+
public class add_plan_to_product_fixture : IDisposable
50+
{
51+
public StripeProductCreateOptions ProductCreateOptions { get; set; }
52+
public StripePlanCreateOptions PlanCreateOptions { get; set; }
53+
54+
public StripeProduct Product{ get; set; }
55+
public StripePlan Plan { get; set; }
56+
public StripePlan PlanRetrieved { get; set; }
57+
58+
public add_plan_to_product_fixture()
59+
{
60+
ProductCreateOptions = new StripeProductCreateOptions
61+
{
62+
Name = $"test-product-{ Guid.NewGuid() }",
63+
Type = "service"
64+
};
65+
66+
var productService = new StripeProductService(Cache.ApiKey);
67+
Product = productService.Create(ProductCreateOptions);
68+
69+
PlanCreateOptions = new StripePlanCreateOptions() {
70+
Nickname = "plan-name",
71+
Amount = 5000,
72+
Currency = "usd",
73+
Interval = "month",
74+
ProductId = Product.Id
75+
};
76+
77+
var planService = new StripePlanService(Cache.ApiKey);
78+
Plan = planService.Create(PlanCreateOptions);
79+
PlanRetrieved = planService.Get(Plan.Id);
80+
}
81+
82+
public void Dispose() { }
83+
}
4384
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using FluentAssertions;
4+
using Xunit;
5+
6+
namespace Stripe.Tests.Xunit
7+
{
8+
public class adding_a_plan_to_a_product : IClassFixture<add_plan_to_product_fixture>
9+
{
10+
private readonly add_plan_to_product_fixture fixture;
11+
12+
public adding_a_plan_to_a_product(add_plan_to_product_fixture fixture)
13+
{
14+
this.fixture = fixture;
15+
}
16+
17+
[Fact]
18+
public void has_the_right_product()
19+
{
20+
fixture.Plan.ProductId.Should().Be(fixture.Product.Id);
21+
fixture.PlanRetrieved.ProductId.Should().Be(fixture.Product.Id);
22+
}
23+
}
24+
}

src/Stripe.Tests.XUnit/plans/when_creating_and_updating_plans.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public creating_and_updating_plans(plans_fixture fixture)
1717
[Fact]
1818
public void created_has_the_right_details()
1919
{
20-
fixture.Plan.Id.Should().Be(fixture.PlanCreateOptions.Id);
21-
fixture.Plan.Name.Should().Be(fixture.PlanCreateOptions.Name);
20+
fixture.Plan.Id.Should().NotBeNull();
2221
fixture.Plan.Amount.Should().Be(fixture.PlanCreateOptions.Amount);
22+
fixture.Plan.Nickname.Should().Be(fixture.PlanCreateOptions.Nickname);
2323
fixture.Plan.Currency.Should().Be(fixture.PlanCreateOptions.Currency);
2424
fixture.Plan.Interval.Should().Be(fixture.PlanCreateOptions.Interval);
2525
}
@@ -28,7 +28,7 @@ public void created_has_the_right_details()
2828
public void updated_has_the_right_details()
2929
{
3030
fixture.PlanUpdated.Id.Should().Be(fixture.Plan.Id);
31-
fixture.PlanUpdated.Name.Should().BeEquivalentTo(fixture.PlanUpdateOptions.Name);
31+
fixture.PlanUpdated.Nickname.Should().Be(fixture.PlanUpdateOptions.Nickname);
3232
}
3333

3434
[Fact]

src/Stripe.Tests.XUnit/products/_fixture.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public products_fixture()
2222
ProductCreateOptions = new StripeProductCreateOptions
2323
{
2424
Name = $"test-product-{ Guid.NewGuid() }",
25+
Type = "good",
2526
PackageDimensions = new StripePackageDimensionOptions {
2627
Height = 100,
2728
Length = 100,
@@ -33,12 +34,13 @@ public products_fixture()
3334

3435
ProductTwoCreateOptions = new StripeProductCreateOptions
3536
{
36-
Name = $"test-product-{ Guid.NewGuid() }"
37+
Name = $"test-product-{ Guid.NewGuid() }",
38+
Type = "good",
3739
};
3840

3941
ProductUpdateOptions = new StripeProductUpdateOptions
4042
{
41-
Name = $"test-product-{ Guid.NewGuid() }"
43+
Name = $"test-product-{ Guid.NewGuid() }",
4244
};
4345

4446
var service = new StripeProductService(Cache.ApiKey);

src/Stripe.Tests.XUnit/skus/_fixture.cs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public skus_fixture()
2222
var productService = new StripeProductService(Cache.ApiKey);
2323
Product = productService.Create(new StripeProductCreateOptions {
2424
Name = "T-shirt",
25+
Type = "good",
2526
Description = "stripe-dotnet product description",
2627
Attributes = new string[] {"size", "color"},
2728
});

src/Stripe.net.Tests/plans/plan_behaviors.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class plan_behaviors
77
{
88
protected static StripePlanCreateOptions StripePlanCreateOptions;
99
protected static StripePlan StripePlan;
10-
10+
1111
It should_have_the_correct_id = () =>
1212
StripePlan.Id.ShouldEqual(StripePlanCreateOptions.Id);
1313

@@ -19,22 +19,19 @@ public class plan_behaviors
1919

2020
It should_have_the_correct_interval = () =>
2121
StripePlan.Interval.ShouldEqual(StripePlanCreateOptions.Interval);
22-
22+
2323
It should_have_the_correct_interval_count = () =>
2424
StripePlan.IntervalCount.ShouldEqual(1);
2525

26-
It should_have_the_correct_name = () =>
27-
StripePlan.Name.ShouldEqual(StripePlanCreateOptions.Name);
26+
It should_have_the_correct_nickname = () =>
27+
StripePlan.Nickname.ShouldEqual(StripePlanCreateOptions.Nickname);
2828

2929
It should_have_the_correct_trial_period_days = () =>
3030
StripePlan.TrialPeriodDays.ShouldEqual(StripePlanCreateOptions.TrialPeriodDays);
3131

3232
It should_have_a_created_date = () =>
3333
StripePlan.Created.ShouldNotBeNull();
3434

35-
It should_have_the_correct_statement_descriptor = () =>
36-
StripePlan.StatementDescriptor.ShouldEqual(StripePlanCreateOptions.StatementDescriptor);
37-
3835
It should_have_the_correct_live_mode = () =>
3936
StripePlan.LiveMode.ShouldEqual(false);
4037
}

src/Stripe.net.Tests/plans/test_data/stripe_plan_create_options.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ public static StripePlanCreateOptions Valid()
1313
Amount = 5000,
1414
Currency = "usd",
1515
Interval = "month",
16-
Name = "Test Plan",
16+
Nickname = "Test Price",
1717
TrialPeriodDays = 1,
1818
Metadata = new Dictionary<string, string>
1919
{
2020
{ "A", "Value-A" },
2121
{ "B", "Value-B" }
2222
},
23-
StatementDescriptor = "heyyyy ya!"
23+
Product = new StripePlanProductCreateOptions
24+
{
25+
Name = "Test Plan",
26+
StatementDescriptor = "heyyyy ya!"
27+
}
2428
};
2529
}
2630

@@ -32,7 +36,10 @@ public static StripePlanCreateOptions ThirtyDayIntervalWithFiveDollars()
3236
Amount = 500,
3337
Currency = "usd",
3438
Interval = "month",
35-
Name = "Thirty Days and Five Dollars"
39+
Product = new StripePlanProductCreateOptions
40+
{
41+
Name = "Thirty Days and Five Dollars"
42+
}
3643
};
3744
}
3845
}

src/Stripe.net.Tests/plans/test_data/stripe_plan_update_options.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ public static StripePlanUpdateOptions Valid()
88
{
99
return new StripePlanUpdateOptions()
1010
{
11-
Name = "Test Plan Modified",
11+
Nickname = "Test Price Modified",
1212
Metadata = new Dictionary<string, string>
1313
{
1414
{ "A", "Value-A" },
1515
{ "B", "Value-B" },
1616
{ "C", "Value-C" }
17-
},
18-
StatementDescriptor = "heyyyy ya?"
17+
}
1918
};
2019
}
2120
}

src/Stripe.net.Tests/plans/when_updating_a_plan.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@ public class when_updating_a_plan
2525
Because of = () =>
2626
StripePlan = _stripePlanService.Update(_createdStripePlanId, StripePlanUpdateOptions);
2727

28-
It should_have_the_new_name = () =>
29-
StripePlan.Name.ShouldEqual(StripePlanUpdateOptions.Name);
28+
It should_have_the_new_nickname = () =>
29+
StripePlan.Nickname.ShouldEqual(StripePlanUpdateOptions.Nickname);
3030

3131
It should_have_metadata = () =>
3232
StripePlan.Metadata.Count.ShouldBeGreaterThan(0);
3333

3434
It should_have_correct_metadata = () =>
3535
StripePlan.Metadata.ShouldContainOnly(StripePlanUpdateOptions.Metadata);
36-
37-
It should_have_the_new_statement_descriptor = () =>
38-
StripePlan.StatementDescriptor.ShouldEqual(StripePlanUpdateOptions.StatementDescriptor);
3936
}
4037
}

src/Stripe.net/Entities/StripePlan.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public class StripePlan : StripeEntityWithId
3232
[JsonProperty("metadata")]
3333
public Dictionary<string, string> Metadata { get; set; }
3434

35-
[JsonProperty("name")]
36-
public string Name { get; set; }
35+
[JsonProperty("nickname")]
36+
public string Nickname { get; set; }
3737

38-
[JsonProperty("statement_descriptor")]
39-
public string StatementDescriptor { get; set; }
38+
[JsonProperty("product")]
39+
public string ProductId { get; set; }
4040

4141
[JsonProperty("trial_period_days")]
4242
public int? TrialPeriodDays { get; set; }
4343
}
44-
}
44+
}

src/Stripe.net/Entities/StripeProduct.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Stripe.Infrastructure;
4-
using Newtonsoft.Json;
4+
using Newtonsoft.Json;
55

66
namespace Stripe
77
{
@@ -14,7 +14,7 @@ public class StripeProduct : StripeEntityWithId
1414
/// Whether or not the product is currently available for purchase.
1515
/// </summary>
1616
[JsonProperty("active")]
17-
public bool Active { get; set; }
17+
public bool? Active { get; set; }
1818

1919
/// <summary>
2020
/// A list of up to 5 attributes that each SKU can provide values for (e.g. ["color", "size"]).
@@ -29,7 +29,7 @@ public class StripeProduct : StripeEntityWithId
2929
public string Caption { get; set; }
3030

3131
/// <summary>
32-
/// Time at which the object was created.
32+
/// Time at which the object was created.
3333
/// </summary>
3434
[JsonProperty("created")]
3535
[JsonConverter(typeof(StripeDateTimeConverter))]
@@ -81,14 +81,26 @@ public class StripeProduct : StripeEntityWithId
8181
/// Whether this product is a shipped good.
8282
/// </summary>
8383
[JsonProperty("shippable")]
84-
public bool Shippable { get; set; }
84+
public bool? Shippable { get; set; }
8585

8686
/// <summary>
8787
/// A sublist of active SKUs associated with this product.
8888
/// </summary>
8989
[JsonProperty("skus")]
9090
public StripeList<StripeSku> Skus { get; set; }
9191

92+
/// <summary>
93+
/// What appears on a customer's credit card statement.
94+
/// </summary>
95+
[JsonProperty("statement_descriptor")]
96+
public string StatementDescriptor { get; set; }
97+
98+
/// <summary>
99+
/// The type of the Product. Either 'good' or 'service'.
100+
/// </summary>
101+
[JsonProperty("type")]
102+
public string Type { get; set; }
103+
92104
[JsonProperty("updated")]
93105
[JsonConverter(typeof(StripeDateTimeConverter))]
94106
public DateTime Updated { get; set; }

src/Stripe.net/Entities/StripeSubscription.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public class StripeSubscription : StripeEntityWithId
1919
[JsonProperty("billing")]
2020
public StripeBilling? Billing { get; set; }
2121

22+
[JsonProperty("billing_cycle_anchor")]
23+
[JsonConverter(typeof(StripeDateTimeConverter))]
24+
public DateTime? BillingCycleAnchor { get; set; }
25+
2226
[JsonProperty("cancel_at_period_end")]
2327
public bool CancelAtPeriodEnd { get; set; }
2428

@@ -100,4 +104,4 @@ internal object InternalCustomer
100104
[JsonConverter(typeof(StripeDateTimeConverter))]
101105
public DateTime? TrialStart { get; set; }
102106
}
103-
}
107+
}

src/Stripe.net/Infrastructure/Public/StripeConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Stripe
77
{
88
public static class StripeConfiguration
99
{
10-
public static string StripeApiVersion = "2017-12-14";
10+
public static string StripeApiVersion = "2018-02-06";
1111
public static string StripeNetVersion { get; }
1212

1313
/// <summary>

0 commit comments

Comments
 (0)