Open decima opened 5 years ago
Hi @decima, thanks for the suggestion.
I think this is a desirable change, but it would require making some significant changes to the HTTP client and interface to be compliant (there are a few things required by the spec that we're not storing right now, like the protocol version or the "reason phrase").
I'll tag this as future
for now and we'll try to do this in a future major version.
Hello, any thoughts on this feature?
Hello in the same context, during a discussion on the Symfony Devs Slack some devs ask about the ability to use a PSR-18 HTTP Client when using stripe/stripe-php
.
Here is what I was able to create: (requires PHP8) https://gist.github.com/Prometee/3bc6ca1a8b16d593ceb24da66fa6142f To use this new client you will have to simply replace the current CurlClient like this (Exemple using Guzzle7 HTTP Client):
use App\Stripe\HttpClient\PsrHttpClient;
use GuzzleHttp\Psr7\HttpFactory;
use Http\Adapter\Guzzle7\Client;
use Stripe\ApiRequestor;
$httpFactory = new HttpFactory();
$psrHttpClient = new PsrHttpClient(
new Client(),
$httpFactory,
$httpFactory
);
ApiRequestor::setHttpClient($psrHttpClient);
ApiRequestor::setStreamingHttpClient($psrHttpClient);
This would be an awesome feature to easily be able to drop in a Guzzle client with some middleware for logging/debugging. Extremely useful if you are trying to monitor all outbound calls from your app to identify performance issues, n+1 issues, or badly written requests/unexpected responses. Yes Stripe give us developers a portal to view this information in but it is much better to have it all in one place.
And thank you @Prometee, this is exactly what I was looking for!
I'm here because this morning I got a RateLimitException
and I expected to mitigate it using my custom Guzzle client I have which has a middleware with retry capabilities only to find out that this component is NOT PSR-18 compliant. That's a bummer for sure.
Yeah, I'd like to do it so I can inject some middleware to record requests and report on errors a bit better.
You can specify retries with the native StripeClient
. I haven't tried to see if it works in the case of a RateLimitException
though.
You're right @ZacharyDuBois
There is a setMaxNetworkRetries()
and by default the value is 0
so it doesn't retry. When it does, it observes exponential backoff, which is great. So yeah, it is supported built in and it seems alright (in fact it seems better than what I was going to do). Thanks!
Sorry for my off-topic.
I'd love to see this happen. A PSR-7 based client would make it so easy to log outgoing requests and find errors. Any update from Stripe?
I think the
Stripe\ApiResponse
should be psr7-compliant for easier integration in frameworks that handle psr7 responses, like Laravel, Symfony and others.What do you think?