Skip to content

Commit

Permalink
Merge pull request #56 from mauriciohaygert/v5.6.3
Browse files Browse the repository at this point in the history
feat: create getAccount on API Pagarme
  • Loading branch information
andreals authored Sep 28, 2023
2 parents 1e6caa9 + 7f9f994 commit 49e0d22
Show file tree
Hide file tree
Showing 5 changed files with 434 additions and 3 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=5.4.0",
"php": ">=7.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand All @@ -29,4 +29,4 @@
"PagarmeCoreApiLib\\": "src/"
}
}
}
}
99 changes: 99 additions & 0 deletions src/Controllers/AccountsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/*
* PagarmeCoreApiLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/

namespace PagarmeCoreApiLib\Controllers;

use PagarmeCoreApiLib\APIException;
use PagarmeCoreApiLib\APIHelper;
use PagarmeCoreApiLib\Configuration;
use PagarmeCoreApiLib\Models;
use PagarmeCoreApiLib\Exceptions;
use PagarmeCoreApiLib\Http\HttpRequest;
use PagarmeCoreApiLib\Http\HttpResponse;
use PagarmeCoreApiLib\Http\HttpMethod;
use PagarmeCoreApiLib\Http\HttpContext;
use Unirest\Request;

/**
* @todo Add a general description for this controller.
*/
class AccountsController extends BaseController
{
/**
* @var AccountsController The reference to *Singleton* instance of this class
*/
private static $instance;

/**
* Returns the *Singleton* instance of this class.
* @return AccountsController The *Singleton* instance.
*/
public static function getInstance()
{
if (null === static::$instance) {
static::$instance = new static();
}

return static::$instance;
}

/**
* @todo Add general description for this endpoint
*
* @param string $accountId TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function getAccountById(
$accountId
) {

//prepare query string for API call
$_queryBuilder = '/accounts/{account_id}';

//process optional query parameters
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
'account_id' => $accountId,
));

//validate and preprocess url
$_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder);

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json'
);

//set HTTP basic auth parameters
Request::auth(Configuration::$basicAuthUserName, Configuration::$basicAuthPassword);

//call on-before Http callback
$_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl);
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
}

//and invoke the API call request to fetch the response
$response = Request::get($_queryUrl, $_headers);

$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);

//call on-after Http callback
if ($this->getHttpCallBack() != null) {
$this->getHttpCallBack()->callOnAfterRequest($_httpContext);
}

//handle errors defined at the API level
$this->validateResponse($_httpResponse, $_httpContext);

$mapper = $this->getJsonMapper();

return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetAccountResponse');
}
}
2 changes: 1 addition & 1 deletion src/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BaseController
* User-agent to be sent with API calls
* @var string
*/
const USER_AGENT = 'PagarmeCoreApi - PHP 5.7.0';
const USER_AGENT = 'PagarmeCoreApi - PHP 5.6.3';

/**
* HttpCallBack instance associated with this controller
Expand Down
Loading

0 comments on commit 49e0d22

Please sign in to comment.