From 62d1ec58223d024a47689193502cb36ac49cfacb Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Wed, 24 Oct 2018 16:30:44 +0200 Subject: [PATCH] Fix handling of Expand* properties in list requests --- .../Services/Account/AccountService.cs | 4 ++-- .../Services/Balance/BalanceService.cs | 4 ++-- .../Services/Customers/CustomerService.cs | 2 +- .../Services/Invoices/InvoiceService.cs | 12 ++++++------ .../Services/Issuing/Cards/CardService.cs | 4 ++-- src/Stripe.net/Services/Service.cs | 16 ++++++++-------- src/Stripe.net/Services/ServiceNested.cs | 8 ++++---- src/Stripe.net/Services/Sources/SourceService.cs | 4 ++-- .../Services/Customers/CustomerServiceTest.cs | 2 ++ 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Stripe.net/Services/Account/AccountService.cs b/src/Stripe.net/Services/Account/AccountService.cs index b54097ec64..5aae870c13 100644 --- a/src/Stripe.net/Services/Account/AccountService.cs +++ b/src/Stripe.net/Services/Account/AccountService.cs @@ -58,12 +58,12 @@ public virtual Account Get(string accountId, RequestOptions requestOptions = nul public virtual Account GetSelf(RequestOptions requestOptions = null) { - return this.GetRequest($"{Urls.BaseUrl}/account", null, requestOptions); + return this.GetRequest($"{Urls.BaseUrl}/account", null, requestOptions, false); } public virtual Task GetSelfAsync(RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync($"{Urls.BaseUrl}/account", null, requestOptions, cancellationToken); + return this.GetRequestAsync($"{Urls.BaseUrl}/account", null, requestOptions, false, cancellationToken); } public virtual StripeList List(AccountListOptions options = null, RequestOptions requestOptions = null) diff --git a/src/Stripe.net/Services/Balance/BalanceService.cs b/src/Stripe.net/Services/Balance/BalanceService.cs index 35b634e153..b3458b9dba 100644 --- a/src/Stripe.net/Services/Balance/BalanceService.cs +++ b/src/Stripe.net/Services/Balance/BalanceService.cs @@ -23,12 +23,12 @@ public BalanceService(string apiKey) public virtual Balance Get(RequestOptions requestOptions = null) { - return this.GetRequest(this.ClassUrl(), null, requestOptions); + return this.GetRequest(this.ClassUrl(), null, requestOptions, false); } public virtual Task GetAsync(RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync(this.ClassUrl(), null, requestOptions, cancellationToken); + return this.GetRequestAsync(this.ClassUrl(), null, requestOptions, false, cancellationToken); } } } diff --git a/src/Stripe.net/Services/Customers/CustomerService.cs b/src/Stripe.net/Services/Customers/CustomerService.cs index c8695fd865..87593d03ec 100644 --- a/src/Stripe.net/Services/Customers/CustomerService.cs +++ b/src/Stripe.net/Services/Customers/CustomerService.cs @@ -27,7 +27,7 @@ public CustomerService(string apiKey) public bool ExpandDefaultSource { get; set; } - public bool ExpandDefaultCustomerBankAccount { get; set; } + public bool ExpandDefaultCustomerBankAccount { get; set; } // TODO: remove in next major version public virtual Customer Create(CustomerCreateOptions options, RequestOptions requestOptions = null) { diff --git a/src/Stripe.net/Services/Invoices/InvoiceService.cs b/src/Stripe.net/Services/Invoices/InvoiceService.cs index e977815b23..c2d40de70c 100644 --- a/src/Stripe.net/Services/Invoices/InvoiceService.cs +++ b/src/Stripe.net/Services/Invoices/InvoiceService.cs @@ -61,22 +61,22 @@ public virtual StripeList List(InvoiceListOptions options = null, Reque public virtual StripeList ListLineItems(string invoiceId, InvoiceListLineItemsOptions options = null, RequestOptions requestOptions = null) { - return this.GetRequest>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions); + return this.GetRequest>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, true); } public virtual Task> ListLineItemsAsync(string invoiceId, InvoiceListLineItemsOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, cancellationToken); + return this.GetRequestAsync>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, true, cancellationToken); } public virtual StripeList ListUpcomingLineItems(UpcomingInvoiceOptions options = null, RequestOptions requestOptions = null) { - return this.GetRequest>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions); + return this.GetRequest>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, true); } public virtual Task> ListUpcomingLineItemsAsync(UpcomingInvoiceOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, cancellationToken); + return this.GetRequestAsync>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, true, cancellationToken); } public virtual Invoice Pay(string invoiceId, InvoicePayOptions options, RequestOptions requestOptions = null) @@ -91,12 +91,12 @@ public virtual Invoice Pay(string invoiceId, InvoicePayOptions options, RequestO public virtual Invoice Upcoming(UpcomingInvoiceOptions options, RequestOptions requestOptions = null) { - return this.GetRequest($"{this.InstanceUrl("upcoming")}", options, requestOptions); + return this.GetRequest($"{this.InstanceUrl("upcoming")}", options, requestOptions, false); } public virtual Task UpcomingAsync(UpcomingInvoiceOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync($"{this.InstanceUrl("upcoming")}", options, requestOptions, cancellationToken); + return this.GetRequestAsync($"{this.InstanceUrl("upcoming")}", options, requestOptions, false, cancellationToken); } public virtual Invoice Update(string invoiceId, InvoiceUpdateOptions options, RequestOptions requestOptions = null) diff --git a/src/Stripe.net/Services/Issuing/Cards/CardService.cs b/src/Stripe.net/Services/Issuing/Cards/CardService.cs index cf48d97e56..756c9079af 100644 --- a/src/Stripe.net/Services/Issuing/Cards/CardService.cs +++ b/src/Stripe.net/Services/Issuing/Cards/CardService.cs @@ -36,12 +36,12 @@ public virtual Card Create(CardCreateOptions options, RequestOptions requestOpti public virtual CardDetails Details(string cardId, RequestOptions requestOptions = null) { - return this.GetRequest($"{this.InstanceUrl(cardId)}/details", null, requestOptions); + return this.GetRequest($"{this.InstanceUrl(cardId)}/details", null, requestOptions, false); } public virtual Task DetailsAsync(string cardId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync($"{this.InstanceUrl(cardId)}/details", null, requestOptions, cancellationToken); + return this.GetRequestAsync($"{this.InstanceUrl(cardId)}/details", null, requestOptions, false, cancellationToken); } public virtual Card Get(string cardId, RequestOptions requestOptions = null) diff --git a/src/Stripe.net/Services/Service.cs b/src/Stripe.net/Services/Service.cs index 87222f4477..a0144b08e2 100644 --- a/src/Stripe.net/Services/Service.cs +++ b/src/Stripe.net/Services/Service.cs @@ -45,22 +45,22 @@ protected Task DeleteEntityAsync(string id, BaseOptions options, protected EntityReturned GetEntity(string id, BaseOptions options, RequestOptions requestOptions) { - return this.GetRequest(this.InstanceUrl(id), options, requestOptions); + return this.GetRequest(this.InstanceUrl(id), options, requestOptions, false); } protected Task GetEntityAsync(string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { - return this.GetRequestAsync(this.InstanceUrl(id), options, requestOptions, cancellationToken); + return this.GetRequestAsync(this.InstanceUrl(id), options, requestOptions, false, cancellationToken); } protected StripeList ListEntities(ListOptions options, RequestOptions requestOptions) { - return this.GetRequest>(this.ClassUrl(), options, requestOptions); + return this.GetRequest>(this.ClassUrl(), options, requestOptions, true); } protected Task> ListEntitiesAsync(ListOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { - return this.GetRequestAsync>(this.ClassUrl(), options, requestOptions, cancellationToken); + return this.GetRequestAsync>(this.ClassUrl(), options, requestOptions, true, cancellationToken); } protected EntityReturned UpdateEntity(string id, BaseOptions options, RequestOptions requestOptions) @@ -90,19 +90,19 @@ await Requestor.DeleteAsync( cancellationToken).ConfigureAwait(false)); } - protected T GetRequest(string url, BaseOptions options, RequestOptions requestOptions) + protected T GetRequest(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod) { return Mapper.MapFromJson( Requestor.GetString( - this.ApplyAllParameters(options, url), + this.ApplyAllParameters(options, url, isListMethod), this.SetupRequestOptions(requestOptions))); } - protected async Task GetRequestAsync(string url, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) + protected async Task GetRequestAsync(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod, CancellationToken cancellationToken) { return Mapper.MapFromJson( await Requestor.GetStringAsync( - this.ApplyAllParameters(options, url), + this.ApplyAllParameters(options, url, isListMethod), this.SetupRequestOptions(requestOptions), cancellationToken).ConfigureAwait(false)); } diff --git a/src/Stripe.net/Services/ServiceNested.cs b/src/Stripe.net/Services/ServiceNested.cs index 2c303fb53c..c37c3ffcb9 100644 --- a/src/Stripe.net/Services/ServiceNested.cs +++ b/src/Stripe.net/Services/ServiceNested.cs @@ -42,22 +42,22 @@ protected Task DeleteNestedEntityAsync(string parentId, string i protected EntityReturned GetNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions) { - return this.GetRequest(this.InstanceUrl(parentId, id), options, requestOptions); + return this.GetRequest(this.InstanceUrl(parentId, id), options, requestOptions, false); } protected Task GetNestedEntityAsync(string parentId, string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { - return this.GetRequestAsync(this.InstanceUrl(parentId, id), options, requestOptions, cancellationToken); + return this.GetRequestAsync(this.InstanceUrl(parentId, id), options, requestOptions, false, cancellationToken); } protected StripeList ListNestedEntities(string parentId, BaseOptions options, RequestOptions requestOptions) { - return this.GetRequest>(this.ClassUrl(parentId), options, requestOptions); + return this.GetRequest>(this.ClassUrl(parentId), options, requestOptions, true); } protected Task> ListNestedEntitiesAsync(string parentId, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken) { - return this.GetRequestAsync>(this.ClassUrl(parentId), options, requestOptions, cancellationToken); + return this.GetRequestAsync>(this.ClassUrl(parentId), options, requestOptions, true, cancellationToken); } protected EntityReturned UpdateNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions) diff --git a/src/Stripe.net/Services/Sources/SourceService.cs b/src/Stripe.net/Services/Sources/SourceService.cs index 0ef8b591ce..40ee4666a2 100644 --- a/src/Stripe.net/Services/Sources/SourceService.cs +++ b/src/Stripe.net/Services/Sources/SourceService.cs @@ -64,12 +64,12 @@ public virtual Source Get(string sourceId, RequestOptions requestOptions = null) public virtual StripeList List(string customerId, SourceListOptions options = null, RequestOptions requestOptions = null) { - return this.GetRequest>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions); + return this.GetRequest>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, true); } public virtual Task> ListAsync(string customerId, SourceListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken)) { - return this.GetRequestAsync>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, cancellationToken); + return this.GetRequestAsync>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, true, cancellationToken); } public virtual Source Update(string sourceId, SourceUpdateOptions options, RequestOptions requestOptions = null) diff --git a/src/StripeTests/Services/Customers/CustomerServiceTest.cs b/src/StripeTests/Services/Customers/CustomerServiceTest.cs index dad6c7c27c..3a6add872d 100644 --- a/src/StripeTests/Services/Customers/CustomerServiceTest.cs +++ b/src/StripeTests/Services/Customers/CustomerServiceTest.cs @@ -95,6 +95,7 @@ public async Task GetAsync() [Fact] public void List() { + this.service.ExpandDefaultSource = true; var customers = this.service.List(this.listOptions); this.AssertRequest(HttpMethod.Get, "/v1/customers"); Assert.NotNull(customers); @@ -106,6 +107,7 @@ public void List() [Fact] public async Task ListAsync() { + this.service.ExpandDefaultSource = true; var customers = await this.service.ListAsync(this.listOptions); this.AssertRequest(HttpMethod.Get, "/v1/customers"); Assert.NotNull(customers);