diff --git a/README.md b/README.md index 5e138de7..a3f5c458 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The SDK supports PHP 5.6 or major #### Using Composer 1. Download [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) if not already installed -2. Go to your project directory and run `composer require "mercadopago/dx-php:1.12.5"` on the command line. +2. Go to your project directory and run `composer require "mercadopago/dx-php:1.12.6"` on the command line. 3. This how your directory structure would look like. 4. Thats all, you have Mercado Pago SDK installed. diff --git a/composer.json b/composer.json index 0efda850..c3709eb7 100755 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "homepage": "https://github.com/mercadopago/sdk-php", "license": "MIT", - "version": "1.12.5", + "version": "1.12.6", "config": { "platform": { "php": "5.6" diff --git a/src/MercadoPago/Manager.php b/src/MercadoPago/Manager.php index f4146e15..1eb2a532 100755 --- a/src/MercadoPago/Manager.php +++ b/src/MercadoPago/Manager.php @@ -84,9 +84,9 @@ 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,32 +409,41 @@ 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(); + } } } /** - * @param $attributes - * - * @return string + * _generateUUID() */ - 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) + ); } } \ No newline at end of file diff --git a/src/MercadoPago/Version.php b/src/MercadoPago/Version.php index 08e28ce5..508acc46 100755 --- a/src/MercadoPago/Version.php +++ b/src/MercadoPago/Version.php @@ -4,5 +4,5 @@ class Version { public static - $_VERSION = '1.12.5'; + $_VERSION = '1.12.6'; }