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

ApiResponse psr-7 compliant #699

Open
decima opened this issue Aug 20, 2019 · 8 comments
Open

ApiResponse psr-7 compliant #699

decima opened this issue Aug 20, 2019 · 8 comments
Labels

Comments

@decima
Copy link

decima commented Aug 20, 2019

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?

@ob-stripe
Copy link
Contributor

ob-stripe commented Aug 20, 2019

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.

@LucasHantz
Copy link

Hello, any thoughts on this feature?

@Prometee
Copy link

Prometee commented Apr 18, 2023

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);

@ZacharyDuBois
Copy link

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!

@fredericgboutin-yapla
Copy link

fredericgboutin-yapla commented Apr 8, 2024

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.

@ZacharyDuBois
Copy link

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.

@fredericgboutin-yapla
Copy link

fredericgboutin-yapla commented Apr 8, 2024

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.

@ZacharyDuBois
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants