Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Account Link resource #1415

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}
1 change: 1 addition & 0 deletions src/Stripe.net/Infrastructure/StripeTypeRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static class StripeTypeRegistry
public static readonly ImmutableDictionary<string, Type> ObjectsToTypes = new Dictionary<string, Type>
{
{ "account", typeof(Account) },
{ "account_link", typeof(AccountLink) },
{ "apple_pay_domain", typeof(ApplePayDomain) },
{ "application", typeof(Application) },
{ "application_fee", typeof(ApplicationFee) },
Expand Down
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/AccountLinks/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"
}
48 changes: 48 additions & 0 deletions src/StripeTests/Services/AccountLinks/AccountLinkServiceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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(MockHttpClientFixture mockHttpClientFixture)
: base(mockHttpClientFixture)
{
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);
}
}
}