Skip to content

Commit

Permalink
Merge pull request #57 from mateus-picoloto/main-opensource
Browse files Browse the repository at this point in the history
feat: create getToken for Tds
  • Loading branch information
andreals authored Dec 15, 2023
2 parents 49e0d22 + d503da5 commit acab770
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
95 changes: 95 additions & 0 deletions src/Controllers/TdsTokenController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?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\Http\HttpRequest;
use PagarmeCoreApiLib\Http\HttpResponse;
use PagarmeCoreApiLib\Http\HttpMethod;
use PagarmeCoreApiLib\Http\HttpContext;
use Unirest\Request;


class TdsTokenController extends BaseController
{
/**
* @var TdsTokenController The reference to *Singleton* instance of this class
*/
private static $instance;

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

return static::$instance;
}

/**
* @param string $environment
* @param string $accountId
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function getToken(
$environment,
$accountId
) {

//prepare query string for API call
$_queryBuilder = '{environment}/3ds2/internal/{account_id}/tds-token';

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

//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\\GetTdsTokenResponse');
}
}
41 changes: 41 additions & 0 deletions src/Models/GetTdsTokenResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
* PagarmeCoreApiLib
*
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
*/

namespace PagarmeCoreApiLib\Models;

use JsonSerializable;

/**
*Response object for getting a charge
*/
class GetTdsTokenResponse implements JsonSerializable
{
/**
* @required
* @var string $tdsToken public property
* @maps tds_token
*/
public $tdsToken;

public function __construct()
{
if (1 == func_num_args()) {
$this->tdsToken = func_get_arg(0);
}
}

/**
* Encode this object to JSON
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$json = array();
$json['tds_token'] = $this->tdsToken;
return $json;
}
}
10 changes: 9 additions & 1 deletion src/PagarmeCoreApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@ public function getTransactions()
return Controllers\TransactionsController::getInstance();
}
/**
* Singleton access to Transactions controller
* Singleton access to Accounts controller
* @return Controllers\AccountsController The *Singleton* instance
*/
public function getAccounts()
{
return Controllers\AccountsController::getInstance();
}
/**
* Singleton access to Tds Tokens controller
* @return Controllers\TdsTokenController The *Singleton* instance
*/
public function getTdsToken()
{
return Controllers\TdsTokenController::getInstance();
}
}

0 comments on commit acab770

Please sign in to comment.