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

Modernize StripeConfiguration #1485

Merged
merged 1 commit into from
Jan 24, 2019
Merged

Conversation

ob-stripe
Copy link
Contributor

@ob-stripe ob-stripe commented Jan 23, 2019

r? @remi-stripe
cc @stripe/api-libraries

Modernize StripeConfiguration:

  • all configuration values are now represented by properties rather than GetFoo() / SetFoo() methods
  • default values are exposed as read-only properties
  • all values have XML doc comments
  • HttpTimeSpan is renamed to HttpTimeout, becomes non-nullable, and defaults to 80 seconds (like our other libraries)
  • setting the API key via ConfigurationManager.AppSettings now works when targeting .NET Standard 2.0
  • moved /v1 prefix out of the base URLs and into each service's path
  • got rid of the Urls internal class

Breaking changes:

  • StripeApiVersion is renamed to ApiVersion, and is now read-only

The existing Get/Set methods map to the new property as appropriate. Existing methods are annotated with Obsolete which will generate warnings when used, with a message indicating what to use instead.

@@ -50,10 +50,6 @@
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<DefineConstants>$(DefineConstants);NET45</DefineConstants>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out this wasn't needed. Preprocessor constants are automatically defined for the target framework: https://docs.microsoft.com/en-us/dotnet/standard/frameworks#how-to-specify-target-frameworks.

@ob-stripe ob-stripe mentioned this pull request Jan 23, 2019
52 tasks
Copy link
Contributor

@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.

Okay this all looks fine to me, but I have some comments (likely me misunderstanding some of it). Usual "I'm wary of reviewing such core changes, but not sure you have an alternative today)

@@ -35,7 +35,7 @@ You can configure the Stripe.net package to use your secret API key in one of tw
a) In your application initialization, set your API key (only once once during startup):

```csharp
StripeConfiguration.SetApiKey("[your api key here]");
StripeConfiguration.ApiKey = "[your api key here]";
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this remove SetApiKey entirely? Isn't this a breaking change? Or are we just making this cleaner but still supporting both (flagging now since it's the first thing in the review)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My intention was to avoid a breaking change by keeping the old methods around, but marking them as Obsolete to encourage users to upgrade to the new way of setting these values, and actually remove the methods in a future major version. This would make the upgrade a bit less painful for users.

I don't feel too strongly about it, if you'd rather we drop the old methods immediately that's fine by me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay I think that's fine and a nicer experience for sure

/// <remarks>
/// You can also set the API key using the <c>StripeApiKey</c> key in
/// <see cref="System.Configuration.ConfigurationManager.AppSettings"/>.
/// </remarks>
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel weird about preprocessor commands + comments. Isn't it better to document it globally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that we can't link to System.Configuration.ConfigurationManager.AppSettings with .NET Standard 1.2 because the class doesn't exist. I could just remove the link or the comment entirely, but it's kind of a shame.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah I see what you mean. Ugh. Sounds good then!

/// <see cref="HttpTimeout"/> property instead.
/// </summary>
// TODO: remove this property in a future major version
[Obsolete("Use StripeConfiguration.HttpTimeout instead.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

We're already merging in a major version. Why not just do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above.

}

// TODO: remove everything below this in a future major version
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, you're already planning version 23, why not do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above.

@@ -120,7 +117,7 @@ private static async Task<StripeResponse> ExecuteRequestAsync(HttpRequestMessage

internal static HttpRequestMessage GetRequestMessage(string url, HttpMethod method, RequestOptions requestOptions)
{
requestOptions.ApiKey = requestOptions.ApiKey ?? StripeConfiguration.GetApiKey();
requestOptions.ApiKey = requestOptions.ApiKey ?? StripeConfiguration.ApiKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay minor but need to flag: there's no thread safety and such, which I think is okay, but removing a getter prevents from ever adding this right? Though I guess it still has a getter/setter associated with it?

Copy link
Contributor Author

@ob-stripe ob-stripe Jan 24, 2019

Choose a reason for hiding this comment

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

I'm not sure I follow. The only thing that changed with regards to the global API key is that StripeConfiguration.GetApiKey() is now StripeConfiguration.ApiKey and StripeConfiguration.SetApiKey(newKey) is now Stripe.Configuration.ApiKey = newKey.

Changing the global API key was never thread-safe. Users that want to use different API keys in a multi-threaded environment must set the API key per request via RequestOptions.

@ob-stripe
Copy link
Contributor Author

ptal @remi-stripe

@ob-stripe ob-stripe assigned remi-stripe and unassigned ob-stripe Jan 24, 2019
@@ -35,7 +35,7 @@ You can configure the Stripe.net package to use your secret API key in one of tw
a) In your application initialization, set your API key (only once once during startup):

```csharp
StripeConfiguration.SetApiKey("[your api key here]");
StripeConfiguration.ApiKey = "[your api key here]";
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay I think that's fine and a nicer experience for sure

/// <remarks>
/// You can also set the API key using the <c>StripeApiKey</c> key in
/// <see cref="System.Configuration.ConfigurationManager.AppSettings"/>.
/// </remarks>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah I see what you mean. Ugh. Sounds good then!

@ob-stripe ob-stripe assigned ob-stripe and unassigned remi-stripe Jan 24, 2019
@ob-stripe ob-stripe merged commit b90a4e9 into integration-v23 Jan 24, 2019
@ob-stripe ob-stripe deleted the ob-stripe-configuration branch January 24, 2019 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants