From 8be061b7a1be2e8abd59e4d608b0f2a447066021 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Mon, 12 Nov 2018 14:21:42 +0100 Subject: [PATCH] Add support for Terminal resources --- .../ConnectionTokens/ConnectionToken.cs | 16 +++ .../Entities/Terminal/Locations/Location.cs | 22 ++++ .../Entities/Terminal/Readers/Reader.cs | 37 ++++++ .../JsonConverters/StripeObjectConverter.cs | 3 + .../ConnectionTokenCreateOptions.cs | 8 ++ .../ConnectionTokenService.cs | 33 +++++ .../Locations/LocationCreateOptions.cs | 8 ++ .../Terminal/Locations/LocationListOptions.cs | 10 ++ .../Terminal/Locations/LocationService.cs | 63 ++++++++++ .../Locations/LocationSharedOptions.cs | 13 ++ .../Locations/LocationUpdateOptions.cs | 10 ++ .../Terminal/Readers/ReaderCreateOptions.cs | 13 ++ .../Terminal/Readers/ReaderListOptions.cs | 13 ++ .../Terminal/Readers/ReaderService.cs | 63 ++++++++++ .../Terminal/Readers/ReaderSharedOptions.cs | 10 ++ .../Terminal/Readers/ReaderUpdateOptions.cs | 10 ++ .../ConnectionTokens/ConnectionTokenTest.cs | 25 ++++ .../Terminal/Locations/LocationTest.cs | 25 ++++ .../Entities/Terminal/Readers/ReaderTest.cs | 25 ++++ .../api_fixtures/connection_token.json | 4 + .../ConnectionTokenServiceTest.cs | 41 +++++++ .../Terminal/Locations/LocationServiceTest.cs | 114 ++++++++++++++++++ .../Terminal/Readers/ReaderServiceTest.cs | 106 ++++++++++++++++ 23 files changed, 672 insertions(+) create mode 100644 src/Stripe.net/Entities/Terminal/ConnectionTokens/ConnectionToken.cs create mode 100644 src/Stripe.net/Entities/Terminal/Locations/Location.cs create mode 100644 src/Stripe.net/Entities/Terminal/Readers/Reader.cs create mode 100644 src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenCreateOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenService.cs create mode 100644 src/Stripe.net/Services/Terminal/Locations/LocationCreateOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Locations/LocationListOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Locations/LocationService.cs create mode 100644 src/Stripe.net/Services/Terminal/Locations/LocationSharedOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Locations/LocationUpdateOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Readers/ReaderCreateOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Readers/ReaderListOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Readers/ReaderService.cs create mode 100644 src/Stripe.net/Services/Terminal/Readers/ReaderSharedOptions.cs create mode 100644 src/Stripe.net/Services/Terminal/Readers/ReaderUpdateOptions.cs create mode 100644 src/StripeTests/Entities/Terminal/ConnectionTokens/ConnectionTokenTest.cs create mode 100644 src/StripeTests/Entities/Terminal/Locations/LocationTest.cs create mode 100644 src/StripeTests/Entities/Terminal/Readers/ReaderTest.cs create mode 100644 src/StripeTests/Resources/api_fixtures/connection_token.json create mode 100644 src/StripeTests/Services/Terminal/ConnectionTokens/ConnectionTokenServiceTest.cs create mode 100644 src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs create mode 100644 src/StripeTests/Services/Terminal/Readers/ReaderServiceTest.cs diff --git a/src/Stripe.net/Entities/Terminal/ConnectionTokens/ConnectionToken.cs b/src/Stripe.net/Entities/Terminal/ConnectionTokens/ConnectionToken.cs new file mode 100644 index 0000000000..4f42c451ba --- /dev/null +++ b/src/Stripe.net/Entities/Terminal/ConnectionTokens/ConnectionToken.cs @@ -0,0 +1,16 @@ +namespace Stripe.Terminal +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class ConnectionToken : StripeEntity, IHasObject + { + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("secret")] + public string Secret { get; set; } + } +} diff --git a/src/Stripe.net/Entities/Terminal/Locations/Location.cs b/src/Stripe.net/Entities/Terminal/Locations/Location.cs new file mode 100644 index 0000000000..84cc0aebd3 --- /dev/null +++ b/src/Stripe.net/Entities/Terminal/Locations/Location.cs @@ -0,0 +1,22 @@ +namespace Stripe.Terminal +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class Location : StripeEntity, IHasId, IHasObject + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("address")] + public Address Address { get; set; } + + [JsonProperty("display_name")] + public string DisplayName { get; set; } + } +} diff --git a/src/Stripe.net/Entities/Terminal/Readers/Reader.cs b/src/Stripe.net/Entities/Terminal/Readers/Reader.cs new file mode 100644 index 0000000000..ddb565ce8f --- /dev/null +++ b/src/Stripe.net/Entities/Terminal/Readers/Reader.cs @@ -0,0 +1,37 @@ +namespace Stripe.Terminal +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class Reader : StripeEntity, IHasObject + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("device_sw_version")] + public string DeviceSwVersion { get; set; } + + [JsonProperty("device_type")] + public string DeviceType { get; set; } + + [JsonProperty("ip_address")] + public string IpAddress { get; set; } + + [JsonProperty("label")] + public string Label { get; set; } + + [JsonProperty("location")] + public string Location { get; set; } + + [JsonProperty("serial_number")] + public string SerialNumber { get; set; } + + [JsonProperty("status")] + public string Status { get; set; } + } +} diff --git a/src/Stripe.net/Infrastructure/JsonConverters/StripeObjectConverter.cs b/src/Stripe.net/Infrastructure/JsonConverters/StripeObjectConverter.cs index 0b5f776003..a55382c155 100644 --- a/src/Stripe.net/Infrastructure/JsonConverters/StripeObjectConverter.cs +++ b/src/Stripe.net/Infrastructure/JsonConverters/StripeObjectConverter.cs @@ -60,6 +60,9 @@ protected override Dictionary> ObjectsToMapperF { "source_transaction", Mapper.MapFromJson }, { "subscription", Mapper.MapFromJson }, { "subscription_item", Mapper.MapFromJson }, + { "terminal.connection_token", Mapper.MapFromJson }, + { "terminal.location", Mapper.MapFromJson }, + { "terminal.reader", Mapper.MapFromJson }, { "three_d_secure", Mapper.MapFromJson }, { "token", Mapper.MapFromJson }, { "topup", Mapper.MapFromJson }, diff --git a/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenCreateOptions.cs b/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenCreateOptions.cs new file mode 100644 index 0000000000..c51bdf385e --- /dev/null +++ b/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenCreateOptions.cs @@ -0,0 +1,8 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class ConnectionTokenCreateOptions : BaseOptions + { + } +} diff --git a/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenService.cs b/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenService.cs new file mode 100644 index 0000000000..1fb7f8659f --- /dev/null +++ b/src/Stripe.net/Services/Terminal/ConnectionTokens/ConnectionTokenService.cs @@ -0,0 +1,33 @@ +namespace Stripe.Terminal +{ + using System; + using System.Threading; + using System.Threading.Tasks; + using Stripe.Infrastructure; + + public class ConnectionTokenService : Service, + ICreatable + { + public ConnectionTokenService() + : base(null) + { + } + + public ConnectionTokenService(string apiKey) + : base(apiKey) + { + } + + public override string BasePath => "/terminal/connection_tokens"; + + public virtual ConnectionToken Create(ConnectionTokenCreateOptions options = null, RequestOptions requestOptions = null) + { + return this.CreateEntity(options, requestOptions); + } + + public virtual Task CreateAsync(ConnectionTokenCreateOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.CreateEntityAsync(options, requestOptions, cancellationToken); + } + } +} diff --git a/src/Stripe.net/Services/Terminal/Locations/LocationCreateOptions.cs b/src/Stripe.net/Services/Terminal/Locations/LocationCreateOptions.cs new file mode 100644 index 0000000000..27d70e4de1 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Locations/LocationCreateOptions.cs @@ -0,0 +1,8 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class LocationCreateOptions : LocationSharedOptions + { + } +} diff --git a/src/Stripe.net/Services/Terminal/Locations/LocationListOptions.cs b/src/Stripe.net/Services/Terminal/Locations/LocationListOptions.cs new file mode 100644 index 0000000000..4927a3aecf --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Locations/LocationListOptions.cs @@ -0,0 +1,10 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class LocationListOptions : ListOptions + { + [JsonProperty("operator_account")] + public string OperatorAccount { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Locations/LocationService.cs b/src/Stripe.net/Services/Terminal/Locations/LocationService.cs new file mode 100644 index 0000000000..193dd813c5 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Locations/LocationService.cs @@ -0,0 +1,63 @@ +namespace Stripe.Terminal +{ + using System; + using System.Threading; + using System.Threading.Tasks; + using Stripe.Infrastructure; + + public class LocationService : Service, + ICreatable + { + public LocationService() + : base(null) + { + } + + public LocationService(string apiKey) + : base(apiKey) + { + } + + public override string BasePath => "/terminal/locations"; + + public virtual Location Create(LocationCreateOptions options, RequestOptions requestOptions = null) + { + return this.CreateEntity(options, requestOptions); + } + + public virtual Task CreateAsync(LocationCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.CreateEntityAsync(options, requestOptions, cancellationToken); + } + + public virtual Location Get(string locationId, RequestOptions requestOptions = null) + { + return this.GetEntity(locationId, null, requestOptions); + } + + public virtual Task GetAsync(string locationId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.GetEntityAsync(locationId, null, requestOptions, cancellationToken); + } + + public virtual StripeList List(LocationListOptions options = null, RequestOptions requestOptions = null) + { + return this.ListEntities(options, requestOptions); + } + + public virtual Task> ListAsync(LocationListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.ListEntitiesAsync(options, requestOptions, cancellationToken); + } + + public virtual Location Update(string locationId, LocationUpdateOptions options, RequestOptions requestOptions = null) + { + return this.UpdateEntity(locationId, options, requestOptions); + } + + public virtual Task UpdateAsync(string locationId, LocationUpdateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.UpdateEntityAsync(locationId, options, requestOptions, cancellationToken); + } + } +} diff --git a/src/Stripe.net/Services/Terminal/Locations/LocationSharedOptions.cs b/src/Stripe.net/Services/Terminal/Locations/LocationSharedOptions.cs new file mode 100644 index 0000000000..694db26f08 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Locations/LocationSharedOptions.cs @@ -0,0 +1,13 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class LocationSharedOptions : BaseOptions + { + [JsonProperty("address")] + public AddressOptions Address { get; set; } + + [JsonProperty("display_name")] + public string DisplayName { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Locations/LocationUpdateOptions.cs b/src/Stripe.net/Services/Terminal/Locations/LocationUpdateOptions.cs new file mode 100644 index 0000000000..c9b1496b73 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Locations/LocationUpdateOptions.cs @@ -0,0 +1,10 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class LocationUpdateOptions : LocationSharedOptions + { + [JsonProperty("operator_account")] + public string OperatorAccount { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Readers/ReaderCreateOptions.cs b/src/Stripe.net/Services/Terminal/Readers/ReaderCreateOptions.cs new file mode 100644 index 0000000000..16270baae4 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Readers/ReaderCreateOptions.cs @@ -0,0 +1,13 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class ReaderCreateOptions : ReaderSharedOptions + { + [JsonProperty("location")] + public string Location { get; set; } + + [JsonProperty("registration_code")] + public string RegistrationCode { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Readers/ReaderListOptions.cs b/src/Stripe.net/Services/Terminal/Readers/ReaderListOptions.cs new file mode 100644 index 0000000000..9aabe215ce --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Readers/ReaderListOptions.cs @@ -0,0 +1,13 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class ReaderListOptions : ListOptions + { + [JsonProperty("location")] + public string Location { get; set; } + + [JsonProperty("operator_account")] + public string OperatorAccount { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Readers/ReaderService.cs b/src/Stripe.net/Services/Terminal/Readers/ReaderService.cs new file mode 100644 index 0000000000..997b899e11 --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Readers/ReaderService.cs @@ -0,0 +1,63 @@ +namespace Stripe.Terminal +{ + using System; + using System.Threading; + using System.Threading.Tasks; + using Stripe.Infrastructure; + + public class ReaderService : Service, + ICreatable + { + public ReaderService() + : base(null) + { + } + + public ReaderService(string apiKey) + : base(apiKey) + { + } + + public override string BasePath => "/terminal/readers"; + + public virtual Reader Create(ReaderCreateOptions options, RequestOptions requestOptions = null) + { + return this.CreateEntity(options, requestOptions); + } + + public virtual Task CreateAsync(ReaderCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.CreateEntityAsync(options, requestOptions, cancellationToken); + } + + public virtual Reader Get(string readerId, RequestOptions requestOptions = null) + { + return this.GetEntity(readerId, null, requestOptions); + } + + public virtual Task GetAsync(string readerId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.GetEntityAsync(readerId, null, requestOptions, cancellationToken); + } + + public virtual StripeList List(ReaderListOptions options = null, RequestOptions requestOptions = null) + { + return this.ListEntities(options, requestOptions); + } + + public virtual Task> ListAsync(ReaderListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.ListEntitiesAsync(options, requestOptions, cancellationToken); + } + + public virtual Reader Update(string readerId, ReaderUpdateOptions options, RequestOptions requestOptions = null) + { + return this.UpdateEntity(readerId, options, requestOptions); + } + + public virtual Task UpdateAsync(string readerId, ReaderUpdateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.UpdateEntityAsync(readerId, options, requestOptions, cancellationToken); + } + } +} diff --git a/src/Stripe.net/Services/Terminal/Readers/ReaderSharedOptions.cs b/src/Stripe.net/Services/Terminal/Readers/ReaderSharedOptions.cs new file mode 100644 index 0000000000..eff59ba01b --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Readers/ReaderSharedOptions.cs @@ -0,0 +1,10 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class ReaderSharedOptions : BaseOptions + { + [JsonProperty("label")] + public string Label { get; set; } + } +} diff --git a/src/Stripe.net/Services/Terminal/Readers/ReaderUpdateOptions.cs b/src/Stripe.net/Services/Terminal/Readers/ReaderUpdateOptions.cs new file mode 100644 index 0000000000..f64626269d --- /dev/null +++ b/src/Stripe.net/Services/Terminal/Readers/ReaderUpdateOptions.cs @@ -0,0 +1,10 @@ +namespace Stripe.Terminal +{ + using Newtonsoft.Json; + + public class ReaderUpdateOptions : ReaderSharedOptions + { + [JsonProperty("operator_account")] + public string OperatorAccount { get; set; } + } +} diff --git a/src/StripeTests/Entities/Terminal/ConnectionTokens/ConnectionTokenTest.cs b/src/StripeTests/Entities/Terminal/ConnectionTokens/ConnectionTokenTest.cs new file mode 100644 index 0000000000..56e06738d6 --- /dev/null +++ b/src/StripeTests/Entities/Terminal/ConnectionTokens/ConnectionTokenTest.cs @@ -0,0 +1,25 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + + using Newtonsoft.Json; + using Stripe; + using Stripe.Terminal; + using Xunit; + + public class ConnectionTokenTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + var json = GetResourceAsString("api_fixtures.connection_token.json"); + var connectionToken = Mapper.MapFromJson(json); + Assert.NotNull(connectionToken); + Assert.IsType(connectionToken); + Assert.NotNull(connectionToken.Secret); + Assert.Equal("terminal.connection_token", connectionToken.Object); + } + } +} diff --git a/src/StripeTests/Entities/Terminal/Locations/LocationTest.cs b/src/StripeTests/Entities/Terminal/Locations/LocationTest.cs new file mode 100644 index 0000000000..30d2381589 --- /dev/null +++ b/src/StripeTests/Entities/Terminal/Locations/LocationTest.cs @@ -0,0 +1,25 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + + using Newtonsoft.Json; + using Stripe; + using Stripe.Terminal; + using Xunit; + + public class LocationTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + string json = GetFixture("/v1/terminal/locations/loc_123"); + var location = Mapper.MapFromJson(json); + Assert.NotNull(location); + Assert.IsType(location); + Assert.NotNull(location.Id); + Assert.Equal("terminal.location", location.Object); + } + } +} diff --git a/src/StripeTests/Entities/Terminal/Readers/ReaderTest.cs b/src/StripeTests/Entities/Terminal/Readers/ReaderTest.cs new file mode 100644 index 0000000000..337d473800 --- /dev/null +++ b/src/StripeTests/Entities/Terminal/Readers/ReaderTest.cs @@ -0,0 +1,25 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Threading.Tasks; + + using Newtonsoft.Json; + using Stripe; + using Stripe.Terminal; + using Xunit; + + public class ReaderTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + string json = GetFixture("/v1/terminal/readers/ds_123"); + var reader = Mapper.MapFromJson(json); + Assert.NotNull(reader); + Assert.IsType(reader); + Assert.NotNull(reader.Id); + Assert.Equal("terminal.reader", reader.Object); + } + } +} diff --git a/src/StripeTests/Resources/api_fixtures/connection_token.json b/src/StripeTests/Resources/api_fixtures/connection_token.json new file mode 100644 index 0000000000..cc66095d1f --- /dev/null +++ b/src/StripeTests/Resources/api_fixtures/connection_token.json @@ -0,0 +1,4 @@ +{ + "object": "terminal.connection_token", + "secret": "pst_test_123" +} \ No newline at end of file diff --git a/src/StripeTests/Services/Terminal/ConnectionTokens/ConnectionTokenServiceTest.cs b/src/StripeTests/Services/Terminal/ConnectionTokens/ConnectionTokenServiceTest.cs new file mode 100644 index 0000000000..4fb1be1c16 --- /dev/null +++ b/src/StripeTests/Services/Terminal/ConnectionTokens/ConnectionTokenServiceTest.cs @@ -0,0 +1,41 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe.Terminal; + using Xunit; + + public class ConnectionTokenServiceTest : BaseStripeTest + { + private ConnectionTokenService service; + private ConnectionTokenCreateOptions createOptions; + + public ConnectionTokenServiceTest() + { + this.service = new ConnectionTokenService(); + + this.createOptions = new ConnectionTokenCreateOptions + { + }; + } + + [Fact] + public void Create() + { + var connectionToken = this.service.Create(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/connection_tokens"); + Assert.NotNull(connectionToken); + } + + [Fact] + public async Task CreateAsync() + { + var connectionToken = await this.service.CreateAsync(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/connection_tokens"); + Assert.NotNull(connectionToken); + } + } +} diff --git a/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs b/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs new file mode 100644 index 0000000000..a6eaabb9c1 --- /dev/null +++ b/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs @@ -0,0 +1,114 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe; + using Stripe.Terminal; + using Xunit; + + public class LocationServiceTest : BaseStripeTest + { + private const string LocationId = "loc_123"; + + private LocationService service; + private LocationCreateOptions createOptions; + private LocationListOptions listOptions; + private LocationUpdateOptions updateOptions; + + public LocationServiceTest() + { + this.service = new LocationService(); + + this.createOptions = new LocationCreateOptions + { + Address = new AddressOptions + { + State = "CA", + City = "City", + Line1 = "Line1", + Line2 = "Line2", + PostalCode = "90210", + Country = "US", + }, + DisplayName = "my location", + }; + + this.listOptions = new LocationListOptions + { + OperatorAccount = "acct_123", + }; + + this.updateOptions = new LocationUpdateOptions + { + DisplayName = "my_location_update", + }; + } + + [Fact] + public void Create() + { + var location = this.service.Create(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/locations"); + Assert.NotNull(location); + } + + [Fact] + public async Task CreateAsync() + { + var location = await this.service.CreateAsync(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/locations"); + Assert.NotNull(location); + } + + [Fact] + public void Get() + { + var location = this.service.Get(LocationId); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/locations/loc_123"); + Assert.NotNull(location); + } + + [Fact] + public async Task GetAsync() + { + var location = await this.service.GetAsync(LocationId); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/locations/loc_123"); + Assert.NotNull(location); + } + + [Fact] + public void List() + { + var locations = this.service.List(this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/locations"); + Assert.NotNull(locations); + } + + [Fact] + public async Task ListAsync() + { + var locations = await this.service.ListAsync(this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/locations"); + Assert.NotNull(locations); + } + + [Fact] + public void Update() + { + var location = this.service.Update(LocationId, this.updateOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/locations/loc_123"); + Assert.NotNull(location); + } + + [Fact] + public async Task UpdateAsync() + { + var location = await this.service.UpdateAsync(LocationId, this.updateOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/locations/loc_123"); + Assert.NotNull(location); + } + } +} diff --git a/src/StripeTests/Services/Terminal/Readers/ReaderServiceTest.cs b/src/StripeTests/Services/Terminal/Readers/ReaderServiceTest.cs new file mode 100644 index 0000000000..5721045cbe --- /dev/null +++ b/src/StripeTests/Services/Terminal/Readers/ReaderServiceTest.cs @@ -0,0 +1,106 @@ +namespace StripeTests.Terminal +{ + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe.Terminal; + using Xunit; + + public class ReaderServiceTest : BaseStripeTest + { + private const string ReaderId = "ds_123"; + + private ReaderService service; + private ReaderCreateOptions createOptions; + private ReaderListOptions listOptions; + private ReaderUpdateOptions updateOptions; + + public ReaderServiceTest() + { + this.service = new ReaderService(); + + this.createOptions = new ReaderCreateOptions + { + Label = "my_reader", + Location = "loc_123", + RegistrationCode = "a-b-c", + }; + + this.listOptions = new ReaderListOptions + { + Location = "loc_123", + }; + + this.updateOptions = new ReaderUpdateOptions + { + Label = "my_reader_update", + }; + } + + [Fact] + public void Create() + { + var reader = this.service.Create(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/readers"); + Assert.NotNull(reader); + } + + [Fact] + public async Task CreateAsync() + { + var reader = await this.service.CreateAsync(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/readers"); + Assert.NotNull(reader); + } + + [Fact] + public void Get() + { + var reader = this.service.Get(ReaderId); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/readers/ds_123"); + Assert.NotNull(reader); + } + + [Fact] + public async Task GetAsync() + { + var reader = await this.service.GetAsync(ReaderId); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/readers/ds_123"); + Assert.NotNull(reader); + } + + [Fact] + public void List() + { + var readers = this.service.List(this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/readers"); + Assert.NotNull(readers); + } + + [Fact] + public async Task ListAsync() + { + var readers = await this.service.ListAsync(this.listOptions); + this.AssertRequest(HttpMethod.Get, "/v1/terminal/readers"); + Assert.NotNull(readers); + } + + [Fact] + public void Update() + { + var reader = this.service.Update(ReaderId, this.updateOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/readers/ds_123"); + Assert.NotNull(reader); + } + + [Fact] + public async Task UpdateAsync() + { + var reader = await this.service.UpdateAsync(ReaderId, this.updateOptions); + this.AssertRequest(HttpMethod.Post, "/v1/terminal/readers/ds_123"); + Assert.NotNull(reader); + } + } +}