Skip to content

Commit

Permalink
Add support for Terminal resources
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Nov 12, 2018
1 parent 414fb62 commit ea8670c
Show file tree
Hide file tree
Showing 23 changed files with 672 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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; }
}
}
22 changes: 22 additions & 0 deletions src/Stripe.net/Entities/Terminal/Locations/Location.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
37 changes: 37 additions & 0 deletions src/Stripe.net/Entities/Terminal/Readers/Reader.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ protected override Dictionary<string, Func<string, IHasObject>> ObjectsToMapperF
{ "source_transaction", Mapper<SourceTransaction>.MapFromJson },
{ "subscription", Mapper<Subscription>.MapFromJson },
{ "subscription_item", Mapper<SubscriptionItem>.MapFromJson },
{ "terminal.connection_token", Mapper<Terminal.ConnectionToken>.MapFromJson },
{ "terminal.location", Mapper<Terminal.Location>.MapFromJson },
{ "terminal.reader", Mapper<Terminal.Reader>.MapFromJson },
{ "three_d_secure", Mapper<ThreeDSecure>.MapFromJson },
{ "token", Mapper<Token>.MapFromJson },
{ "topup", Mapper<Topup>.MapFromJson },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class ConnectionTokenCreateOptions : BaseOptions
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Stripe.Terminal
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class ConnectionTokenService : Service<ConnectionToken>,
ICreatable<ConnectionToken, ConnectionTokenCreateOptions>
{
public ConnectionTokenService()
: base(null)
{
}

public ConnectionTokenService(string apiKey)
: base(apiKey)
{
}

public override string BasePath => "/terminal/connection_tokens";

public virtual ConnectionToken Create(ConnectionTokenCreateOptions options, RequestOptions requestOptions = null)
{
return this.CreateEntity(options, requestOptions);
}

public virtual Task<ConnectionToken> CreateAsync(ConnectionTokenCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.CreateEntityAsync(options, requestOptions, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class LocationCreateOptions : LocationSharedOptions
{
}
}
10 changes: 10 additions & 0 deletions src/Stripe.net/Services/Terminal/Locations/LocationListOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class LocationListOptions : ListOptions
{
[JsonProperty("operator_account")]
public string OperatorAccount { get; set; }
}
}
63 changes: 63 additions & 0 deletions src/Stripe.net/Services/Terminal/Locations/LocationService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Stripe.Terminal
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class LocationService : Service<Location>,
ICreatable<Location, LocationCreateOptions>
{
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<Location> 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<Location> GetAsync(string locationId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetEntityAsync(locationId, null, requestOptions, cancellationToken);
}

public virtual StripeList<Location> List(LocationListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntities(options, requestOptions);
}

public virtual Task<StripeList<Location>> 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<Location> UpdateAsync(string locationId, LocationUpdateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.UpdateEntityAsync(locationId, options, requestOptions, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class LocationUpdateOptions : LocationSharedOptions
{
[JsonProperty("operator_account")]
public string OperatorAccount { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/Stripe.net/Services/Terminal/Readers/ReaderCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
13 changes: 13 additions & 0 deletions src/Stripe.net/Services/Terminal/Readers/ReaderListOptions.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
63 changes: 63 additions & 0 deletions src/Stripe.net/Services/Terminal/Readers/ReaderService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Stripe.Terminal
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class ReaderService : Service<Reader>,
ICreatable<Reader, ReaderCreateOptions>
{
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<Reader> 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<Reader> GetAsync(string readerId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetEntityAsync(readerId, null, requestOptions, cancellationToken);
}

public virtual StripeList<Reader> List(ReaderListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntities(options, requestOptions);
}

public virtual Task<StripeList<Reader>> 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<Reader> UpdateAsync(string readerId, ReaderUpdateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.UpdateEntityAsync(readerId, options, requestOptions, cancellationToken);
}
}
}
10 changes: 10 additions & 0 deletions src/Stripe.net/Services/Terminal/Readers/ReaderSharedOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class ReaderSharedOptions : BaseOptions
{
[JsonProperty("label")]
public string Label { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/Stripe.net/Services/Terminal/Readers/ReaderUpdateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Stripe.Terminal
{
using Newtonsoft.Json;

public class ReaderUpdateOptions : ReaderSharedOptions
{
[JsonProperty("operator_account")]
public string OperatorAccount { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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<ConnectionToken>.MapFromJson(json);
Assert.NotNull(connectionToken);
Assert.IsType<ConnectionToken>(connectionToken);
Assert.NotNull(connectionToken.Secret);
Assert.Equal("terminal.connection_token", connectionToken.Object);
}
}
}
Loading

0 comments on commit ea8670c

Please sign in to comment.