Skip to content

Commit

Permalink
added 3d secure service/entity, closes #651 (#656)
Browse files Browse the repository at this point in the history
also fixed issue with tests for transfers not passing due to account not being managed, per new stripe assertion

* tests

* renamed Stripe3DSecure to ThreeDSecure on card

* fixed tests that needed to be a managed account, per stripe assertion change
  • Loading branch information
jaymedavis authored Oct 26, 2016
1 parent 28fd442 commit b9e98e4
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Stripe.Portable/Stripe.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<Compile Include="..\Stripe\Entities\Source.cs">
<Link>Entities\Source.cs</Link>
</Compile>
<Compile Include="..\Stripe\Entities\Stripe3DSecure.cs">
<Link>Entities\Stripe3DSecure.cs</Link>
</Compile>
<Compile Include="..\Stripe\Entities\StripeAccount.cs">
<Link>Entities\StripeAccount.cs</Link>
</Compile>
Expand Down Expand Up @@ -247,6 +250,12 @@
<Compile Include="..\Stripe\Properties\InternalsVisibleTo.cs">
<Link>Properties\InternalsVisibleTo.cs</Link>
</Compile>
<Compile Include="..\Stripe\Services\3DSecure\Stripe3DSecureCreateOptions.cs">
<Link>Services\3DSecure\Stripe3DSecureCreateOptions.cs</Link>
</Compile>
<Compile Include="..\Stripe\Services\3DSecure\Stripe3DSecureService.cs">
<Link>Services\3DSecure\Stripe3DSecureService.cs</Link>
</Compile>
<Compile Include="..\Stripe\Services\Account\StripeAccountBankAccountOptions.cs">
<Link>Services\Account\StripeAccountBankAccountOptions.cs</Link>
</Compile>
Expand Down
43 changes: 43 additions & 0 deletions src/Stripe.Tests/3d_secure/when_creating_3d_secure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Machine.Specifications;

namespace Stripe.Tests
{
public class when_creating_3d_secure
{
private static StripeToken _token;
private static Stripe3DSecure _3DSecure;

private Establish context = () =>
{
var tokenOptions = test_data.stripe_token_create_options.Valid();
tokenOptions.Card.Number = "4000000000003055";

_token = new StripeTokenService().Create(tokenOptions);
};

Because of = () =>
_3DSecure = new Stripe3DSecureService().Create(new Stripe3DSecureCreateOptions
{
Amount = 1000,
Currency = "usd",
ReturnUrl = "http://3d-secure-needs-no-glasses.com",
CardTokenOrCardId = _token.Id
});

It should_have_a_3d_secure_object = () =>
_3DSecure.ShouldNotBeNull();

It should_have_the_right_amount = () =>
_3DSecure.Amount.ShouldEqual(1000);

It should_have_the_right_currency = () =>
_3DSecure.Currency.ShouldEqual("usd");

It should_have_a_redirect_url = () =>
_3DSecure.RedirectUrl.ShouldContain("http");

It should_have_a_card_with_3d_secure_hash = () =>
_3DSecure.Card.ThreeDSecure.Keys.ShouldContain("supported");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Machine.Specifications;

namespace Stripe.Tests
{
public class when_creating_3d_secure_for_a_customer
{
private static StripeCustomer _customer;
private static Stripe3DSecure _3DSecure;

private Establish context = () =>
{
var customerOptions = test_data.stripe_customer_create_options.ValidCard();
_customer = new StripeCustomerService().Create(customerOptions);
};

Because of = () =>
_3DSecure = new Stripe3DSecureService().Create(new Stripe3DSecureCreateOptions
{
Amount = 1000,
Currency = "usd",
ReturnUrl = "http://3d-secure-needs-no-glasses.com",
CardTokenOrCardId = _customer.DefaultSourceId,
CustomerId = _customer.Id
});

It should_have_a_3d_secure_object = () =>
_3DSecure.ShouldNotBeNull();

It should_have_the_right_amount = () =>
_3DSecure.Amount.ShouldEqual(1000);

It should_have_the_right_currency = () =>
_3DSecure.Currency.ShouldEqual("usd");
}
}
2 changes: 2 additions & 0 deletions src/Stripe.Tests/Stripe.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="3d_secure\when_creating_3d_secure_for_a_customer.cs" />
<Compile Include="3d_secure\when_creating_3d_secure.cs" />
<Compile Include="account\account_behaviors.cs" />
<Compile Include="account\test_data\stripe_account_create_options.cs" />
<Compile Include="account\when_creating_an_account_with_a_legal_entity.cs" />
Expand Down
5 changes: 4 additions & 1 deletion src/Stripe.Tests/transfers/when_creating_a_transfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class when_creating_a_transfer

Establish context = () =>
{
var account = new StripeAccountService().Create(test_data.stripe_account_create_options.ValidAccountWithCard());
var accountOptions = test_data.stripe_account_create_options.ValidAccountWithCard();
accountOptions.Managed = true;

var account = new StripeAccountService().Create(accountOptions);

_stripeTransferService = new StripeTransferService();
StripeTransferCreateOptions = test_data.stripe_transfer_create_options.ValidForDestination(account.Id);
Expand Down
37 changes: 37 additions & 0 deletions src/Stripe/Entities/Stripe3DSecure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Newtonsoft.Json;
using Stripe.Infrastructure;

namespace Stripe
{
public class Stripe3DSecure : StripeObject
{
[JsonProperty("object")]
public string Object { get; set; }

[JsonProperty("amount")]
public int Amount { get; set; }

[JsonProperty("authenticated")]
public bool Authenticated { get; set; }

[JsonProperty("card")]
public StripeCard Card { get; set; }

[JsonProperty("created")]
[JsonConverter(typeof(StripeDateTimeConverter))]
public DateTime Created { get; set; }

[JsonProperty("currency")]
public string Currency { get; set; }

[JsonProperty("livemode")]
public bool LiveMode { get; set; }

[JsonProperty("redirect_url")]
public string RedirectUrl { get; set; }

[JsonProperty("status")]
public string Status { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/Stripe/Entities/StripeCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public class StripeCard : StripeObject
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("three_d_secure")]
public Dictionary<string, string> ThreeDSecure { get; set; }

[JsonProperty("tokenization_method")]
public string TokenizationMethod { get; set; }

Expand Down
1 change: 0 additions & 1 deletion src/Stripe/Entities/StripeCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class StripeCustomer : StripeObject
[JsonProperty("account_balance")]
public int AccountBalance { get; set; }


[JsonProperty("created")]
[JsonConverter(typeof(StripeDateTimeConverter))]
public DateTime Created { get; set; }
Expand Down
25 changes: 25 additions & 0 deletions src/Stripe/Services/3DSecure/Stripe3DSecureCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace Stripe
{
public class Stripe3DSecureCreateOptions
{
[JsonProperty("amount")]
public int Amount { get; set; }

[JsonProperty("currency")]
public string Currency { get; set; }

[JsonProperty("return_url")]
public string ReturnUrl { get; set; }

/// <summary>
/// If you pass a card id, you must also pass the customer id
/// </summary>
[JsonProperty("card")]
public string CardTokenOrCardId { get; set; }

[JsonProperty("customer")]
public string CustomerId { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/Stripe/Services/3DSecure/Stripe3DSecureService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Stripe
{
public class Stripe3DSecureService : StripeBasicService<Stripe3DSecure>
{
public Stripe3DSecureService(string apiKey = null) : base(apiKey) { }

// Sync
public virtual Stripe3DSecure Create(Stripe3DSecureCreateOptions createOptions, StripeRequestOptions requestOptions = null)
{
return Post($"{Urls.BaseUrl}/3d_secure", requestOptions, createOptions);
}




// Async
public virtual Task<Stripe3DSecure> CreateAsync(Stripe3DSecureCreateOptions createOptions, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return PostAsync($"{Urls.BaseUrl}/3d_secure", requestOptions, cancellationToken, createOptions);
}
}
}
3 changes: 3 additions & 0 deletions src/Stripe/Stripe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Constants\BankAccountHolderType.cs" />
<Compile Include="Constants\StripeFilePurpose.cs" />
<Compile Include="Entities\CustomerBankAccount.cs" />
<Compile Include="Entities\Stripe3DSecure.cs" />
<Compile Include="Entities\Source.cs" />
<Compile Include="Entities\CountrySpec.cs" />
<Compile Include="Entities\StripeDeleted.cs" />
Expand Down Expand Up @@ -92,6 +93,8 @@
<Compile Include="Infrastructure\ExpandableProperty.cs" />
<Compile Include="Infrastructure\Client.cs" />
<Compile Include="Infrastructure\SourceConverter.cs" />
<Compile Include="Services\3DSecure\Stripe3DSecureService.cs" />
<Compile Include="Services\3DSecure\Stripe3DSecureCreateOptions.cs" />
<Compile Include="Services\ApplicationFeeRefunds\StripeApplicationFeeRefundUpdateOptions.cs" />
<Compile Include="Services\ApplicationFeeRefunds\StripeApplicationFeeRefundCreateOptions.cs" />
<Compile Include="Services\ApplicationFeeRefunds\StripeApplicationFeeRefundService.cs" />
Expand Down

0 comments on commit b9e98e4

Please sign in to comment.