Skip to content

Commit

Permalink
Merge pull request #304 from mercadopago/release/2.4.0
Browse files Browse the repository at this point in the history
Release 2.4.0
  • Loading branch information
delias-silva authored Jul 15, 2021
2 parents 951c2e9 + 97962eb commit 1ea94fb
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0"` for PHP7 or `composer require "mercadopago/dx-php:1.11.0"` for PHP5.6.
`composer require "mercadopago/dx-php:2.4.0"` for PHP7 or `composer require "mercadopago/dx-php:1.12.0"` 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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "library",
"homepage": "https://github.com/mercadopago/sdk-php",
"license": "MIT",
"version": "2.3.0",
"version": "2.4.0",
"config": {
"platform": {
"php": "7.1"
Expand Down
2 changes: 1 addition & 1 deletion docs/classes/MercadoPago-Version.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h4 class="phpdocumentor-element__name" id="property__VERSION">
<span class="phpdocumentor-signature__visibility">public</span>
<span class="phpdocumentor-signature__static">static</span> <span class="phpdocumentor-signature__type">mixed</span>
<span class="phpdocumentor-signature__name">$_VERSION</span>
= <span class="phpdocumentor-signature__default-value">&#039;2.3.0&#039;</span></code>
= <span class="phpdocumentor-signature__default-value">&#039;2.4.0&#039;</span></code>



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 @@ -29,9 +29,16 @@ class Card extends Entity
*/
protected $id;

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

/**
* customer_id
* @Attribute(required = true)
* @Attribute(required = true, serialize = false)
* @var string
*/
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 @@ -12,6 +12,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
46 changes: 35 additions & 11 deletions src/MercadoPago/Generic/SearchResultsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,36 @@ public function setPaginateParams($params){
}

public function next() {

$new_offset = $this->limit + $this->offset;
echo "\n new offset" . $new_offset ;

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

$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 +77,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;
}
}

}

?>
?>
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 = '2.3.0';
$_VERSION = '2.4.0';
}

0 comments on commit 1ea94fb

Please sign in to comment.