From 8d46ae62d3af8ecc290f3c0ad30a1f68308b1735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Gon=C3=A7alves?= Date: Tue, 12 Nov 2019 15:49:38 -0300 Subject: [PATCH 1/2] Added OAuth functionalities - Added Mercado Pago OAuth functionalities - Fixed proccess_causes method --- src/MercadoPago/Entities/OAuth.php | 82 ++++++++++++++++++++ src/MercadoPago/Generic/RecuperableError.php | 14 ++-- 2 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 src/MercadoPago/Entities/OAuth.php diff --git a/src/MercadoPago/Entities/OAuth.php b/src/MercadoPago/Entities/OAuth.php new file mode 100644 index 00000000..0d5a314b --- /dev/null +++ b/src/MercadoPago/Entities/OAuth.php @@ -0,0 +1,82 @@ +client_secret = SDK::getAccessToken(); + $this->grant_type = 'authorization_code'; + $this->code = $authorization_code; + $this->redirect_uri = $redirect_uri; + + return $this->save(); + } + + public function refreshOAuthCredentials($refresh_token){ + $this->client_secret = SDK::getAccessToken(); + $this->grant_type = 'refresh_token'; + $this->refresh_token = $refresh_token; + + return $this->save(); + } +} diff --git a/src/MercadoPago/Generic/RecuperableError.php b/src/MercadoPago/Generic/RecuperableError.php index 530b8688..6d6662b6 100644 --- a/src/MercadoPago/Generic/RecuperableError.php +++ b/src/MercadoPago/Generic/RecuperableError.php @@ -24,11 +24,15 @@ public function add_cause($code, $description) { } public function proccess_causes($causes){ - foreach ($causes as $cause){ - if(is_array($cause) && (!isset($cause['code']) && !isset($cause['description']))){ - $this->proccess_causes($cause); - }else{ - $this->add_cause($cause['code'], $cause['description']); + if(isset($causes['code']) && isset($causes['description'])){ + $this->add_cause($causes['code'], $causes['description']); + }else{ + foreach ($causes as $cause){ + if(is_array($cause) && (!isset($cause['code']) && !isset($cause['description']))){ + $this->proccess_causes($cause); + }else{ + $this->add_cause($cause['code'], $cause['description']); + } } } } From d2406c3fed48954d6e9cd9358d9d9948faf53213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Gon=C3=A7alves?= Date: Thu, 14 Nov 2019 14:53:36 -0300 Subject: [PATCH 2/2] Fix issue converting numeric attribute to json Fix the issue while converting a numeric attribute to json element. The issue was identified while trying to send a tax value as 0 --- src/MercadoPago/Manager.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/MercadoPago/Manager.php b/src/MercadoPago/Manager.php index 1ec5fe19..c8081d09 100755 --- a/src/MercadoPago/Manager.php +++ b/src/MercadoPago/Manager.php @@ -299,7 +299,9 @@ public function setQueryParams($entity, $urlParams = []) protected function _attributesToJson($entity, &$result) { if (is_array($entity)) { - $attributes = array_filter($entity); + $attributes = array_filter($entity, function($entity) { + return ($entity !== null && $entity !== false && $entity !== ''); + }); } else { $attributes = $entity->toArray(); } @@ -308,7 +310,7 @@ protected function _attributesToJson($entity, &$result) if ($value instanceof Entity || is_array($value)) { $this->_attributesToJson($value, $result[$key]); } else { - if ($value != null || is_bool($value)){ + if ($value != null || is_bool($value) || is_numeric($value)){ $result[$key] = $value; } }