Skip to content

Commit

Permalink
Merge pull request #241 from TransbankDevelopers/feat/api-1.3
Browse files Browse the repository at this point in the history
Feat/api 1.3
  • Loading branch information
Matiasnickolas authored Sep 7, 2022
2 parents fca5464 + 600d4fb commit 6d9c5be
Show file tree
Hide file tree
Showing 40 changed files with 1,128 additions and 53 deletions.
19 changes: 19 additions & 0 deletions src/Common/Responses/BaseDeferredCaptureHistoryResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Transbank\Common\Responses;

class BaseDeferredCaptureHistoryResponse
{
public $operations;

public function __construct($json)
{
if (is_array($json)) {
$this->operations = [];
foreach ($json as $operation) {
$this->operations[] = HistoryDetails::createFromArray($operation);
}
}

}
}
63 changes: 63 additions & 0 deletions src/Common/Responses/BaseDeferredStatusResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Transbank\Common\Responses;

use Transbank\Utils\Utils;

class BaseDeferredStatusResponse
{
public $authorizationCode;
public $authorizationDate;
public $totalAmount;
public $expirationDate;
public $responseCode;

public function __construct($json)
{
$authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->setAuthorizationCode($authorizationCode);
$authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->setAuthorizationDate($authorizationDate);
$totalAmount = Utils::returnValueIfExists($json, 'total_amount');
$this->setTotalAmount($totalAmount);
$expirationDate = Utils::returnValueIfExists($json, 'expiration_date');
$this->setExpirationDate($expirationDate);
$responseCode = Utils::returnValueIfExists($json, 'response_code');
$this->setResponseCode($responseCode);
}

public function setAuthorizationCode($authorizationCode)
{
$this->authorizationCode = $authorizationCode;

return $this;
}

public function setAuthorizationDate($authorizationDate)
{
$this->authorizationDate = $authorizationDate;

return $this;
}

public function setTotalAmount($totalAmount)
{
$this->totalAmount = $totalAmount;

return $this;
}

public function setExpirationDate($expirationDate)
{
$this->expirationDate = $expirationDate;

return $this;
}

public function setResponseCode($responseCode)
{
$this->responseCode = $responseCode;

return $this;
}
}
50 changes: 50 additions & 0 deletions src/Common/Responses/HistoryDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Transbank\Common\Responses;

use Transbank\Utils\Utils;

class HistoryDetails
{

public $type;
public $amount;
public $authorizationCode;
public $authorizationDate;
public $totalAmount;
public $expirationDate;
public $responseCode;

public function __construct(
$type,
$amount,
$authorizationCode,
$authorizationDate,
$totalAmount,
$expirationDate,
$responseCode
) {
$this->type = $type;
$this->amount = $amount;
$this->authorizationCode = $authorizationCode;
$this->authorizationDate = $authorizationDate;
$this->totalAmount = $totalAmount;
$this->expirationDate = $expirationDate;
$this->responseCode = $responseCode;
}

public static function createFromArray(array $array)
{
$type = isset($array['type']) ? $array['type'] : null;
$amount = isset($array['amount']) ? $array['amount'] : null;
$authorizationCode = isset($array['authorization_code']) ? $array['authorization_code'] : null;
$authorizationDate = isset($array['authorization_date']) ? $array['authorization_date'] : null;
$totalAmount = isset($array['total_amount']) ? $array['total_amount'] : null;
$expirationDate = isset($array['expiration_date']) ? $array['expiration_date'] : null;
$responseCode = isset($array['response_code']) ? $array['response_code'] : null;

return new static($type, $amount, $authorizationCode, $authorizationDate, $totalAmount, $expirationDate,
$responseCode);
}

}
155 changes: 149 additions & 6 deletions src/TransaccionCompleta/MallTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

namespace Transbank\TransaccionCompleta;

use Transbank\TransaccionCompleta\Responses\MallDeferredCaptureHistoryResponse;
use Transbank\TransaccionCompleta\Responses\MallIncreaseAmountResponse;
use Transbank\TransaccionCompleta\Responses\MallIncreaseAuthorizationDateResponse;
use Transbank\TransaccionCompleta\Responses\MallReversePreAuthorizedAmountResponse;
use Transbank\TransaccionCompleta\Exceptions\MallTransactionCaptureException;
use Transbank\TransaccionCompleta\Exceptions\MallTransactionCommitException;
use Transbank\TransaccionCompleta\Exceptions\MallTransactionCreateException;
Expand All @@ -20,19 +24,27 @@
use Transbank\TransaccionCompleta\Responses\MallTransactionRefundResponse;
use Transbank\TransaccionCompleta\Responses\MallTransactionStatusResponse;
use Transbank\Utils\InteractsWithWebpayApi;
use Transbank\Webpay\Exceptions\MallDeferredCaptureHistoryException;
use Transbank\Webpay\Exceptions\MallIncreaseAmountException;
use Transbank\Webpay\Exceptions\MallIncreaseAuthorizationDateException;
use Transbank\Webpay\Exceptions\MallReversePreAuthorizedAmountException;
use Transbank\Webpay\Exceptions\WebpayRequestException;
use Transbank\Webpay\Options;

class MallTransaction
{
use InteractsWithWebpayApi;

const ENDPOINT_CREATE = 'rswebpaytransaction/api/webpay/v1.2/transactions';
const ENDPOINT_INSTALLMENTS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/installments';
const ENDPOINT_COMMIT = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}';
const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/refunds';
const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}';
const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.2/transactions/{token}/capture';
const ENDPOINT_CREATE = 'rswebpaytransaction/api/webpay/v1.3/transactions';
const ENDPOINT_INSTALLMENTS = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/installments';
const ENDPOINT_COMMIT = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}';
const ENDPOINT_REFUND = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/refunds';
const ENDPOINT_STATUS = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}';
const ENDPOINT_CAPTURE = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/capture';
const ENDPOINT_INCREASE_AMOUNT = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/amount';
const ENDPOINT_INCREASE_AUTHORIZATION_DATE = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/authorization_date';
const ENDPOINT_REVERSE_PRE_AUTHORIZE_AMOUNT = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/reverse/amount';
const ENDPOINT_DEFERRED_CAPTURE_HISTORY = 'rswebpaytransaction/api/webpay/v1.3/transactions/{token}/details';

public function create(
$buyOrder,
Expand Down Expand Up @@ -171,6 +183,137 @@ public function capture($token, $commerceCode, $buyOrder, $authorizationCode, $c
return new Responses\MallTransactionCaptureResponse($response);
}

/**
* @param $token
* @param $buyOrder
* @param $authorizationCode
* @param $amount
* @param $commerceCode
*
* @throws MallIncreaseAmountException
* @throws GuzzleException
*
* @return MallIncreaseAmountResponse
*/
public function increaseAmount($token, $buyOrder, $authorizationCode, $amount, $commerceCode)
{
$payload = [
'buy_order' => $buyOrder,
'authorization_code' => $authorizationCode,
'amount' => $amount,
'commerce_code' => $commerceCode,
];

try {
$response = $this->sendRequest(
'PUT',
str_replace('{token}', $token, static::ENDPOINT_INCREASE_AMOUNT),
$payload
);
} catch (WebpayRequestException $e) {
throw MallIncreaseAmountException::raise($e);
}

return new MallIncreaseAmountResponse($response);
}

/**
* @param $token
* @param $buyOrder
* @param $authorizationCode
* @param $commerceCode
*
* @throws MallIncreaseAuthorizationDateException
* @throws GuzzleException
*
* @return MallIncreaseAuthorizationDateResponse
*/
public function increaseAuthorizationDate($token, $buyOrder, $authorizationCode, $commerceCode)
{
$payload = [
'buy_order' => $buyOrder,
'authorization_code' => $authorizationCode,
'commerce_code' => $commerceCode,
];

try {
$response = $this->sendRequest(
'PUT',
str_replace('{token}', $token, static::ENDPOINT_INCREASE_AUTHORIZATION_DATE),
$payload
);
} catch (WebpayRequestException $e) {
throw MallIncreaseAuthorizationDateException::raise($e);
}

return new MallIncreaseAuthorizationDateResponse($response);
}

/**
* @param $token
* @param $buyOrder
* @param $authorizationCode
* @param $amount
* @param $commerceCode
*
* @throws MallReversePreAuthorizedAmountException
* @throws GuzzleException
*
* @return MallReversePreAuthorizedAmountResponse
*/
public function reversePreAuthorizedAmount($token, $buyOrder, $authorizationCode, $amount, $commerceCode)
{
$payload = [
'buy_order' => $buyOrder,
'authorization_code' => $authorizationCode,
'amount' => $amount,
'commerce_code' => $commerceCode,
];

try {
$response = $this->sendRequest(
'PUT',
str_replace('{token}', $token, static::ENDPOINT_REVERSE_PRE_AUTHORIZE_AMOUNT),
$payload
);
} catch (WebpayRequestException $e) {
throw MallReversePreAuthorizedAmountException::raise($e);
}

return new MallReversePreAuthorizedAmountResponse($response);
}

/**
* @param $token
* @param $buyOrder
* @param $commerceCode
*
* @throws MallDeferredCaptureHistoryException
* @throws GuzzleException
*
* @return MallDeferredCaptureHistoryResponse
*/
public function deferredCaptureHistory($token, $buyOrder, $commerceCode)
{
$payload = [
'buy_order' => $buyOrder,
'commerce_code' => $commerceCode,
];

try {
$response = $this->sendRequest(
'POST',
str_replace('{token}', $token, static::ENDPOINT_DEFERRED_CAPTURE_HISTORY),
$payload
);
var_dump($response);
} catch (WebpayRequestException $e) {
throw MallDeferredCaptureHistoryException::raise($e);
}

return new MallDeferredCaptureHistoryResponse($response);
}

public static function getDefaultOptions()
{
return Options::forIntegration(TransaccionCompleta::DEFAULT_MALL_COMMERCE_CODE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredCaptureHistoryResponse;

class DeferredCaptureHistoryResponse extends BaseDeferredCaptureHistoryResponse
{
}
9 changes: 9 additions & 0 deletions src/TransaccionCompleta/Responses/IncreaseAmountResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class IncreaseAmountResponse extends BaseDeferredStatusResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class IncreaseAuthorizationDateResponse extends BaseDeferredStatusResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredCaptureHistoryResponse;

class MallDeferredCaptureHistoryResponse extends BaseDeferredCaptureHistoryResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class MallIncreaseAmountResponse extends BaseDeferredStatusResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class MallIncreaseAuthorizationDateResponse extends BaseDeferredStatusResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class MallReversePreAuthorizedAmountResponse extends BaseDeferredStatusResponse
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Common\Responses\BaseDeferredStatusResponse;

class ReversePreAuthorizedAmountResponse extends BaseDeferredStatusResponse
{
}
Loading

0 comments on commit 6d9c5be

Please sign in to comment.