stripe / stripe-dotnet

Stripe.net is a sync/async .NET 4.6.1+ client, and a portable class library for stripe.com.
Apache License 2.0
1.37k stars 570 forks source link

Fixes ApiRequestorAdapter requests with BaseAddress other than Api #3007

Closed jar-stripe closed 1 month ago

jar-stripe commented 1 month ago

Why?

v46 of the SDK introduced a service accessors into StripeClient and a internal ApiRequestor classes for implementing the actual request issuing and response parsing logic used by the service classes. The ApiRequestorAdapter class is used to support older-style SDK usage patterns, e.g.

var svc = new CustomerService();
var customer = svc.Get("cust_...");

and also to support any custom implementations of IStripeClient. When a service is created directly like this, Stripe.net wraps the StripeConfiguration.StripeClient client object with this adapter to adapt the client to an ApiRequestor.

A user reported a problem with using the OAuthTokenService service with the pattern described above (https://github.com/stripe/stripe-dotnet/issues/3006) where the SDK was not using the correct API base address. The root issue appears to be that BaseAddress specified by the OAuthTokenService.Create method is getting replaced with the API base address when it passes through the ApiRequestorAdapter, because the IStripeClient RequestAsync method does not accept a BaseAddress argument. To fix this would introduce a breaking change in IStripeClient; this PR implements a backwards compatible fix by utilizing the RequestOption.BaseUrl property.

What?

Changelog