Skip to content

Commit

Permalink
Added OAuth functionalities
Browse files Browse the repository at this point in the history
- Added Mercado Pago OAuth functionalities
- Fixed proccess_causes method
  • Loading branch information
Pedro Gonçalves committed Nov 12, 2019
1 parent 902cfe1 commit 8d46ae6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
82 changes: 82 additions & 0 deletions src/MercadoPago/Entities/OAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
namespace MercadoPago;
use MercadoPago\Annotation\RestMethod;
use MercadoPago\Annotation\Attribute;

/**
* @RestMethod(resource="/oauth/token", method="create")
*/

class OAuth extends Entity
{
/**
* @Attribute()
*/
protected $client_secret;
/**
* @Attribute()
*/
protected $grant_type;
/**
* @Attribute()
*/
protected $code;
/**
* @Attribute()
*/
protected $redirect_uri;

/**
* @Attribute()
*/
protected $access_token;
/**
* @Attribute()
*/
protected $public_key;
/**
* @Attribute()
*/
protected $refresh_token;
/**
* @Attribute()
*/
protected $live_mode;
/**
* @Attribute()
*/
protected $user_id;
/**
* @Attribute()
*/
protected $token_type;
/**
* @Attribute()
*/
protected $expires_in;
/**
* @Attribute()
*/
protected $scope;

public function getAuthorizationURL($app_id, $redirect_uri){
return "https://auth.mercadopago.com.br/authorization?client_id=${app_id}&response_type=code&platform_id=mp&redirect_uri=${redirect_uri}";
}

public function getOAuthCredentials($authorization_code, $redirect_uri){
$this->client_secret = SDK::getAccessToken();
$this->grant_type = 'authorization_code';
$this->code = $authorization_code;
$this->redirect_uri = $redirect_uri;

return $this->save();
}

public function refreshOAuthCredentials($refresh_token){
$this->client_secret = SDK::getAccessToken();
$this->grant_type = 'refresh_token';
$this->refresh_token = $refresh_token;

return $this->save();
}
}
14 changes: 9 additions & 5 deletions src/MercadoPago/Generic/RecuperableError.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ public function add_cause($code, $description) {
}

public function proccess_causes($causes){
foreach ($causes as $cause){
if(is_array($cause) && (!isset($cause['code']) && !isset($cause['description']))){
$this->proccess_causes($cause);
}else{
$this->add_cause($cause['code'], $cause['description']);
if(isset($causes['code']) && isset($causes['description'])){
$this->add_cause($causes['code'], $causes['description']);
}else{
foreach ($causes as $cause){
if(is_array($cause) && (!isset($cause['code']) && !isset($cause['description']))){
$this->proccess_causes($cause);
}else{
$this->add_cause($cause['code'], $cause['description']);
}
}
}
}
Expand Down

0 comments on commit 8d46ae6

Please sign in to comment.