Skip to content

Commit

Permalink
Add support for the Account Link resource
Browse files Browse the repository at this point in the history
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
  • Loading branch information
remi-stripe committed Dec 8, 2018
1 parent 6af79c7 commit 173dab3
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Stripe.net/Entities/AccountLinks/AccountLink.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
25 changes: 25 additions & 0 deletions src/Stripe.net/Services/AccountLinks/AccountLinkCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
34 changes: 34 additions & 0 deletions src/Stripe.net/Services/AccountLinks/AccountLinkService.cs
Original file line number Diff line number Diff line change
@@ -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<AccountLink>,
ICreatable<AccountLink, AccountLinkCreateOptions>
{
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<AccountLink> CreateAsync(AccountLinkCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.CreateEntityAsync(options, requestOptions, cancellationToken);
}
}
}
19 changes: 19 additions & 0 deletions src/StripeTests/Entities/Coupons/AccountLinkTest.cs
Original file line number Diff line number Diff line change
@@ -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<AccountLink>(json);
Assert.NotNull(accountLink);
Assert.IsType<AccountLink>(accountLink);
Assert.Equal("account_link", accountLink.Object);
}
}
}
6 changes: 6 additions & 0 deletions src/StripeTests/Resources/api_fixtures/account_link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"object": "account_link",
"created": 1544220862,
"expires_at": 1544221162,
"url": "https://stripe.com/hv/12345"
}
47 changes: 47 additions & 0 deletions src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public LocationServiceTest()

this.listOptions = new LocationListOptions
{
OperatorAccount = "acct_123",
};

this.updateOptions = new LocationUpdateOptions
Expand Down

0 comments on commit 173dab3

Please sign in to comment.