Skip to content

Commit

Permalink
Merge pull request #1071 from stripe/remi-add-account-debits
Browse files Browse the repository at this point in the history
Add support for account debits
  • Loading branch information
ob-stripe authored Dec 26, 2017
2 parents 5074afd + a323a9e commit 7e8b64b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Machine.Specifications;

namespace Stripe.Tests
{
public class when_creating_a_charge_with_a_stripe_account
{
private static StripeAccount _stripeAccount;
private static StripeCharge _stripeCharge;

Establish context = () =>
{
// create a new custom account
_stripeAccount = new StripeAccountService().Create(new StripeAccountCreateOptions()
{
Country = "US",
Type = StripeAccountType.Custom
});
};

Because of = () =>
{
// charge the customer something
_stripeCharge = new StripeChargeService().Create(new StripeChargeCreateOptions()
{
Amount = 100,
Currency = "usd",
SourceTokenOrExistingSourceId = _stripeAccount.Id
});
};

It should_have_the_right_source = () =>
_stripeCharge.Source.Account.ShouldNotBeNull();

It should_not_have_the_wrong_source = () =>
_stripeCharge.Source.Card.ShouldBeNull();

It should_have_the_right_source_type = () =>
_stripeCharge.Source.Type.ShouldEqual(SourceType.Account);

It should_have_the_right_id = () =>
_stripeCharge.Source.Id.ShouldEqual(_stripeAccount.Id);

It should_deserialize_the_account_properly = () =>
_stripeCharge.Source.Account.Id.ShouldEqual(_stripeAccount.Id);
}
}
2 changes: 2 additions & 0 deletions src/Stripe.net/Entities/Source.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Stripe
{
public enum SourceType
{
Account,
Card,
BankAccount,
Deleted
Expand All @@ -15,6 +16,7 @@ public class Source : StripeEntityWithId
{
public SourceType Type { get; set; }

public StripeAccount Account { get; set; }
public StripeDeleted Deleted { get; set; }
public StripeCard Card { get; set; }
public StripeBankAccount BankAccount { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
Id = incoming.SelectToken("id").ToString()
};

if (incoming.SelectToken("object")?.ToString() == "account")
{
source.Type = SourceType.Account;
source.Account = Mapper<StripeAccount>.MapFromJson(incoming.ToString());
}

if (incoming.SelectToken("object")?.ToString() == "bank_account")
{
source.Type = SourceType.BankAccount;
Expand Down

0 comments on commit 7e8b64b

Please sign in to comment.