readdle / app-store-server-api

Pure PHP library that allows managing customer transactions using the App Store Server API and handling server-to-server notifications using the App Store Server Notifications V2
MIT License
53 stars 20 forks source link

Update HTTPRequest.php #6

Closed teanooki closed 11 months ago

teanooki commented 11 months ago

Status codes below 300 are valid. And status codes in the 300s are redirections or similar tasks for the client side. So, a exception for all status codes not equal to 200 is wrong.

The main problem here is that the "Send Consumtion Information" endpoint returns a 202 under normal circumstances:

https://developer.apple.com/documentation/appstoreserverapi/send_consumption_information#response-codes

pkotets commented 11 months ago

Hello,

Thank you for helping in improving this library!

I agree that the behaviour you mentioned is erroneous. The thing is that the endpoint you are referring to is the only one which returns not 200 in case of success and I just missed that :)

However, speaking of 3xx responses, despite they are valid from HTTP protocol point of view, they are still exceptional from the point of view of the library, as there is no scenario how the library has to react to such a response.

So I'd say as a temporary solution it's better to include 202 response code in the list, because any other response code will probably need additional program code as a reaction to them.

As a full-fledged solution I see some refactoring with introducing HttpRequest/HttpResponse classes which are passed to Response class so that the implementation of specific response can react to the HTTP response code.

teanooki commented 11 months ago

Thank you. :+1: Regarding the HttpRequest/HttpResponse: implementing the PSR interfaces would be awesome. But in this case it would be too much overhead and accepting the 202 status is just fine.