-
Notifications
You must be signed in to change notification settings - Fork 572
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 /v1/topups endpoints #1110
Changes from 4 commits
613a80a
9f512d0
ea64c21
3492e7b
fffc954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Stripe.Tests.Xunit | ||
{ | ||
public class topups_fixture | ||
{ | ||
public StripeTopupCreateOptions TopupCreateOptions { get; } | ||
public StripeTopupUpdateOptions TopupUpdateOptions { get; } | ||
public StripeTopupListOptions TopupListOptions { get; } | ||
|
||
public StripeTopup Topup { get; } | ||
public StripeTopup TopupUpdated { get; } | ||
public StripeTopup TopupRetrieved { get; } | ||
public StripeList<StripeTopup> TopupList { get; } | ||
|
||
public topups_fixture() | ||
{ | ||
StripeSource source = new StripeSourceService(Cache.ApiKey).Create(new StripeSourceCreateOptions | ||
{ | ||
Type = StripeSourceType.AchCreditTransfer, | ||
Currency = "usd", | ||
Owner = new StripeSourceOwner | ||
{ | ||
Email = "amount_4242@example.com" | ||
} | ||
}); | ||
|
||
// Sleep for 5 seconds to ensure the Source is chargeable | ||
// 1 or 2 seconds are unfortunately not enough. | ||
System.Threading.Thread.Sleep(5000); | ||
|
||
TopupCreateOptions = new StripeTopupCreateOptions | ||
{ | ||
Amount = 1000, | ||
Currency = "usd", | ||
Description = "Test Topup", | ||
SourceTokenOrExistingSourceId = source.Id, | ||
StatementDescriptor = "Descriptor", | ||
}; | ||
|
||
TopupUpdateOptions = new StripeTopupUpdateOptions | ||
{ | ||
Metadata = new Dictionary<string, string>() | ||
{ | ||
{ "some-key", "some-value" } | ||
} | ||
}; | ||
|
||
var service = new StripeTopupService(Cache.ApiKey); | ||
Topup = service.Create(TopupCreateOptions); | ||
TopupUpdated = service.Update(Topup.Id, TopupUpdateOptions); | ||
TopupRetrieved = service.Get(Topup.Id); | ||
|
||
TopupListOptions = new StripeTopupListOptions | ||
{ | ||
Created = new StripeDateFilter { EqualTo = Topup.Created }, | ||
}; | ||
|
||
TopupList = service.List(TopupListOptions); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Stripe.Tests.Xunit | ||
{ | ||
public class creating_and_updating_topups : IClassFixture<topups_fixture> | ||
{ | ||
private readonly topups_fixture fixture; | ||
|
||
public creating_and_updating_topups(topups_fixture topupsFixture) | ||
{ | ||
fixture = topupsFixture; | ||
} | ||
|
||
[Fact] | ||
public void created_has_right_details() | ||
{ | ||
fixture.Topup.Should().NotBeNull(); | ||
fixture.Topup.Id.Should().StartWith("tu_"); | ||
fixture.Topup.Amount.Should().Be(fixture.TopupCreateOptions.Amount); | ||
fixture.Topup.Currency.Should().Be(fixture.TopupCreateOptions.Currency); | ||
fixture.Topup.Description.Should().Be(fixture.TopupCreateOptions.Description); | ||
fixture.Topup.StatementDescriptor.Should().Be(fixture.TopupCreateOptions.StatementDescriptor); | ||
} | ||
|
||
[Fact] | ||
public void get_is_not_null() | ||
{ | ||
fixture.TopupRetrieved.Should().NotBeNull(); | ||
fixture.TopupRetrieved.Id.Should().Be(fixture.Topup.Id); | ||
fixture.TopupRetrieved.Amount.Should().Be(fixture.Topup.Amount); | ||
fixture.TopupRetrieved.Currency.Should().Be(fixture.Topup.Currency); | ||
} | ||
|
||
[Fact] | ||
public void updated_has_the_right_metadata() | ||
{ | ||
fixture.TopupUpdated.Metadata.Keys.Should().BeEquivalentTo(fixture.TopupUpdateOptions.Metadata.Keys); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using FluentAssertions; | ||
using Stripe.Tests.Xunit; | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Stripe.Tests.XUnit | ||
{ | ||
public class when_listing_topups : IClassFixture<topups_fixture> | ||
{ | ||
private readonly topups_fixture fixture; | ||
private StripeList<StripeTopup> result; | ||
|
||
public when_listing_topups(topups_fixture topupsFixture) | ||
{ | ||
fixture = topupsFixture; | ||
result = fixture.TopupList; | ||
} | ||
|
||
[Fact] | ||
public void list_is_iterable() | ||
{ | ||
var count = 0; | ||
IEnumerable<StripeTopup> enumerable = result as IEnumerable<StripeTopup>; | ||
foreach (var obj in enumerable) | ||
{ | ||
count += 1; | ||
} | ||
Assert.Equal(result.ToList().Count > 0, true); | ||
Assert.Equal(result.ToList().Count, count); | ||
|
||
} | ||
|
||
[Fact] | ||
public void list_contents_equal() | ||
{ | ||
|
||
var datahash = new HashSet<String>(); | ||
foreach (var obj in result.Data) | ||
{ | ||
datahash.Add(obj.Id); | ||
} | ||
|
||
var enumhash = new HashSet<String>(); | ||
IEnumerable<StripeTopup> enumerable = result as IEnumerable<StripeTopup>; | ||
foreach (var obj in enumerable) | ||
{ | ||
enumhash.Add(obj.Id); | ||
} | ||
|
||
Assert.Equal(datahash, enumhash); | ||
|
||
} | ||
|
||
[Fact] | ||
public void list_contains_extra_attributes() | ||
{ | ||
Assert.NotNull(result.Object); | ||
Assert.Equal(result.Object, "list"); | ||
Assert.NotNull(result.Data); | ||
Assert.NotNull(result.Url); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
using Stripe.Infrastructure; | ||
|
||
namespace Stripe | ||
{ | ||
public class StripeTopup : StripeEntityWithId | ||
{ | ||
[JsonProperty("object")] | ||
public string Object { get; set; } | ||
|
||
/// <summary> | ||
/// A positive integer in the smallest currency unit (e.g., 100 cents to top up $1.00 or 100 to topup ¥100, a 0-decimal currency) representing how much to top up. The minimum amount is $0.50 US or equivalent in Top-up currency. | ||
/// </summary> | ||
[JsonProperty("amount")] | ||
public int Amount { get; set; } | ||
|
||
#region Expandable Balance Transaction | ||
/// <summary> | ||
/// ID of the balance transaction that describes the impact of this Top-up on your account balance (not including refunds or disputes). | ||
/// </summary> | ||
public string BalanceTransactionId { get; set; } | ||
|
||
[JsonIgnore] | ||
public StripeBalanceTransaction BalanceTransaction { get; set; } | ||
|
||
[JsonProperty("balance_transaction")] | ||
internal object InternalBalanceTransaction | ||
{ | ||
set | ||
{ | ||
StringOrObject<StripeBalanceTransaction>.Map(value, s => BalanceTransactionId = s, o => BalanceTransaction = o); | ||
} | ||
} | ||
#endregion | ||
|
||
[JsonProperty("created")] | ||
[JsonConverter(typeof(StripeDateTimeConverter))] | ||
public DateTime Created { get; set; } | ||
|
||
[JsonProperty("expected_availability_date")] | ||
[JsonConverter(typeof(StripeDateTimeConverter))] | ||
public DateTime? ExpectedAvailabilityDate { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weirdly this value is null in Test so I had to make it optional with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what you have here is correct given that it's also marked optional in the backend too. I'm not too sure that we should go around applying this too liberally because the On that note though. I was cross-referencing this with the API resource and noticed these fields are also optional:
Should we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think for strings it's fine. But it'd be great to figure out a better way than throwing the |
||
|
||
/// <summary> | ||
/// Three-letter ISO currency code representing the currency in which the Top-up was made. | ||
/// </summary> | ||
[JsonProperty("currency")] | ||
public string Currency { get; set; } | ||
|
||
[JsonProperty("description")] | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// Error code explaining reason for topup failure if available (see the errors section for a list of codes). | ||
/// </summary> | ||
[JsonProperty("failure_code")] | ||
public string FailureCode { get; set; } | ||
|
||
/// <summary> | ||
/// Message to user further explaining reason for topup failure if available. | ||
/// </summary> | ||
[JsonProperty("failure_message")] | ||
public string FailureMessage { get; set; } | ||
|
||
[JsonProperty("livemode")] | ||
public bool LiveMode { get; set; } | ||
|
||
/// <summary> | ||
/// A set of key/value pairs that you can attach to a topup object. It can be useful for storing additional information about the topup in a structured format. | ||
/// </summary> | ||
[JsonProperty("metadata")] | ||
public Dictionary<string, string> Metadata { get; set; } | ||
|
||
/// <summary> | ||
/// For most Stripe users, the source of every Top-up is a bank account. This hash is then the source object describing that bank account. | ||
/// </summary> | ||
[JsonProperty("source")] | ||
public Source Source { get; set; } | ||
|
||
/// <summary> | ||
/// Extra information about a topup. This will appear on your customer’s credit card statement. | ||
/// </summary> | ||
[JsonProperty("statement_descriptor")] | ||
public string StatementDescriptor { get; set; } | ||
|
||
/// <summary> | ||
/// The status of the payment is either succeeded, pending, or failed | ||
/// </summary> | ||
[JsonProperty("status")] | ||
public string Status { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Stripe | ||
{ | ||
public class StripeTopupCreateOptions : StripeBaseOptions | ||
{ | ||
/// <summary> | ||
/// A positive integer in the smallest currency unit (e.g., 100 cents to top up $1.00 or 100 to top up ¥100, a 0-decimal currency) representing how much to top up your Stripe balance. | ||
/// </summary> | ||
[JsonProperty("amount")] | ||
public int? Amount { get; set; } | ||
|
||
/// <summary> | ||
/// 3-letter ISO code for currency. | ||
/// </summary> | ||
[JsonProperty("currency")] | ||
public string Currency { get; set; } | ||
|
||
/// <summary> | ||
/// An arbitrary string which you can attach to a Top-up object. It is displayed when in the web interface alongside the Top-up. | ||
/// </summary> | ||
[JsonProperty("description")] | ||
public string Description { get; set; } | ||
|
||
/// <summary> | ||
/// A set of key/value pairs that you can attach to a Top-up object. It can be useful for storing additional information in a structured format. | ||
/// </summary> | ||
[JsonProperty("metadata")] | ||
public Dictionary<string, string> Metadata { get; set; } | ||
|
||
[JsonProperty("source")] | ||
public string SourceTokenOrExistingSourceId { get; set; } | ||
|
||
/// <summary> | ||
/// An arbitrary string to be displayed on your bank statement. This may be up to 22 characters. The statement description may not include <>"' characters, and will appear on your bank statement in capital letters. Non-ASCII characters are automatically stripped. While most banks display this information consistently, some may display it incorrectly or not at all. | ||
/// </summary> | ||
[JsonProperty("statement_descriptor")] | ||
public string StatementDescriptor { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Stripe | ||
{ | ||
public class StripeTopupListOptions : StripeListOptions | ||
{ | ||
[JsonProperty("created")] | ||
public StripeDateFilter Created { get; set; } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awful, but I can't see another way for now 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fuuu :/ Yeah, I don't know of one either.