Skip to content

Commit

Permalink
Make base URLs in StripeClient readonly (#1640)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe authored May 31, 2019
1 parent 580c1a0 commit 2c4c404
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
29 changes: 22 additions & 7 deletions src/Stripe.net/Infrastructure/Public/StripeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ public class StripeClient : IStripeClient
/// The <see cref="IHttpClient"/> client to use. If <c>null</c>, an HTTP client will be
/// created with default parameters.
/// </param>
/// <param name="apiBase">
/// The base URL for Stripe's API. Defaults to <see cref="DefaultApiBase"/>
/// </param>
/// <param name="connectBase">
/// The base URL for Stripe's OAuth API. Defaults to <see cref="DefaultConnectBase"/>
/// </param>
/// <param name="filesBase">
/// The base URL for Stripe's Files API. Defaults to <see cref="DefaultFilesBase"/>
/// </param>
/// <exception cref="ArgumentNullException">if <c>apiKey</c> is <c>null</c></exception>
/// <exception cref="ArgumentException">
/// if <c>apiKey</c> is empty or contains whitespace
/// </exception>
public StripeClient(
string apiKey,
string clientId = null,
IHttpClient httpClient = null)
IHttpClient httpClient = null,
string apiBase = null,
string connectBase = null,
string filesBase = null)
{
if (apiKey == null)
{
Expand All @@ -47,6 +59,9 @@ public StripeClient(
this.ApiKey = apiKey;
this.ClientId = clientId;
this.HttpClient = httpClient ?? BuildDefaultHttpClient();
this.ApiBase = apiBase ?? DefaultApiBase;
this.ConnectBase = connectBase ?? DefaultConnectBase;
this.FilesBase = filesBase ?? DefaultFilesBase;
}

/// <summary>Default base URL for Stripe's API.</summary>
Expand All @@ -58,9 +73,9 @@ public StripeClient(
/// <summary>Default base URL for Stripe's Files API.</summary>
public static string DefaultFilesBase => "https://files.stripe.com";

/// <summary>Gets or sets the base URL for Stripe's API.</summary>
/// <summary>Gets the base URL for Stripe's API.</summary>
/// <value>The base URL for Stripe's API.</value>
public string ApiBase { get; set; } = DefaultApiBase;
public string ApiBase { get; }

/// <summary>Gets the API key used by the client to send requests.</summary>
/// <value>The API key used by the client to send requests.</value>
Expand All @@ -70,13 +85,13 @@ public StripeClient(
/// <value>The client ID used by the client in OAuth requests.</value>
public string ClientId { get; }

/// <summary>Gets or sets the base URL for Stripe's OAuth API.</summary>
/// <summary>Gets the base URL for Stripe's OAuth API.</summary>
/// <value>The base URL for Stripe's OAuth API.</value>
public string ConnectBase { get; set; } = DefaultConnectBase;
public string ConnectBase { get; }

/// <summary>Gets or sets the base URL for Stripe's Files API.</summary>
/// <summary>Gets the base URL for Stripe's Files API.</summary>
/// <value>The base URL for Stripe's Files API.</value>
public string FilesBase { get; set; } = DefaultFilesBase;
public string FilesBase { get; }

/// <summary>Gets the <see cref="IHttpClient"/> used to send HTTP requests.</summary>
/// <value>The <see cref="IHttpClient"/> used to send HTTP requests.</value>
Expand Down
7 changes: 3 additions & 4 deletions src/StripeTests/Infrastructure/Public/StripeRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ public class StripeRequestTest : BaseStripeTest

public StripeRequestTest()
{
this.stripeClient = new StripeClient("sk_test_123")
{
ApiBase = "https://client.example.com"
};
this.stripeClient = new StripeClient(
"sk_test_123",
apiBase: "https://client.example.com");
}

[Fact]
Expand Down
8 changes: 3 additions & 5 deletions src/StripeTests/StripeMockFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ public StripeClient BuildStripeClient(IHttpClient httpClient = null)
return new StripeClient(
"sk_test_123",
"ca_123",
httpClient: httpClient)
{
ApiBase = $"http://localhost:{this.port}",
FilesBase = $"http://localhost:{this.port}",
};
httpClient: httpClient,
apiBase: $"http://localhost:{this.port}",
filesBase: $"http://localhost:{this.port}");
}

/// <summary>
Expand Down

0 comments on commit 2c4c404

Please sign in to comment.