Skip to content

Commit

Permalink
Merge pull request #21 from pagarme/CodeGen-PHP
Browse files Browse the repository at this point in the history
5.4.0 - Added split on subscription
  • Loading branch information
GusBedasi authored Jan 12, 2022
2 parents bdd66ae + 2b95adb commit 9f9bba7
Show file tree
Hide file tree
Showing 16 changed files with 1,711 additions and 1,428 deletions.
1,693 changes: 862 additions & 831 deletions README.md

Large diffs are not rendered by default.

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.3.0';
const USER_AGENT = 'PagarmeCoreApi - PHP 5.4.0';

/**
* HttpCallBack instance associated with this controller
Expand Down
130 changes: 65 additions & 65 deletions src/Controllers/ChargesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,71 +107,6 @@ public function updateChargeMetadata(
return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetChargeResponse');
}

/**
* Captures a charge
*
* @param string $chargeId Charge id
* @param Models\CreateCaptureChargeRequest $request (optional) Request for capturing a charge
* @param string $idempotencyKey (optional) TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function captureCharge(
$chargeId,
$request = null,
$idempotencyKey = null
) {

//prepare query string for API call
$_queryBuilder = '/charges/{charge_id}/capture';

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

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

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json',
'content-type' => 'application/json; charset=utf-8',
'idempotency-key' => $idempotencyKey
);

//json encode body
$_bodyJson = Request\Body::Json($request);

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

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

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

$_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\\GetChargeResponse');
}

/**
* Updates a charge's payment method
*
Expand Down Expand Up @@ -449,6 +384,71 @@ public function getCharges(
return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\ListChargesResponse');
}

/**
* Captures a charge
*
* @param string $chargeId Charge id
* @param Models\CreateCaptureChargeRequest $request (optional) Request for capturing a charge
* @param string $idempotencyKey (optional) TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function captureCharge(
$chargeId,
$request = null,
$idempotencyKey = null
) {

//prepare query string for API call
$_queryBuilder = '/charges/{charge_id}/capture';

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

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

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json',
'content-type' => 'application/json; charset=utf-8',
'idempotency-key' => $idempotencyKey
);

//json encode body
$_bodyJson = Request\Body::Json($request);

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

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

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

$_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\\GetChargeResponse');
}

/**
* Updates the card from a charge
*
Expand Down
142 changes: 71 additions & 71 deletions src/Controllers/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,20 @@ public function deleteAccessToken(
}

/**
* Creates a access token for a customer
* Creates a new customer
*
* @param string $customerId Customer Id
* @param Models\CreateAccessTokenRequest $request Request for creating a access token
* @param string $idempotencyKey (optional) TODO: type description here
* @param Models\CreateCustomerRequest $request Request for creating a customer
* @param string $idempotencyKey (optional) TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function createAccessToken(
$customerId,
public function createCustomer(
$request,
$idempotencyKey = null
) {

//prepare query string for API call
$_queryBuilder = '/customers/{customer_id}/access-tokens';

//process optional query parameters
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
'customer_id' => $customerId,
));
$_queryBuilder = '/customers';

//validate and preprocess url
$_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI . $_queryBuilder);
Expand Down Expand Up @@ -301,7 +294,7 @@ public function createAccessToken(

$mapper = $this->getJsonMapper();

return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetAccessTokenResponse');
return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetCustomerResponse');
}

/**
Expand Down Expand Up @@ -369,64 +362,6 @@ public function createAddress(
return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetAddressResponse');
}

/**
* Creates a new customer
*
* @param Models\CreateCustomerRequest $request Request for creating a customer
* @param string $idempotencyKey (optional) TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function createCustomer(
$request,
$idempotencyKey = null
) {

//prepare query string for API call
$_queryBuilder = '/customers';

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

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json',
'content-type' => 'application/json; charset=utf-8',
'idempotency-key' => $idempotencyKey
);

//json encode body
$_bodyJson = Request\Body::Json($request);

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

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

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

$_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\\GetCustomerResponse');
}

/**
* Delete a Customer's access tokens
*
Expand Down Expand Up @@ -805,6 +740,71 @@ public function updateCustomer(
return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetCustomerResponse');
}

/**
* Creates a access token for a customer
*
* @param string $customerId Customer Id
* @param Models\CreateAccessTokenRequest $request Request for creating a access token
* @param string $idempotencyKey (optional) TODO: type description here
* @return mixed response from the API call
* @throws APIException Thrown if API call fails
*/
public function createAccessToken(
$customerId,
$request,
$idempotencyKey = null
) {

//prepare query string for API call
$_queryBuilder = '/customers/{customer_id}/access-tokens';

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

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

//prepare headers
$_headers = array (
'user-agent' => BaseController::USER_AGENT,
'Accept' => 'application/json',
'content-type' => 'application/json; charset=utf-8',
'idempotency-key' => $idempotencyKey
);

//json encode body
$_bodyJson = Request\Body::Json($request);

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

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

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

$_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\\GetAccessTokenResponse');
}

/**
* Get all access tokens from a customer
*
Expand Down
Loading

0 comments on commit 9f9bba7

Please sign in to comment.