diff --git a/README.md b/README.md index fc363995..0318d8c6 100755 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ First time using Mercado Pago? Create your [Mercado Pago account](https://www.me 1. Download [Composer](https://getcomposer.org/doc/00-intro.md) if not already installed 2. On your project directory run on the command line -`composer require "mercadopago/dx-php:2.6.1"` for PHP7 or `composer require "mercadopago/dx-php:1.12.5"` for PHP5.6. +`composer require "mercadopago/dx-php:2.6.2"` for PHP7 or `composer require "mercadopago/dx-php:1.12.5"` for PHP5.6. 3. Copy the access_token in the [credentials](https://www.mercadopago.com/mlb/account/credentials) section of the page and replace YOUR_ACCESS_TOKEN with it. diff --git a/composer.json b/composer.json index b8323d2f..002ab69c 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "homepage": "https://github.com/mercadopago/sdk-php", "license": "MIT", - "version": "2.6.1", + "version": "2.6.2", "config": { "platform": { "php": "7.1" diff --git a/src/MercadoPago/Manager.php b/src/MercadoPago/Manager.php index c09b391a..e0a741b2 100755 --- a/src/MercadoPago/Manager.php +++ b/src/MercadoPago/Manager.php @@ -84,7 +84,7 @@ public function execute($entity, $method = 'get', $options = []) $this->_setDefaultHeaders($configuration->query); $this->_setCustomHeaders($entity, $configuration->query); - //$this->_setIdempotencyHeader($configuration->query, $configuration, $method); + $this->_setIdempotencyHeader($configuration->query, $method); $this->setQueryParams($entity); return $this->_client->{$method}($configuration->url, $configuration->query); @@ -409,17 +409,12 @@ protected function _setDefaultHeaders(&$query) * @param $configuration * @param string $method */ - protected function _setIdempotencyHeader(&$query, $configuration, $method) + protected function _setIdempotencyHeader(&$query, $method) { - if (!isset($configuration->methods[$method])) { - return; - } - $fields = ''; - if ($configuration->methods[$method]['idempotency']) { - $fields = $this->_getIdempotencyAttributes($configuration->attributes); - } - if ($fields != '') { - $query['headers']['x-idempotency-key'] = hash(self::$CIPHER, $fields); + if ($method != 'get' && $method != 'delete') { + if (array_key_exists('headers', array_change_key_case($query)) && !array_key_exists('x-idempotency-key', array_change_key_case($query['headers']))){ + $query['headers']['x-idempotency-key'] = $this->_generateUUID(); + } } } /** @@ -427,14 +422,30 @@ protected function _setIdempotencyHeader(&$query, $configuration, $method) * * @return string */ - protected function _getIdempotencyAttributes($attributes) + protected function _generateUUID() { - $result = []; - foreach ($attributes as $key => $value) { - if ($value['idempotency']) { - $result[] = $key; - } - } - return implode('&', $result); + return sprintf( + '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + // 32 bits for "time_low" + mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + + // 16 bits for "time_mid" + mt_rand(0, 0xffff), + + // 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + mt_rand(0, 0x0fff) | 0x4000, + + // 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + mt_rand(0, 0x3fff) | 0x8000, + + // 48 bits for "node" + mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0xffff) + ); } } diff --git a/src/MercadoPago/Version.php b/src/MercadoPago/Version.php index 6267661f..e989f3ad 100755 --- a/src/MercadoPago/Version.php +++ b/src/MercadoPago/Version.php @@ -4,5 +4,5 @@ class Version { public static - $_VERSION = '2.6.1'; + $_VERSION = '2.6.2'; }