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

Move all services to BasicService #1305

Merged
merged 1 commit into from
Sep 29, 2018

Conversation

remi-stripe
Copy link
Contributor

This PR moves all existing services over to BasicService.

cc @stripe/api-libraries

@remi-stripe remi-stripe changed the base branch from master to integration-next-major-version September 29, 2018 01:15
Copy link
Contributor Author

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments that came to mind while porting everything.


public virtual StripeList<ApplicationFee> List(ApplicationFeeListOptions options = null, RequestOptions requestOptions = null)
{
return this.GetEntityList($"{Urls.BaseUrl}/application_fees", requestOptions, options);
}

public virtual ApplicationFee Refund(string applicationFeeId, int? refundAmount = null, RequestOptions requestOptions = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just remove the Refund method on this service and force devs to use the ApplicationFeeRefundService instead? If not, should we make this method take an Options class instead of an amount?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on removing the method.

@@ -21,87 +21,52 @@ public TopupService(string apiKey = null)

public virtual Topup Cancel(string topupId, RequestOptions requestOptions = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cancel has no parameters today but might in the future. What is the best approach? Adding it in the future would be a breaking change (unless we add an overloaded method).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I suppose we could make it a convention that all non-standard request methods (i.e. request methods not covered by the CRUD + list interfaces) must take an options argument, even if the options class is empty.

Requestor.PostString(
this.ApplyAllParameters(createOptions, classUrl, false),
this.SetupRequestOptions(requestOptions)));
return this.Post($"{classUrl}", requestOptions, options);
}

public virtual CardDetails Details(string cardId, RequestOptions requestOptions = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method still uses the old way since it returns CardDetails and not Card. What is the right approach? The current method is verbose and error prone IMO but not sure there's a better way

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now. I have some ideas for covering these cases using generic methods (but will be much simpler to experiment once this PR is merged).

}

public virtual async Task<Invoice> GetAsync(string invoiceId, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
public virtual StripeList<InvoiceLineItem> ListLineItems(string invoiceId, InvoiceListLineItemsOptions listOptions = null, RequestOptions requestOptions = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Issuing.Card: This returns a different class so we can't use the GetEntity approach. What is the right way to do this? Should it be in the InvoiceLineItemService (does not yet exist)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as is for now.

Requestor.PostString(
this.ApplyAllParameters(createOptions, $"{Urls.BaseUrl}/customers/{customerId}/bank_accounts"),
this.SetupRequestOptions(requestOptions)));
return this.Post($"{Urls.BaseUrl}/customers/{customerId}/bank_accounts", requestOptions, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we stop using /bank_accounts and move to /sources like we do with cards? I think this will require a default value for the options class but might be cleaner.
Issue is that stripe-mock will not return a bank account though not a big deal I guess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on using /sources.

@@ -4,7 +4,7 @@ namespace Stripe
using System.Threading.Tasks;
using Stripe.Infrastructure;

public class OAuthTokenService : StripeService,
public class OAuthTokenService : BasicService<OAuthToken>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class has no OAuthTokenServiceTest we should fix this as it makes it dangerous to make random changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the sentiment, but in practice we'd need local mocking to test this (stripe-mock doesn't support OAuth endpoints).

}

public virtual OAuthDeauthorize Deauthorize(string clientId, string stripeUserId, RequestOptions requestOptions = null)
{
var url = ParameterBuilder.ApplyParameterToUrl(Urls.OAuthDeauthorize, "client_id", clientId);
var url = ParameterBuilder.ApplyParameterToUrl($"{Urls.BaseConnectUrl}/oauth/deauthorize", "client_id", clientId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as Issuing.Card: returns a different object


public virtual Task<OAuthToken> CreateAsync(OAuthTokenCreateOptions options, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
{
return this.PostAsync($"{Urls.BaseConnectUrl}/oauth/token", requestOptions, cancellationToken, options);
}

public virtual OAuthDeauthorize Deauthorize(string clientId, string stripeUserId, RequestOptions requestOptions = null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a OAuthDeauthorizeOptions or something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but OAuth is definitely an odd case. I wouldn't sweat it if it doesn't abide completely by the library's conventions.

@@ -95,7 +95,7 @@ public virtual async Task<Source> DetachAsync(string customerId, string sourceId

public virtual async Task<StripeList<Source>> ListAsync(string customerId, SourceListOptions listOptions = null, RequestOptions requestOptions = null, CancellationToken cancellationToken = default(CancellationToken))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we don't simply use the GetEntityList and DeleteEntity on this service?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we couldn't use DeleteEntity before because it returned a StripeDeleted object, but detaching a source always returned a source.

Not sure about GetEntityList. We can likely use it as well.

@remi-stripe remi-stripe force-pushed the remi-move-all-services branch from d669ed7 to 4346480 Compare September 29, 2018 14:12
@remi-stripe
Copy link
Contributor Author

@ob-stripe Okay I did another round of fixes. There are 2 Services left that use Requestor.* directly: OAuthTokenService and FileService. My guess is that we can fix the first one and not the latter. Can you have a look?

@remi-stripe remi-stripe assigned ob-stripe and unassigned ob-stripe Sep 29, 2018
@ob-stripe
Copy link
Contributor

My guess is that we can fix the first one and not the latter. Can you have a look?

Yeah, that sounds correct. I updated OAuthTokenService to use the new generic methods.

Doing the same for FileService would require some more refactoring, but I don't think it's worth it for now since only file creation requests would benefit from it. Let's leave as is for now.

@ob-stripe ob-stripe changed the title [WIP] Move all services to BasicService Move all services to BasicService Sep 29, 2018
@ob-stripe ob-stripe mentioned this pull request Sep 29, 2018
32 tasks
@ob-stripe ob-stripe force-pushed the remi-move-all-services branch from 87027dc to d450f4c Compare September 29, 2018 15:16
@ob-stripe ob-stripe merged commit 542842c into integration-next-major-version Sep 29, 2018
@ob-stripe ob-stripe deleted the remi-move-all-services branch September 29, 2018 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants