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?
changes ApiRequestorAdapter to set the RequestOptions.BaseUrl if the baseAddress argument is anything other than API
change sLiveApiRequestorMakeStripeRequest to use the BaseUrl to override baseAddress, if BaseUrl is specified
adds unit tests for ApiRequestorAdapter RequestAsync with different base addresses
adds unit tests for OAuthTokenService Create and CreateAsync using the older-style instantiation pattern
Changelog
fixes bug where OAuthTokenService created without an explicit StripeClient accesses the wrong base url
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. TheApiRequestorAdapter
class is used to support older-style SDK usage patterns, e.g.and also to support any custom implementations of
IStripeClient
. When a service is created directly like this, Stripe.net wraps theStripeConfiguration.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 inIStripeClient
; this PR implements a backwards compatible fix by utilizing theRequestOption.BaseUrl
property.What?
ApiRequestorAdapter
to set theRequestOptions.BaseUrl
if thebaseAddress
argument is anything other than APILiveApiRequestor
MakeStripeRequest
to use theBaseUrl
to overridebaseAddress
, if BaseUrl is specifiedChangelog