chargebee / chargebee-dotnet

.NET library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=dotnet
MIT License
20 stars 24 forks source link

Change the ApiConfig.ApiBaseUrl for testing #38

Closed jezzsantos closed 5 months ago

jezzsantos commented 3 years ago

We want to redirect this client library to use our own Stub (that simulates chargebee.com) when we are running locally (ie manual testing), so that we are not hitting chargebee.com.

Most other client libraries (eg Stripe) allow use to re-define the BaseUrl that their client uses, so that we can achieve this. However, this library does not allow us to do that.

Examining this:

    public string ApiBaseUrl => string.Format("{0}://{1}.{2}/api/{3}", (object) ApiConfig.Proto, (object) this.SiteName, (object) ApiConfig.DomainSuffix, (object) ApiConfig.API_VERSION);

https://github.com/chargebee/chargebee-dotnet/blob/afd9f77e9e2cbb819b7e0ef529b71e6eb65341e2/ChargeBee/Api/ApiConfig.cs#L20

It appears that we can change the ApiConfig.Site and the ApiConfig.DomainSuffix but these are still concatenated together with a '.', and the /api part and version are enforced, but what we really need to do is set the ApiBaseUrl to something like: https://localhost:5656/chargebee (where 5656 is the port of our stubservices).

Is it possible to change ApiConfig in some way to allow us to set: ApiConfig.ApiBaseUrl = https://localhost:5656/chargebee?

benjiro commented 11 months ago

This is still an issue, we need a way to overrride the ApiBaseUrl so we can use a tool like WireMock to stub out the responses when writing unit tests.

cb-alish commented 6 months ago

Hi @jezzsantos, we have included this in version v3.12.1 please upgrade our package to >=v3.12.1. After that You will be able to set base URL in the following way, ApiConfig.SetBaseUrl("https://test-url.cargebee.com/api/v2"); Please let us know if this is not working for you.

cb-sriramthiagarajan commented 5 months ago

Hi @jezzsantos — can you confirm if this is working for you in v3.12.1 or later?

cb-sriramthiagarajan commented 5 months ago

Hi @jezzsantos, I'm closing this issue for now. Please open a new one if you're still facing this issue. Thanks.

jezzsantos commented 5 months ago

Sorry @cb-sriramthiagarajan, thanks you heaps for putting this in the product. I've been delayed implementing this for some weeks now. Hope to get there in the coming month, to verify.

cb-sriramthiagarajan commented 5 months ago

No worries @jezzsantos. Let us know how it goes 🙌