From 173dab3982f01f2788fe578ba4a4e7d50f9246f4 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Fri, 7 Dec 2018 16:23:07 -0800 Subject: [PATCH] Add support for the Account Link resource Also fixed a test as the latest openapi spec removed support for it. It's now gated. Leaving in the library though to avoid a major version --- .../Entities/AccountLinks/AccountLink.cs | 24 ++++++++++ .../AccountLinks/AccountLinkCreateOptions.cs | 25 ++++++++++ .../AccountLinks/AccountLinkService.cs | 34 ++++++++++++++ .../Entities/Coupons/AccountLinkTest.cs | 19 ++++++++ .../Resources/api_fixtures/account_link.json | 6 +++ .../AccountLinks/AccountLinkServiceTest.cs | 47 +++++++++++++++++++ .../Terminal/Locations/LocationServiceTest.cs | 1 - 7 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 src/Stripe.net/Entities/AccountLinks/AccountLink.cs create mode 100644 src/Stripe.net/Services/AccountLinks/AccountLinkCreateOptions.cs create mode 100644 src/Stripe.net/Services/AccountLinks/AccountLinkService.cs create mode 100644 src/StripeTests/Entities/Coupons/AccountLinkTest.cs create mode 100644 src/StripeTests/Resources/api_fixtures/account_link.json create mode 100644 src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs diff --git a/src/Stripe.net/Entities/AccountLinks/AccountLink.cs b/src/Stripe.net/Entities/AccountLinks/AccountLink.cs new file mode 100644 index 0000000000..e2d61c3669 --- /dev/null +++ b/src/Stripe.net/Entities/AccountLinks/AccountLink.cs @@ -0,0 +1,24 @@ +namespace Stripe +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class AccountLink : StripeEntity, IHasObject + { + [JsonProperty("object")] + public string Object { get; set; } + + [JsonProperty("created")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime? Created { get; set; } + + [JsonProperty("expires_at")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime? ExpiresAt { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + } +} diff --git a/src/Stripe.net/Services/AccountLinks/AccountLinkCreateOptions.cs b/src/Stripe.net/Services/AccountLinks/AccountLinkCreateOptions.cs new file mode 100644 index 0000000000..aad05013f7 --- /dev/null +++ b/src/Stripe.net/Services/AccountLinks/AccountLinkCreateOptions.cs @@ -0,0 +1,25 @@ +namespace Stripe +{ + using System; + using System.Collections.Generic; + using Newtonsoft.Json; + using Stripe.Infrastructure; + + public class AccountLinkCreateOptions : BaseOptions + { + [JsonProperty("account")] + public string AccountId { get; set; } + + [JsonProperty("collect")] + public string Collect { get; set; } + + [JsonProperty("failure_url")] + public string FailureUrl { get; set; } + + [JsonProperty("success_url")] + public string SuccessUrl { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + } +} diff --git a/src/Stripe.net/Services/AccountLinks/AccountLinkService.cs b/src/Stripe.net/Services/AccountLinks/AccountLinkService.cs new file mode 100644 index 0000000000..d0fd83f7ea --- /dev/null +++ b/src/Stripe.net/Services/AccountLinks/AccountLinkService.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 AccountLinkService : Service, + ICreatable + { + public AccountLinkService() + : base(null) + { + } + + public AccountLinkService(string apiKey) + : base(apiKey) + { + } + + public override string BasePath => "/account_links"; + + public virtual AccountLink Create(AccountLinkCreateOptions options, RequestOptions requestOptions = null) + { + return this.CreateEntity(options, requestOptions); + } + + public virtual Task CreateAsync(AccountLinkCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) + { + return this.CreateEntityAsync(options, requestOptions, cancellationToken); + } + } +} diff --git a/src/StripeTests/Entities/Coupons/AccountLinkTest.cs b/src/StripeTests/Entities/Coupons/AccountLinkTest.cs new file mode 100644 index 0000000000..465d35a16d --- /dev/null +++ b/src/StripeTests/Entities/Coupons/AccountLinkTest.cs @@ -0,0 +1,19 @@ +namespace StripeTests +{ + using Newtonsoft.Json; + using Stripe; + using Xunit; + + public class AccountLinkTest : BaseStripeTest + { + [Fact] + public void Deserialize() + { + var json = GetResourceAsString("api_fixtures.account_link.json"); + var accountLink = JsonConvert.DeserializeObject(json); + Assert.NotNull(accountLink); + Assert.IsType(accountLink); + Assert.Equal("account_link", accountLink.Object); + } + } +} diff --git a/src/StripeTests/Resources/api_fixtures/account_link.json b/src/StripeTests/Resources/api_fixtures/account_link.json new file mode 100644 index 0000000000..3999b5c420 --- /dev/null +++ b/src/StripeTests/Resources/api_fixtures/account_link.json @@ -0,0 +1,6 @@ +{ + "object": "account_link", + "created": 1544220862, + "expires_at": 1544221162, + "url": "https://stripe.com/hv/12345" +} \ No newline at end of file diff --git a/src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs b/src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs new file mode 100644 index 0000000000..12a0464e07 --- /dev/null +++ b/src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs @@ -0,0 +1,47 @@ +namespace StripeTests +{ + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + + using Stripe; + using Xunit; + + public class AccountLinkServiceTest : BaseStripeTest + { + private AccountLinkService service; + private AccountLinkCreateOptions createOptions; + + public AccountLinkServiceTest() + { + this.service = new AccountLinkService(); + + this.createOptions = new AccountLinkCreateOptions() + { + AccountId = "acct_123", + Collect = "eventually_due", + FailureUrl = "https://stripe.com/failure", + SuccessUrl = "https://stripe.com/success", + Type = "custom_account_verification", + }; + } + + [Fact] + public void Create() + { + var accountLink = this.service.Create(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/account_links"); + Assert.NotNull(accountLink); + Assert.Equal("account_link", accountLink.Object); + } + + [Fact] + public async Task CreateAsync() + { + var accountLink = await this.service.CreateAsync(this.createOptions); + this.AssertRequest(HttpMethod.Post, "/v1/account_links"); + Assert.NotNull(accountLink); + Assert.Equal("account_link", accountLink.Object); + } + } +} diff --git a/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs b/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs index a6eaabb9c1..3398cf4f29 100644 --- a/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs +++ b/src/StripeTests/Services/Terminal/Locations/LocationServiceTest.cs @@ -38,7 +38,6 @@ public LocationServiceTest() this.listOptions = new LocationListOptions { - OperatorAccount = "acct_123", }; this.updateOptions = new LocationUpdateOptions