Skip to content

Commit

Permalink
Merge pull request #230 from mercadopago/master
Browse files Browse the repository at this point in the history
Update from master
  • Loading branch information
Pedro Gonçalves committed Nov 5, 2019
2 parents 2a63626 + e8764a9 commit 902cfe1
Show file tree
Hide file tree
Showing 58 changed files with 1,962 additions and 694 deletions.
3 changes: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve

---

> For support request no related with bugs or feature requests for this SDK, please use the official developers support channel https://mercadopago.com.ar/developers/es/support/

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Using this snippet '....'
3. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Server (please complete the following information):**
- OS: [e.g. iOS]
- WebServer
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ nbproject
/composer.lock

#Samples Vendor
/samples/vendor
/samples/vendor

.env
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php
php:
- "5.3"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"

before_script:
- composer self-update
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 MercadoPago Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
# Mercado Pago SDK for PHP

[![Build Status](https://travis-ci.org/imasson/px-php.png)](https://travis-ci.org/imasson/px-php)
[![Coverage Status](https://coveralls.io/repos/github/imasson/px-php/badge.svg?branch=feature-ci-configuration-restclient)](https://coveralls.io/github/imasson/px-php?branch=feature-ci-configuration-restclient)
[![Build Status](https://travis-ci.org/mercadopago/dx-php.png)](https://travis-ci.org/mercadopago/dx-php)

This library provides developers with a simple set of bindings to the Mercado Pago API.

### PHP Versions Supported:

The SDK supports PHP 5 or major
The SDK supports PHP 5.6 or major

### Installation

#### Using Composer

1. Download [Composer](https://getcomposer.org/download/) if not already installed
2. Go to your project directory and Execute `composer require "mercadopago/px-php"` on the command line.
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.2.1"` on the command line.
3. This how your directory structure would look like.

![screen shot 2017-12-27 at 5 25 43 pm](https://user-images.githubusercontent.com/864790/34393031-6c1068a4-eb2e-11e7-933a-81a47ba7b727.png)

4. Thats all, you have Mercado Pago SDK installed.

![installation-demo](img/ezgif-2-f98e8701825e.gif)

### Quick Start

1. You have to require the library from your Composer vendor folder.
Expand All @@ -33,19 +31,18 @@ The SDK supports PHP 5 or major

You have two types of credentials:

* **For web-checkout:**
* **For API or custom checkout:**
```php
MercadoPago\SDK::setAccessToken("YOUR_ACCESS_TOKEN"); // On Production
MercadoPago\SDK::setAccessToken("YOUR_TEST_ACCESS_TOKEN"); // On Sandbox
```

* **For API or custom checkout:**
* **For Web-checkout:**
```php
MercadoPago\SDK::setClientId("YOUR_CLIENT_ID");
MercadoPago\SDK::setClientSecret("YOUR_CLIENT_SECRET");
```

3. Use the resource objects.
3. Using resource objects.

You can interact with all the resources available in the public API, to this each resource is represented by classes according to the following diagram:

Expand All @@ -56,7 +53,7 @@ The SDK supports PHP 5 or major
```php
<?php

require_once 'vendor/autoload.php';
require __DIR__ . '/vendor/autoload.php';

MercadoPago\SDK::setAccessToken("YOUR_ACCESS_TOKEN");

Expand All @@ -70,14 +67,12 @@ The SDK supports PHP 5 or major
$payment->payer = array(
"email" => "[email protected]"
);

$payment->save();


echo $payment->status;

?>
```

### Support

Write us at developers@mercadopago.com
Write us at [developers.mercadopago.com](https://developers.mercadopago.com)
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"type": "library",
"homepage": "https://github.com/mercadopago/dx-php",
"license": "MIT",
"config": {
"platform": {
"php": "5.6"
}
},
"authors": [
{
"name": "imasson",
Expand All @@ -16,25 +21,28 @@
}
],
"require": {
"php": ">=5.4.0",
"doctrine/common": "~2.4"
"php": ">=5.5.0",
"doctrine/common": "~2.6",
"doctrine/annotations": "1.4"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "^5",
"symfony/yaml": "~2.5",
"phpmd/phpmd": "@stable",
"squizlabs/php_codesniffer": "2.3.*",
"sebastian/phpcpd": "*",
"doctrine/orm": "~2.3"
"doctrine/orm": "~2.3",
"vlucas/phpdotenv": "^2.5"
},
"autoload": {
"psr-4": {
"MercadoPago\\": [
"src/MercadoPago/",
"tests/",
"src/MercadoPago/Generic/",
"src/MercadoPago/Entities/",
"src/MercadoPago/Entities/Shared/"
]
}
}
}
}
48 changes: 48 additions & 0 deletions img/demo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/ezgif-2-f98e8701825e.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified phpunit.phar
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion samples/customer-and-cards/customer/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__).'/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');

$customer = new MercadoPago\Customer();
$customer->email = "[email protected]";
Expand Down
2 changes: 1 addition & 1 deletion samples/payment/minimal/cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__) . '/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');

# Create a Payment
require_once dirname(__FILE__) . '/create.php';
Expand Down
2 changes: 1 addition & 1 deletion samples/suscriptions/basic-suscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__) . '/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');


$preapproval_data = new MercadoPago\Preapproval();
Expand Down
2 changes: 1 addition & 1 deletion samples/suscriptions/pause-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__) . '/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');


# Create a Plan
Expand Down
2 changes: 1 addition & 1 deletion samples/suscriptions/plan-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__) . '/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');

$plan = new MercadoPago\Plan();

Expand Down
4 changes: 2 additions & 2 deletions samples/suscriptions/subscribe-to-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once dirname(__FILE__) . '/../../index.php';

$config->set('ACCESS_TOKEN', 'TEST-6295877106812064-042916-6cead5bc1e48af95ea61cc9254595865__LC_LA__-202809963');
$config->set('ACCESS_TOKEN', 'ACCESS_TOKEN');


# Create a Plan
Expand All @@ -12,7 +12,7 @@

$subscription->plan_id = $plan->id;

$subscription->payer = array("id": "customer_id");
$subscription->payer = array("id" => "customer_id");

$subscription->save();

Expand Down
1 change: 1 addition & 0 deletions src/MercadoPago/Annotation/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Attribute extends Annotation
* @var
*/
public $required = false;
public $serialize = true ;
public $readOnly;
public $primaryKey;
public $idempotency;
Expand Down
45 changes: 40 additions & 5 deletions src/MercadoPago/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function getDefaults()
'base_url' => 'https://api.mercadopago.com',
'CLIENT_ID' => '',
'CLIENT_SECRET' => '',
'USER_ID' => '',
'APP_ID' => '',
'ACCESS_TOKEN' => '',
'REFRESH_TOKEN' => '',
Expand Down Expand Up @@ -106,13 +107,47 @@ private function _getParser($extension)
public function set($key, $value)
{
parent::set($key, $value);
if ($this->get('CLIENT_ID') != "" && $this->get('CLIENT_SECRET') != "" && empty($this->get('ACCESS_TOKEN'))) {

if ($key == "ACCESS_TOKEN") {
$user = $this->getUserId($value);
parent::set('USER_ID', $user['id']);
}

if (parent::get('CLIENT_ID') != "" && parent::get('CLIENT_SECRET') != "" && empty(parent::get('ACCESS_TOKEN'))) {

$response = $this->getToken();
if (isset($response['access_token']) && isset($response['refresh_token'])) {

if (isset($response['access_token'])) {
parent::set('ACCESS_TOKEN', $response['access_token']);
parent::set('REFRESH_TOKEN', $response['refresh_token']);


$user = $this->getUserId($response['access_token']);

if (isset($user['id'])) {
parent::set('USER_ID', $user['id']);
}

}

}
}


/**
* @return mixed
*/
public function getUserId($access_token)
{
if (!$this->_restclient) {
$this->_restclient = new RestClient();
$this->_restclient->setHttpParam('address', $this->get('base_url'));
}
$response = $this->_restclient->get("/users/me", array(
"url_query" => array("access_token" => $access_token)
)
);

return $response["body"];
}

/**
Expand Down Expand Up @@ -143,8 +178,8 @@ public function refreshToken()
$this->_restclient = new RestClient();
}
$data = ['grant_type' => 'refresh_token',
'refresh_token' => $this->get('REFRESH_TOKEN'),
'client_secret' => $this->get('ACCESS_TOKEN')];
'refresh_token' => $this->get('REFRESH_TOKEN'),
'client_secret' => $this->get('ACCESS_TOKEN')];
$this->_restclient->setHttpParam('address', $this->get('base_url'));
$response = $this->_restclient->post("/oauth/token", ['json_data' => json_encode($data)]);
if (isset($response['access_token']) && isset($response['refresh_token']) && isset($response['client_id']) && isset($response['client_secret'])) {
Expand Down
9 changes: 9 additions & 0 deletions src/MercadoPago/Config/AbstractConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ protected function getDefaults()
return [];
}

public function clean()
{
return $this->data = array(
'base_url' => 'https://api.mercadopago.com',
);
}


/**
* @param $key
* @param null $default
Expand All @@ -44,6 +52,7 @@ protected function getDefaults()
*/
public function get($key, $default = null)
{

if ($this->has($key)) {
return $this->data[$key];
}
Expand Down
Loading

0 comments on commit 902cfe1

Please sign in to comment.