diff --git a/appveyor.yml b/appveyor.yml index 977d6f1150..5a62af1860 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,7 +5,7 @@ environment: COVERALLS_REPO_TOKEN: secure: T0PmP8uyzCseacBCDRBlti2y9Tz5DL6fknea0MKWvbPYrzADmLY2/5kOTfYIsPUk # If you bump this, don't forget to bump `MinimumMockVersion` in `BaseStripeTest.cs` as well. - STRIPE_MOCK_VERSION: 0.39.0 + STRIPE_MOCK_VERSION: 0.40.0 deploy: - provider: NuGet diff --git a/src/Stripe.net/Entities/CheckoutSessions/CheckoutSession.cs b/src/Stripe.net/Entities/CheckoutSessions/CheckoutSession.cs new file mode 100644 index 0000000000..574594f77f --- /dev/null +++ b/src/Stripe.net/Entities/CheckoutSessions/CheckoutSession.cs @@ -0,0 +1,19 @@ +namespace Stripe +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class CheckoutSession : StripeEntity, IHasId, IHasObject + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("livemode")] + public bool Livemode { get; set; } + } +} diff --git a/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionCreateOptions.cs b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionCreateOptions.cs new file mode 100644 index 0000000000..20d904fbdb --- /dev/null +++ b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionCreateOptions.cs @@ -0,0 +1,28 @@ +namespace Stripe +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class CheckoutSessionCreateOptions : BaseOptions + { + [JsonProperty("allowed_source_types")] + public List AllowedSourceTypes { get; set; } + + [JsonProperty("cancel_url")] + public string CancelUrl { get; set; } + + [JsonProperty("client_reference_id")] + public string ClientReferenceId { get; set; } + + [JsonProperty("line_items")] + public List LineItems { get; set; } + + [JsonProperty("payment_intent_data")] + public CheckoutSessionPaymentIntentDataOptions PaymentIntentData { get; set; } + + [JsonProperty("success_url")] + public string SuccessUrl { get; set; } + } +} diff --git a/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionLineItemOptions.cs b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionLineItemOptions.cs new file mode 100644 index 0000000000..7f12bf51f0 --- /dev/null +++ b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionLineItemOptions.cs @@ -0,0 +1,26 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class CheckoutSessionLineItemOptions : INestedOptions + { + [JsonProperty("amount")] + public long? Amount { get; set; } + + [JsonProperty("currency")] + public string Currency { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("images")] + public List Images { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("quantity")] + public long? Quantity { get; set; } + } +} diff --git a/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionPaymentIntentDataOptions.cs b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionPaymentIntentDataOptions.cs new file mode 100644 index 0000000000..e3424fd744 --- /dev/null +++ b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionPaymentIntentDataOptions.cs @@ -0,0 +1,23 @@ +namespace Stripe +{ + using System.Collections.Generic; + using Newtonsoft.Json; + + public class CheckoutSessionPaymentIntentDataOptions : INestedOptions + { + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("metadata")] + public Dictionary Metadata { get; set; } + + [JsonProperty("receipt_email")] + public string ReceiptEmail { get; set; } + + [JsonProperty("shipping")] + public ChargeShippingOptions Shipping { get; set; } + + [JsonProperty("statement_descriptor")] + public string StatementDescriptor { get; set; } + } +} diff --git a/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionService.cs b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionService.cs new file mode 100644 index 0000000000..4b3d88b47c --- /dev/null +++ b/src/Stripe.net/Services/CheckoutSessions/CheckoutSessionService.cs @@ -0,0 +1,34 @@ +namespace Stripe +{ + using System.Collections.Generic; + using System.Net; + using System.Threading; + using System.Threading.Tasks; + using Stripe.Infrastructure; + + public class CheckoutSessionService : Service, + ICreatable + { + public CheckoutSessionService() + : base(null) + { + } + + public CheckoutSessionService(string apiKey) + : base(apiKey) + { + } + + public override string BasePath => "/checkout_sessions"; + + public virtual CheckoutSession Create(CheckoutSessionCreateOptions options, RequestOptions requestOptions = null) + { + return this.CreateEntity(options, requestOptions); + } + + public virtual Task CreateAsync(CheckoutSessionCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.CreateEntityAsync(options, requestOptions, cancellationToken); + } + } +} diff --git a/src/StripeTests/BaseStripeTest.cs b/src/StripeTests/BaseStripeTest.cs index 56c9b85307..c33c9ea31f 100644 --- a/src/StripeTests/BaseStripeTest.cs +++ b/src/StripeTests/BaseStripeTest.cs @@ -19,7 +19,7 @@ public class BaseStripeTest /// /// If you bump this, don't forget to bump `STRIPE_MOCK_VERSION` in appveyor.yml as well. /// - private const string MockMinimumVersion = "0.39.0"; + private const string MockMinimumVersion = "0.40.0"; private static Mock mockHandler; diff --git a/src/StripeTests/Entities/Coupons/CheckoutSessionTest.cs b/src/StripeTests/Entities/Coupons/CheckoutSessionTest.cs new file mode 100644 index 0000000000..919090772e --- /dev/null +++ b/src/StripeTests/Entities/Coupons/CheckoutSessionTest.cs @@ -0,0 +1,20 @@ +namespace StripeTests +{ + using Newtonsoft.Json; + using Stripe; + using Xunit; + + public class CheckoutSessionTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + var json = GetResourceAsString("api_fixtures.checkout_session.json"); + var session = JsonConvert.DeserializeObject(json); + Assert.NotNull(session); + Assert.IsType(session); + Assert.NotNull(session.Id); + Assert.Equal("checkout_session", session.Object); + } + } +} diff --git a/src/StripeTests/Resources/api_fixtures/checkout_session.json b/src/StripeTests/Resources/api_fixtures/checkout_session.json new file mode 100644 index 0000000000..835dc48ec0 --- /dev/null +++ b/src/StripeTests/Resources/api_fixtures/checkout_session.json @@ -0,0 +1,5 @@ +{ + "id": "randomid", + "object": "checkout_session", + "livemode": false +} \ No newline at end of file diff --git a/src/StripeTests/Services/CheckoutSessions/CheckoutSessionServiceTest.cs b/src/StripeTests/Services/CheckoutSessions/CheckoutSessionServiceTest.cs new file mode 100644 index 0000000000..40a72c7bc4 --- /dev/null +++ b/src/StripeTests/Services/CheckoutSessions/CheckoutSessionServiceTest.cs @@ -0,0 +1,82 @@ +namespace StripeTests +{ + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe; + using Xunit; + + public class CheckoutSessionServiceTest : BaseStripeTest + { + private CheckoutSessionService service; + private CheckoutSessionCreateOptions createOptions; + + public CheckoutSessionServiceTest() + { + this.service = new CheckoutSessionService(); + + this.createOptions = new CheckoutSessionCreateOptions + { + AllowedSourceTypes = new List + { + "card", + }, + CancelUrl = "https://stripe.con/cancel", + ClientReferenceId = "1234", + LineItems = new List + { + new CheckoutSessionLineItemOptions + { + Amount = 1234, + Currency = "usd", + Description = "item1", + Images = new List + { + "https://stripe.com/image1", + }, + Name = "item name", + Quantity = 2, + }, + }, + PaymentIntentData = new CheckoutSessionPaymentIntentDataOptions + { + Description = "description", + Shipping = new ChargeShippingOptions + { + Name = "name", + Phone = "555-555-5555", + Address = new AddressOptions + { + State = "CA", + City = "City", + Line1 = "Line1", + Line2 = "Line2", + PostalCode = "90210", + Country = "US", + }, + } + }, + SuccessUrl = "https://stripe.con/success", + }; + } + + [Fact] + public void Create() + { + var session = this.service.Create(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/checkout_sessions"); + Assert.NotNull(session); + Assert.Equal("checkout_session", session.Object); + } + + [Fact] + public async Task CreateAsync() + { + var session = await this.service.CreateAsync(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/checkout_sessions"); + Assert.NotNull(session); + Assert.Equal("checkout_session", session.Object); + } + } +}