stripe / stripe-php

PHP library for the Stripe API.
https://stripe.com
MIT License
3.75k stars 848 forks source link

Fixes requests with no params and responses with no response #1752

Closed jar-stripe closed 1 month ago

jar-stripe commented 2 months ago

Why?

When testing the meter event stream examples, I saw error code 400 return from creating a MeterEventSession (using MeterEventSessionService.create()) the issue was that we were sending an encoded empty array [] instead of no body. The fix here is to allow null params through, and then test for null where we attempt to iterate thru them.

After fixing this, I saw that creating a MeterEventStream (using MeterEventSessionService) was raising an exception when trying to setLastResponse. The issue here is that the response from the server is empty, which json_decode decodes as an empty array, which is then interpreted as a list in convertToStripeObject. The fix here (I think) is to not interpret an empty array as a list.

What?

jar-stripe commented 2 months ago

The indented comments were automatic and I couldn't figure out how to get VS code to knock it off.

helenye-stripe commented 2 months ago

added a test for empty array to convertToStripeObject (in Util) so that this case falls thru the is_array branch and returns an empty StripeObject object

is the test supposed to be in this PR?

jar-stripe commented 1 month ago

added a test for empty array to convertToStripeObject (in Util) so that this case falls thru the is_array branch and returns an empty StripeObject object

is the test supposed to be in this PR?

sorry, poor choice of words. by test i meant a conditional test, as part of an if statement.

jar-stripe commented 1 month ago

The fixes here were implemented better in https://github.com/stripe/stripe-php/pull/1755 and https://github.com/stripe/stripe-php/pull/1754