Skip to content

Commit

Permalink
Merge pull request #305 from mercadopago/release/1.12.0
Browse files Browse the repository at this point in the history
Release 1.12.0
  • Loading branch information
delias-silva authored Jul 15, 2021
2 parents 0e53346 + 0963c3b commit f282d14
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.11.0"` on the command line.
2. Go to your project directory and run `composer require "mercadopago/dx-php:1.12.0"` on the command line.
3. This how your directory structure would look like.
4. Thats all, you have Mercado Pago SDK installed.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"homepage": "https://github.com/mercadopago/sdk-php",
"license": "MIT",
"version": "1.11.0",
"version": "1.12.0",
"config": {
"platform": {
"php": "5.6"
Expand Down
9 changes: 8 additions & 1 deletion src/MercadoPago/Entities/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ class Card extends Entity
protected $id;

/**
* @Attribute(required = true)
* token
* @Attribute()
* @var string
*/
protected $token;

/**
* @Attribute(required = true, serialize = false)
*/
protected $customer_id;
/**
Expand Down
1 change: 1 addition & 0 deletions src/MercadoPago/Entities/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @RestMethod(resource="/checkout/preferences", method="create")
* @RestMethod(resource="/checkout/preferences/:id", method="read")
* @RestMethod(resource="/checkout/preferences/search", method="search")
* @RestMethod(resource="/checkout/preferences/:id", method="update")
*/
class Preference extends Entity
Expand Down
24 changes: 14 additions & 10 deletions src/MercadoPago/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,12 @@ public static function search($filters = [], $options = [])

$response = self::$_manager->execute($entityToQuery, 'get');
if ($response['code'] == "200" || $response['code'] == "201") {
$results = $response['body']['results'];
foreach ($results as $result) {
$entity = new $class();
$entity->_fillFromArray($entity, $result);
$searchResult->append($entity);
}
$searchResult->setPaginateParams($response['body']['paging']);
$searchResult->_filters = $filters;
$searchResult->fetch($filters, $response['body']);
} elseif (intval($response['code']) >= 400 && intval($response['code']) < 500) {
$searchResult->process_error_body($response['body']);
throw new Exception ($response['body']['message']);
throw new Exception($response['body']['message']);
} else {
throw new Exception ("Internal API Error");
throw new Exception("Internal API Error");
}
return $searchResult;
}
Expand Down Expand Up @@ -458,6 +451,17 @@ protected function tryFormat($value, $type, $property)
}
throw new \Exception('Wrong type ' . gettype($value) . '. It should be ' . $type . ' for property ' . $property);
}

/**
* Fill entity from data with nested object creation
*
* @param $entity
* @param $data
*/
public function fillFromArray($entity, $data) {
$this->_fillFromArray($entity, $data);
}

/**
* Fill entity from data with nested object creation
*
Expand Down
49 changes: 37 additions & 12 deletions src/MercadoPago/Generic/SearchResultsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,37 @@ public function setPaginateParams($params){
}

public function next() {

$new_offset = $this->limit + $this->offset;
echo "\n new offset" . $new_offset ;
$this->_filters['offset'] = $new_offset;
$class = $this->_class;
$result = $class::search($this->_filters);

$this->_filters['offset'] = $new_offset;

$result = $this->_class::search($this->_filters);



echo "\nlimit" . $result->limit ;
echo "\nresult offset" . $result->offset ;

$this->limit = $result->limit;
$this->offset = $result->offset;
$this->total = $result->total;

$this->exchangeArray($result->getArrayCopy());
}

public function fetch($filters, $body) {
$this->_filters = $filters;

if ($body) {
$results = [];
if (array_key_exists("results", $body)) {
$results = $body["results"];
} else if (array_key_exists("elements", $body)) {
$results = $body["elements"];
}

foreach ($results as $result) {
$entity = new $this->_class();
$entity->fillFromArray($entity, $result);
$this->append($entity);
}

$this->fetchPaging($filters, $body);
}
}

public function process_error_body($message){
Expand All @@ -66,6 +78,19 @@ public function process_error_body($message){
$this->errors = $recuperable_error;
}

private function fetchPaging($filters, $body) {
if (array_key_exists("paging", $body)) {
$paging = $body["paging"];
$this->limit = $paging["limit"];
$this->total = $paging["total"];
$this->offset = $paging["offset"];
} else {
$this->offset = array_key_exists("offset", $filters) ? $filters["offset"] : 0;
$this->limit = array_key_exists("limit", $filters) ? $filters["limit"] : 20;
$this->total = array_key_exists("total", $body) ? $body["total"] : 0;
}
}

}

?>
?>
15 changes: 6 additions & 9 deletions src/MercadoPago/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,20 @@ public function cleanQueryParams($entity)
public function setQueryParams($entity, $urlParams = [])
{
$configuration = $this->_getEntityConfiguration($entity);
$params = [];



if (!isset($configuration->query) || !isset($configuration->query['url_query'])) {
$configuration->query['url_query'] = $params;
$configuration->query['url_query'] = [];
}

$params = [];
if (isset($configuration->params)) {
foreach ($configuration->params as $value) {
$params[$value] = $this->_config->get(strtoupper($value));
}
if (count($params) > 0) {
$arrayMerge = array_merge($urlParams, $params, $configuration->query['url_query']);
$configuration->query['url_query'] = $arrayMerge;
}
}


$arrayMerge = array_merge($urlParams, $params, $configuration->query['url_query']);
$configuration->query['url_query'] = $arrayMerge;
}
/**
* @param $entity
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class Version
{
public static
$_VERSION = '1.11.0';
$_VERSION = '1.12.0';
}

0 comments on commit f282d14

Please sign in to comment.