Skip to content

Commit

Permalink
Merge pull request #1272 from stripe/remi-add-reporting-resources
Browse files Browse the repository at this point in the history
Add support for Reporting resources
  • Loading branch information
ob-stripe authored Sep 6, 2018
2 parents 0c961a9 + f442a26 commit 82c414c
Show file tree
Hide file tree
Showing 13 changed files with 499 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Stripe.net/Entities/Reporting/Parameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Stripe.Reporting
{
using System;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class Parameters : StripeEntity
{
[JsonProperty("connected_account")]
public string ConnectedAccount { get; set; }

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

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

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

[JsonProperty("payout")]
public string Payout { get; set; }

[JsonProperty("reporting_category")]
public string ReportingCategory { get; set; }
}
}
39 changes: 39 additions & 0 deletions src/Stripe.net/Entities/Reporting/ReportRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Stripe.Reporting
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class ReportRun : StripeEntityWithId
{
[JsonProperty("object")]
public string Object { get; set; }

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

[JsonProperty("error")]
public string Error { get; set; }

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

[JsonProperty("parameters")]
public Parameters Parameters { get; set; }

[JsonProperty("reportType")]
public string ReportType { get; set; }

[JsonProperty("result")]
public StripeFileUpload Result { get; set; }

[JsonProperty("status")]
public string Status { get; set; }

[JsonProperty("succeeded_at")]
[JsonConverter(typeof(StripeDateTimeConverter))]
public DateTime SucceededAt { get; set; }
}
}
31 changes: 31 additions & 0 deletions src/Stripe.net/Entities/Reporting/ReportType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Stripe.Reporting
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class ReportType : StripeEntityWithId
{
[JsonProperty("object")]
public string Object { get; set; }

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

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

[JsonProperty("name")]
public string Name { get; set; }

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

[JsonProperty("version")]
public int Version { get; set; }
}
}
54 changes: 54 additions & 0 deletions src/Stripe.net/Services/Reporting/ReportRuns/ParametersOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Stripe.Reporting
{
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Stripe.Infrastructure;

public class ParametersOptions : INestedOptions
{
[JsonProperty("parameters[connected_account]")]
public string ConnectedAccount { get; set; }

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

public DateTime? IntervalEnd { get; set; }

[JsonProperty("parameters[interval_end]")]
internal long? IntervalEndInternal
{
get
{
if (!this.IntervalEnd.HasValue)
{
return null;
}

return EpochTime.ConvertDateTimeToEpoch(this.IntervalEnd.Value);
}
}

public DateTime? IntervalStart { get; set; }

[JsonProperty("parameters[interval_start]")]
internal long? IntervalStartInternal
{
get
{
if (!this.IntervalStart.HasValue)
{
return null;
}

return EpochTime.ConvertDateTimeToEpoch(this.IntervalStart.Value);
}
}

[JsonProperty("parameters[payout]")]
public string Payout { get; set; }

[JsonProperty("parameters[reporting_category]")]
public string ReportingCategory { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Stripe.Reporting
{
using System.Collections.Generic;
using Newtonsoft.Json;

public class ReportRunCreateOptions : StripeBaseOptions
{
[JsonProperty("parameters")]
public ParametersOptions Parameters { get; set; }

[JsonProperty("report_type")]
public string ReportType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Stripe.Reporting
{
using Newtonsoft.Json;

public class ReportRunListOptions : StripeListOptions
{
[JsonProperty("created")]
public StripeDateFilter Created { get; set; }
}
}
74 changes: 74 additions & 0 deletions src/Stripe.net/Services/Reporting/ReportRuns/ReportRunService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace Stripe.Reporting
{
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class ReportRunService : StripeService
{
private static string classUrl = Urls.BaseUrl + "/reporting/report_runs";

public ReportRunService()
: base(null)
{
}

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

public virtual ReportRun Create(ReportRunCreateOptions createOptions, StripeRequestOptions requestOptions = null)
{
return Mapper<ReportRun>.MapFromJson(
Requestor.PostString(
this.ApplyAllParameters(createOptions, classUrl, false),
this.SetupRequestOptions(requestOptions)));
}

public virtual ReportRun Get(string reportRunId, StripeRequestOptions requestOptions = null)
{
return Mapper<ReportRun>.MapFromJson(
Requestor.GetString(
this.ApplyAllParameters(null, $"{classUrl}/{reportRunId}", false),
this.SetupRequestOptions(requestOptions)));
}

public virtual StripeList<ReportRun> List(ReportRunListOptions listOptions = null, StripeRequestOptions requestOptions = null)
{
return Mapper<StripeList<ReportRun>>.MapFromJson(
Requestor.GetString(
this.ApplyAllParameters(listOptions, classUrl, true),
this.SetupRequestOptions(requestOptions)));
}

public virtual async Task<ReportRun> CreateAsync(ReportRunCreateOptions createOptions, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return Mapper<ReportRun>.MapFromJson(
await Requestor.PostStringAsync(
this.ApplyAllParameters(createOptions, classUrl, false),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}

public virtual async Task<ReportRun> GetAsync(string reportRunId, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return Mapper<ReportRun>.MapFromJson(
await Requestor.GetStringAsync(
this.ApplyAllParameters(null, $"{classUrl}/{reportRunId}", false),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}

public virtual async Task<StripeList<ReportRun>> ListAsync(ReportRunListOptions listOptions = null, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return Mapper<StripeList<ReportRun>>.MapFromJson(
await Requestor.GetStringAsync(
this.ApplyAllParameters(listOptions, classUrl, true),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Stripe.Reporting
{
using Newtonsoft.Json;

public class ReportTypeListOptions : StripeListOptions
{
}
}
57 changes: 57 additions & 0 deletions src/Stripe.net/Services/Reporting/ReportTypes/ReportTypeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Stripe.Reporting
{
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class ReportTypeService : StripeService
{
private static string classUrl = Urls.BaseUrl + "/reporting/report_types";

public ReportTypeService()
: base(null)
{
}

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

public virtual ReportType Get(string reportTypeId, StripeRequestOptions requestOptions = null)
{
return Mapper<ReportType>.MapFromJson(
Requestor.GetString(
this.ApplyAllParameters(null, $"{classUrl}/{reportTypeId}", false),
this.SetupRequestOptions(requestOptions)));
}

public virtual StripeList<ReportType> List(ReportTypeListOptions listOptions = null, StripeRequestOptions requestOptions = null)
{
return Mapper<StripeList<ReportType>>.MapFromJson(
Requestor.GetString(
this.ApplyAllParameters(listOptions, classUrl, true),
this.SetupRequestOptions(requestOptions)));
}

public virtual async Task<ReportType> GetAsync(string reportTypeId, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return Mapper<ReportType>.MapFromJson(
await Requestor.GetStringAsync(
this.ApplyAllParameters(null, $"{classUrl}/{reportTypeId}", false),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}

public virtual async Task<StripeList<ReportType>> ListAsync(ReportTypeListOptions listOptions = null, StripeRequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return Mapper<StripeList<ReportType>>.MapFromJson(
await Requestor.GetStringAsync(
this.ApplyAllParameters(listOptions, classUrl, true),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}
}
}
25 changes: 25 additions & 0 deletions src/StripeTests/Entities/Reporting/ReportRunTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace StripeTests.Reporting
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Newtonsoft.Json;
using Stripe;
using Stripe.Reporting;
using Xunit;

public class ReportRunTest : BaseStripeTest
{
[Fact]
public void Deserialize()
{
string json = GetFixture("/v1/reporting/report_runs/frr_123");
var reportRun = Mapper<ReportRun>.MapFromJson(json);
Assert.NotNull(reportRun);
Assert.IsType<ReportRun>(reportRun);
Assert.NotNull(reportRun.Id);
Assert.Equal("reporting.report_run", reportRun.Object);
}
}
}
25 changes: 25 additions & 0 deletions src/StripeTests/Entities/Reporting/ReportTypeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace StripeTests.Reporting
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Newtonsoft.Json;
using Stripe;
using Stripe.Reporting;
using Xunit;

public class ReportTypeTest : BaseStripeTest
{
[Fact]
public void Deserialize()
{
string json = GetFixture("/v1/reporting/report_types/activity.summary.1");
var reportType = Mapper<ReportType>.MapFromJson(json);
Assert.NotNull(reportType);
Assert.IsType<ReportType>(reportType);
Assert.NotNull(reportType.Id);
Assert.Equal("reporting.report_type", reportType.Object);
}
}
}
Loading

0 comments on commit 82c414c

Please sign in to comment.