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

Ignore null values in params #526

Merged
merged 1 commit into from
Sep 25, 2018
Merged

Ignore null values in params #526

merged 1 commit into from
Sep 25, 2018

Conversation

ob-stripe
Copy link
Contributor

r? @remi-stripe
cc @stripe/api-libraries @EatonZ

This fixes a regression I caused in #517 that caused null values in parameters to be encoded as empty strings and sent in requests.

stripe-ruby handles this via the objects_to_ids helper method, whose main purpose is to replace instances of Stripe resources with their IDs, but that also clears null values. Since the parameter encoding logic in stripe-php is already very similar to stripe-ruby's, I simply ported the method.

Fixes #525.

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comments but LGTM

public static function objectsToIds($h)
{
if ($h instanceof \Stripe\ApiResource) {
return $h->id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there will be some cases where some resources will not have an id and break this logic and we will regret this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I considered that. This would only happen if a user passed a resource without an ID inside a parameter hash though. We could check if the resource has an id property and output an error message if not, but I don't think it's worth the hassle.

(stripe-ruby has the same issue fwiw)

'customer' => Util\Util::convertToStripeObject([
'id' => 'cus_123',
'object' => 'customer',
], null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation on this kind of threw me off

@ob-stripe
Copy link
Contributor Author

Released as 6.19.1.

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

Successfully merging this pull request may close these issues.

Null array value regression
3 participants