Skip to content

Commit

Permalink
Merge pull request #1355 from stripe/ob-fix-1351
Browse files Browse the repository at this point in the history
Fix handling of Expand* properties in list requests
  • Loading branch information
ob-stripe authored Oct 25, 2018
2 parents be6cf75 + 62d1ec5 commit 7fa2805
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/Stripe.net/Services/Account/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public virtual Account Get(string accountId, RequestOptions requestOptions = nul

public virtual Account GetSelf(RequestOptions requestOptions = null)
{
return this.GetRequest<Account>($"{Urls.BaseUrl}/account", null, requestOptions);
return this.GetRequest<Account>($"{Urls.BaseUrl}/account", null, requestOptions, false);
}

public virtual Task<Account> GetSelfAsync(RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<Account>($"{Urls.BaseUrl}/account", null, requestOptions, cancellationToken);
return this.GetRequestAsync<Account>($"{Urls.BaseUrl}/account", null, requestOptions, false, cancellationToken);
}

public virtual StripeList<Account> List(AccountListOptions options = null, RequestOptions requestOptions = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Stripe.net/Services/Balance/BalanceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public BalanceService(string apiKey)

public virtual Balance Get(RequestOptions requestOptions = null)
{
return this.GetRequest<Balance>(this.ClassUrl(), null, requestOptions);
return this.GetRequest<Balance>(this.ClassUrl(), null, requestOptions, false);
}

public virtual Task<Balance> GetAsync(RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<Balance>(this.ClassUrl(), null, requestOptions, cancellationToken);
return this.GetRequestAsync<Balance>(this.ClassUrl(), null, requestOptions, false, cancellationToken);
}
}
}
2 changes: 1 addition & 1 deletion src/Stripe.net/Services/Customers/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Stripe.net/Services/Invoices/InvoiceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ public virtual StripeList<Invoice> List(InvoiceListOptions options = null, Reque

public virtual StripeList<InvoiceLineItem> ListLineItems(string invoiceId, InvoiceListLineItemsOptions options = null, RequestOptions requestOptions = null)
{
return this.GetRequest<StripeList<InvoiceLineItem>>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions);
return this.GetRequest<StripeList<InvoiceLineItem>>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, true);
}

public virtual Task<StripeList<InvoiceLineItem>> ListLineItemsAsync(string invoiceId, InvoiceListLineItemsOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<StripeList<InvoiceLineItem>>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, cancellationToken);
return this.GetRequestAsync<StripeList<InvoiceLineItem>>($"{this.InstanceUrl(invoiceId)}/lines", options, requestOptions, true, cancellationToken);
}

public virtual StripeList<InvoiceLineItem> ListUpcomingLineItems(UpcomingInvoiceOptions options = null, RequestOptions requestOptions = null)
{
return this.GetRequest<StripeList<InvoiceLineItem>>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions);
return this.GetRequest<StripeList<InvoiceLineItem>>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, true);
}

public virtual Task<StripeList<InvoiceLineItem>> ListUpcomingLineItemsAsync(UpcomingInvoiceOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<StripeList<InvoiceLineItem>>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, cancellationToken);
return this.GetRequestAsync<StripeList<InvoiceLineItem>>($"{this.InstanceUrl("upcoming")}/lines", options, requestOptions, true, cancellationToken);
}

public virtual Invoice Pay(string invoiceId, InvoicePayOptions options, RequestOptions requestOptions = null)
Expand All @@ -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<Invoice>($"{this.InstanceUrl("upcoming")}", options, requestOptions);
return this.GetRequest<Invoice>($"{this.InstanceUrl("upcoming")}", options, requestOptions, false);
}

public virtual Task<Invoice> UpcomingAsync(UpcomingInvoiceOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<Invoice>($"{this.InstanceUrl("upcoming")}", options, requestOptions, cancellationToken);
return this.GetRequestAsync<Invoice>($"{this.InstanceUrl("upcoming")}", options, requestOptions, false, cancellationToken);
}

public virtual Invoice Update(string invoiceId, InvoiceUpdateOptions options, RequestOptions requestOptions = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Stripe.net/Services/Issuing/Cards/CardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public virtual Card Create(CardCreateOptions options, RequestOptions requestOpti

public virtual CardDetails Details(string cardId, RequestOptions requestOptions = null)
{
return this.GetRequest<CardDetails>($"{this.InstanceUrl(cardId)}/details", null, requestOptions);
return this.GetRequest<CardDetails>($"{this.InstanceUrl(cardId)}/details", null, requestOptions, false);
}

public virtual Task<CardDetails> DetailsAsync(string cardId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<CardDetails>($"{this.InstanceUrl(cardId)}/details", null, requestOptions, cancellationToken);
return this.GetRequestAsync<CardDetails>($"{this.InstanceUrl(cardId)}/details", null, requestOptions, false, cancellationToken);
}

public virtual Card Get(string cardId, RequestOptions requestOptions = null)
Expand Down
16 changes: 8 additions & 8 deletions src/Stripe.net/Services/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ protected Task<EntityReturned> DeleteEntityAsync(string id, BaseOptions options,

protected EntityReturned GetEntity(string id, BaseOptions options, RequestOptions requestOptions)
{
return this.GetRequest<EntityReturned>(this.InstanceUrl(id), options, requestOptions);
return this.GetRequest<EntityReturned>(this.InstanceUrl(id), options, requestOptions, false);
}

protected Task<EntityReturned> GetEntityAsync(string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
{
return this.GetRequestAsync<EntityReturned>(this.InstanceUrl(id), options, requestOptions, cancellationToken);
return this.GetRequestAsync<EntityReturned>(this.InstanceUrl(id), options, requestOptions, false, cancellationToken);
}

protected StripeList<EntityReturned> ListEntities(ListOptions options, RequestOptions requestOptions)
{
return this.GetRequest<StripeList<EntityReturned>>(this.ClassUrl(), options, requestOptions);
return this.GetRequest<StripeList<EntityReturned>>(this.ClassUrl(), options, requestOptions, true);
}

protected Task<StripeList<EntityReturned>> ListEntitiesAsync(ListOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
{
return this.GetRequestAsync<StripeList<EntityReturned>>(this.ClassUrl(), options, requestOptions, cancellationToken);
return this.GetRequestAsync<StripeList<EntityReturned>>(this.ClassUrl(), options, requestOptions, true, cancellationToken);
}

protected EntityReturned UpdateEntity(string id, BaseOptions options, RequestOptions requestOptions)
Expand Down Expand Up @@ -90,19 +90,19 @@ await Requestor.DeleteAsync(
cancellationToken).ConfigureAwait(false));
}

protected T GetRequest<T>(string url, BaseOptions options, RequestOptions requestOptions)
protected T GetRequest<T>(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod)
{
return Mapper<T>.MapFromJson(
Requestor.GetString(
this.ApplyAllParameters(options, url),
this.ApplyAllParameters(options, url, isListMethod),
this.SetupRequestOptions(requestOptions)));
}

protected async Task<T> GetRequestAsync<T>(string url, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
protected async Task<T> GetRequestAsync<T>(string url, BaseOptions options, RequestOptions requestOptions, bool isListMethod, CancellationToken cancellationToken)
{
return Mapper<T>.MapFromJson(
await Requestor.GetStringAsync(
this.ApplyAllParameters(options, url),
this.ApplyAllParameters(options, url, isListMethod),
this.SetupRequestOptions(requestOptions),
cancellationToken).ConfigureAwait(false));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Stripe.net/Services/ServiceNested.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ protected Task<EntityReturned> DeleteNestedEntityAsync(string parentId, string i

protected EntityReturned GetNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions)
{
return this.GetRequest<EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions);
return this.GetRequest<EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, false);
}

protected Task<EntityReturned> GetNestedEntityAsync(string parentId, string id, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
{
return this.GetRequestAsync<EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, cancellationToken);
return this.GetRequestAsync<EntityReturned>(this.InstanceUrl(parentId, id), options, requestOptions, false, cancellationToken);
}

protected StripeList<EntityReturned> ListNestedEntities(string parentId, BaseOptions options, RequestOptions requestOptions)
{
return this.GetRequest<StripeList<EntityReturned>>(this.ClassUrl(parentId), options, requestOptions);
return this.GetRequest<StripeList<EntityReturned>>(this.ClassUrl(parentId), options, requestOptions, true);
}

protected Task<StripeList<EntityReturned>> ListNestedEntitiesAsync(string parentId, BaseOptions options, RequestOptions requestOptions, CancellationToken cancellationToken)
{
return this.GetRequestAsync<StripeList<EntityReturned>>(this.ClassUrl(parentId), options, requestOptions, cancellationToken);
return this.GetRequestAsync<StripeList<EntityReturned>>(this.ClassUrl(parentId), options, requestOptions, true, cancellationToken);
}

protected EntityReturned UpdateNestedEntity(string parentId, string id, BaseOptions options, RequestOptions requestOptions)
Expand Down
4 changes: 2 additions & 2 deletions src/Stripe.net/Services/Sources/SourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public virtual Source Get(string sourceId, RequestOptions requestOptions = null)

public virtual StripeList<Source> List(string customerId, SourceListOptions options = null, RequestOptions requestOptions = null)
{
return this.GetRequest<StripeList<Source>>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions);
return this.GetRequest<StripeList<Source>>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, true);
}

public virtual Task<StripeList<Source>> ListAsync(string customerId, SourceListOptions options = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.GetRequestAsync<StripeList<Source>>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, cancellationToken);
return this.GetRequestAsync<StripeList<Source>>($"{Urls.BaseUrl}/customers/{customerId}/sources", options, requestOptions, true, cancellationToken);
}

public virtual Source Update(string sourceId, SourceUpdateOptions options, RequestOptions requestOptions = null)
Expand Down
2 changes: 2 additions & 0 deletions src/StripeTests/Services/Customers/CustomerServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 7fa2805

Please sign in to comment.