Mangopay / mangopay2-php-sdk

PHP SDK for MANGOPAY
https://packagist.org/packages/mangopay/php-sdk-v2
MIT License
123 stars 134 forks source link

Card Update endpoint gives empty string on some errors - resulting in SDK error Invalid argument supplied for foreach() #516

Closed BinaryKitten closed 3 years ago

BinaryKitten commented 3 years ago

If you try to update a card data that's already been processed (this is scenario we have presently) the api results in a 400 response code. The RestTool calls CheckResponseCode which then gets to the following

if (property_exists($response, 'errors')) {
    $error->Errors = $response->errors;
}

foreach ($error->Errors as $key => $val) {

the issue here is that in the case of 400/card already processed, the server responds with errors being an empty string and not an empty object/array. Taken from: https://docs.mangopay.com/endpoints/v2/cards#e179_update-a-card-registration and https://docs.mangopay.com/endpoints/v2.01/cards#e179_update-a-card-registration

HTTP/1.1 400 (Bad Request)
{
"Message": "the card registration has already been processed",
"Type": "cardregistration_already_process",
"Id": "ea97470c-0060-4366-95dc-037c2510612e#1628023220",
"Date": "1628023221",
"errors": ""
}

This means the code in the RestTool on line 379 errors as you cannot foreach over a string.

We started seeing this error July 29th 2021 around 9:51am UK BST - We've not changed or updated the code our side.. so was not expecting something to break. With the Error happening in the RestTool of the SDK, we are not getting what the error is from the API and as such cannot make amends to see if/what is going wrong.

BinaryKitten commented 3 years ago

i notice that the code in the master branch for RestTool has been updated to cast the element to array before iterating. Is there any chance that this update can be tagged for release as say 3.6.1 ?

fredericdelordm commented 3 years ago

Hello @BinaryKitten,

We have released a new version of the SDK. Tell me if it's solve your issue.

Have a nice day,