Change StripeClient initialization #903
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
r? @remi-stripe @richardm-stripe
cc @stripe/api-libraries
Change the
StripeClient
constructor to expose a simpler API.The new constructor takes a single argument, which can be a string (the API key) or an array with various configuration values.
In most cases, users will use the string form:
If needed, it's easy to pass "advanced" configuration settings:
The configuration array approach is used by other PHP libraries, including Guzzle, the most popular PHP HTTP client library (https://github.com/guzzle/guzzle/blob/1cdd69a0cd361ee8b6ba5584e45db80c0ea8b31c/src/Client.php#L51). The main downside is that there is no standard PHPDoc syntax for defining the shape of the array, but I think PHPStan and other static analyzer tools are working on something like this, and it's not that bad to just use freeform text to expose the various configuration keys and their expected types.