-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for radar.early_warning_fraud resource (#1626)
- Loading branch information
Showing
8 changed files
with
241 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Stripe.net/Entities/Radar/EarlyFraudWarnings/EarlyFraudWarning.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Stripe.net/Services/Radar/EarlyFraudWarnings/EarlyFraudWarningListOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Stripe.net/Services/Radar/EarlyFraudWarnings/EarlyFraudWarningService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/StripeTests/Entities/Radar/EarlyFraudWarnings/EarlyFraudWarningTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/StripeTests/Services/Radar/EarlyFraudWarnings/EarlyFraudWarningServiceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters