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 radar.early_warning_fraud resource #1626

Merged
merged 1 commit into from
May 24, 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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ environment:
COVERALLS_REPO_TOKEN:
secure: T0PmP8uyzCseacBCDRBlti2y9Tz5DL6fknea0MKWvbPYrzADmLY2/5kOTfYIsPUk
# If you bump this, don't forget to bump `MinimumMockVersion` in `StripeMockFixture.cs` as well.
STRIPE_MOCK_VERSION: 0.56.0
STRIPE_MOCK_VERSION: 0.57.0

deploy:
- provider: NuGet
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace Stripe.Radar
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class EarlyFraudWarning : StripeEntity, IHasId, IHasObject
{
/// <summary>Unique identifier for the object.</summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// String representing the object’s type. Objects of the same type share the same value.
/// </summary>
[JsonProperty("object")]
public string Object { get; set; }

/// <summary>
/// An EFW is actionable if it has not received a dispute and has not been fully refunded.
/// You may wish to proactively refund a charge that receives an EFW, in order to avoid
/// receiving a dispute later.
/// </summary>
[JsonProperty("actionable")]
public bool Actionable { get; set; }

#region Expandable Application

/// <summary>ID of the charge this early fraud warning is for.</summary>
[JsonIgnore]
public string ChargeId { get; set; }

[JsonIgnore]
public Charge Charge { get; set; }

[JsonProperty("application")]
internal object InternalCharge
{
get
{
return this.Charge ?? (object)this.ChargeId;
}

set
{
StringOrObject<Charge>.Map(value, s => this.ChargeId = s, o => this.Charge = o);
}
}
#endregion

/// <summary>Time at which the object was created.</summary>
[JsonProperty("created")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime Created { get; set; }

/// <summary>
/// The type of fraud labelled by the issuer. One of <c>card_never_received</c>,
/// <c>fraudulent_card_application</c>, <c>made_with_counterfeit_card</c>,
/// <c>made_with_lost_card</c>, <c>made_with_stolen_card</c>, <c>misc</c>,
/// <c>unauthorized_use_of_card</c>.
/// </summary>
[JsonProperty("fraud_type")]
public string FraudType { get; set; }

/// <summary>
/// Has the value <c>true</c> if the object exists in live mode or the value <c>false</c>
/// if the object exists in test mode.
/// </summary>
[JsonProperty("livemode")]
public bool Livemode { 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 @@ -56,6 +56,7 @@ internal static class StripeTypeRegistry
{ "person", typeof(Person) },
{ "plan", typeof(Plan) },
{ "product", typeof(Product) },
{ "radar.early_fraud_warning", typeof(Radar.EarlyFraudWarning) },
{ "radar.value_list", typeof(Radar.ValueList) },
{ "radar.value_list_item", typeof(Radar.ValueListItem) },
{ "recipient", typeof(Recipient) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Stripe.Radar
{
using Newtonsoft.Json;

public class EarlyFraudWarningListOptions : ListOptions
{
/// <summary>
/// Only return early fraud warnings for the charge specified by this charge ID.
/// </summary>
[JsonProperty("charge")]
public string Charge { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace Stripe.Radar
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public class EarlyFraudWarningService : Service<EarlyFraudWarning>,
IListable<EarlyFraudWarning, EarlyFraudWarningListOptions>,
IRetrievable<EarlyFraudWarning>
{
public EarlyFraudWarningService()
: base(null)
{
}

public EarlyFraudWarningService(string apiKey)
: base(apiKey)
{
}

public override string BasePath => "/radar/early_fraud_warnings";

public virtual EarlyFraudWarning Get(string earlyFraudWarningId, RequestOptions requestOptions = null)
{
return this.GetEntity(earlyFraudWarningId, null, requestOptions);
}

public virtual Task<EarlyFraudWarning> GetAsync(string earlyFraudWarningId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetEntityAsync(earlyFraudWarningId, null, requestOptions, cancellationToken);
}

public virtual StripeList<EarlyFraudWarning> List(EarlyFraudWarningListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntities(options, requestOptions);
}

public virtual Task<StripeList<EarlyFraudWarning>> ListAsync(EarlyFraudWarningListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.ListEntitiesAsync(options, requestOptions, cancellationToken);
}

public virtual IEnumerable<EarlyFraudWarning> ListAutoPaging(EarlyFraudWarningListOptions options = null, RequestOptions requestOptions = null)
{
return this.ListEntitiesAutoPaging(options, requestOptions);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace StripeTests.Radar
{
using Newtonsoft.Json;
using Stripe;
using Stripe.Radar;
using Xunit;

public class EarlyFraudWarningTest : BaseStripeTest
{
public EarlyFraudWarningTest(StripeMockFixture stripeMockFixture)
: base(stripeMockFixture)
{
}

[Fact]
public void Deserialize()
{
string json = this.GetFixture("/v1/radar/early_fraud_warnings/issfr_123");
var warning = JsonConvert.DeserializeObject<EarlyFraudWarning>(json);
Assert.NotNull(warning);
Assert.IsType<EarlyFraudWarning>(warning);
Assert.NotNull(warning.Id);
Assert.Equal("radar.early_fraud_warning", warning.Object);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace StripeTests.Radar
{
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

using Stripe.Radar;
using Xunit;

public class EarlyFraudWarningServiceTest : BaseStripeTest
{
private const string EarlyFraudWarningId = "issfr_123";

private readonly EarlyFraudWarningService service;
private readonly EarlyFraudWarningListOptions listOptions;

public EarlyFraudWarningServiceTest(MockHttpClientFixture mockHttpClientFixture)
: base(mockHttpClientFixture)
{
this.service = new EarlyFraudWarningService();

this.listOptions = new EarlyFraudWarningListOptions
{
Charge = "ch_123",
Limit = 1,
};
}

[Fact]
public void Get()
{
var warning = this.service.Get(EarlyFraudWarningId);
this.AssertRequest(HttpMethod.Get, "/v1/radar/early_fraud_warnings/issfr_123");
Assert.NotNull(warning);
Assert.Equal("radar.early_fraud_warning", warning.Object);
}

[Fact]
public async Task GetAsync()
{
var warning = await this.service.GetAsync(EarlyFraudWarningId);
this.AssertRequest(HttpMethod.Get, "/v1/radar/early_fraud_warnings/issfr_123");
Assert.NotNull(warning);
Assert.Equal("radar.early_fraud_warning", warning.Object);
}

[Fact]
public void List()
{
var warnings = this.service.List(this.listOptions);
this.AssertRequest(HttpMethod.Get, "/v1/radar/early_fraud_warnings");
Assert.NotNull(warnings);
Assert.Equal("list", warnings.Object);
Assert.Single(warnings.Data);
Assert.Equal("radar.early_fraud_warning", warnings.Data[0].Object);
}

[Fact]
public async Task ListAsync()
{
var warnings = await this.service.ListAsync(this.listOptions);
this.AssertRequest(HttpMethod.Get, "/v1/radar/early_fraud_warnings");
Assert.NotNull(warnings);
Assert.Equal("list", warnings.Object);
Assert.Single(warnings.Data);
Assert.Equal("radar.early_fraud_warning", warnings.Data[0].Object);
}

[Fact]
public void ListAutoPaging()
{
var warnings = this.service.ListAutoPaging(this.listOptions).ToList();
Assert.NotNull(warnings);
Assert.Equal("radar.early_fraud_warning", warnings[0].Object);
}
}
}
2 changes: 1 addition & 1 deletion src/StripeTests/StripeMockFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StripeMockFixture : IDisposable
/// <remarks>
/// If you bump this, don't forget to bump `STRIPE_MOCK_VERSION` in `appveyor.yml` as well.
/// </remarks>
private const string MockMinimumVersion = "0.56.0";
private const string MockMinimumVersion = "0.57.0";

private readonly string origApiBase;
private readonly string origFilesBase;
Expand Down