Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: kiuwan bugs 01 #270

Merged
merged 9 commits into from
Nov 30, 2023
Merged
15 changes: 5 additions & 10 deletions src/Common/Responses/BaseDeferredStatusResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ class BaseDeferredStatusResponse

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);
$this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->totalAmount = Utils::returnValueIfExists($json, 'total_amount');
$this->expirationDate = Utils::returnValueIfExists($json, 'expiration_date');
$this->responseCode = Utils::returnValueIfExists($json, 'response_code');
}

public function setAuthorizationCode($authorizationCode)
Expand Down
31 changes: 14 additions & 17 deletions src/Patpass/PatpassByWebpay/Responses/TransactionCommitResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Transbank\Patpass\PatpassByWebpay\Responses;

use Transbank\Utils\Utils;

class TransactionCommitResponse
{
private $vci;
Expand All @@ -22,23 +24,18 @@ class TransactionCommitResponse
*/
public function __construct($json)
{
$this->setVci($this->returnValueIfExists($json, 'vci'));
$this->setAmount($this->returnValueIfExists($json, 'amount'));
$this->setStatus($this->returnValueIfExists($json, 'status'));
$this->setBuyOrder($this->returnValueIfExists($json, 'buy_order'));
$this->setSessionId($this->returnValueIfExists($json, 'session_id'));
$this->setCardDetail($this->returnValueIfExists($json, 'card_detail'));
$this->setAccountingDate($this->returnValueIfExists($json, 'accounting_date'));
$this->setTransactionDate($this->returnValueIfExists($json, 'transaction_date'));
$this->setAuthorizationCode($this->returnValueIfExists($json, 'authorization_code'));
$this->setPaymentTypeCode($this->returnValueIfExists($json, 'payment_type_code'));
$this->setResponseCode($this->returnValueIfExists($json, 'response_code'));
$this->setInstallmentsNumber($this->returnValueIfExists($json, 'installments_number'));
}

public function returnValueIfExists($json, $key)
{
return isset($json[$key]) ? $json[$key] : null;
$this->vci = Utils::returnValueIfExists($json, 'vci');
$this->amount = Utils::returnValueIfExists($json, 'amount');
$this->status = Utils::returnValueIfExists($json, 'status');
$this->buyOrder = Utils::returnValueIfExists($json, 'buy_order');
$this->sessionId = Utils::returnValueIfExists($json, 'session_id');
$this->cardDetail = Utils::returnValueIfExists($json, 'card_detail');
$this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date');
$this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date');
$this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->paymentTypeCode = Utils::returnValueIfExists($json, 'payment_type_code');
$this->responseCode = Utils::returnValueIfExists($json, 'response_code');
$this->installmentsNumber = Utils::returnValueIfExists($json, 'installments_number');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Transbank\Patpass\PatpassByWebpay\Responses;

use Transbank\Utils\Utils;

class TransactionCreateResponse
{
public $token;
Expand All @@ -14,10 +16,8 @@ class TransactionCreateResponse
*/
public function __construct($json)
{
$token = isset($json['token']) ? $json['token'] : null;
$this->setToken($token);
$url = isset($json['url']) ? $json['url'] : null;
$this->setUrl($url);
$this->token = Utils::returnValueIfExists($json, 'token');
$this->url = Utils::returnValueIfExists($json, 'url');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Transbank\Patpass\PatpassComercio\Exceptions;

use Transbank\PatPass\Exceptions\PatpassException;
use Transbank\Patpass\Exceptions\PatpassException;

class InscriptionStartException extends PatpassException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ class InscriptionFinishResponse

public function __construct($httpCode)
{
$this->setCode($httpCode);
$this->code = $httpCode;

if ($httpCode == 204) {
$this->setStatus('OK');

return;
$this->status = 'OK';
}
if ($httpCode == 404) {
$this->setStatus('Not Found');

return;
$this->status = 'Not Found';
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ class InscriptionStartResponse
*/
public function __construct($json)
{
$token = Utils::returnValueIfExists($json, 'token');
$this->setToken($token);

$url = Utils::returnValueIfExists($json, 'url');
$this->setUrlWebpay($url);
$this->token = Utils::returnValueIfExists($json, 'token');
$this->urlWebpay = Utils::returnValueIfExists($json, 'url');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class InscriptionStatusResponse

public function __construct($json)
{
$status = Utils::returnValueIfExists($json, 'authorized');
$this->setStatus($status);
$urlVoucher = Utils::returnValueIfExists($json, 'voucherUrl');
$this->setUrlVoucher($urlVoucher);
$this->status = Utils::returnValueIfExists($json, 'authorized');
$this->urlVoucher = Utils::returnValueIfExists($json, 'voucherUrl');
}

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

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 @@ -24,10 +20,6 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class MallTransactionCreateResponse

public function __construct($json)
{
$token = Utils::returnValueIfExists($json, 'token');
$this->setToken($token);
$this->token = Utils::returnValueIfExists($json, 'token');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ class MallTransactionInstallmentsResponse

public function __construct($json)
{
$installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount');
$this->setInstallmentsAmount($installmentsAmount);
$idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments');
$this->setIdQueryInstallments($idQueryInstallments);
$deferredPeriods = Utils::returnValueIfExists($json, 'deferred_periods');
$this->setDeferredPeriods($deferredPeriods);
$this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount');
$this->idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments');
$this->deferredPeriods = Utils::returnValueIfExists($json, 'deferred_periods');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ class MallTransactionRefundResponse

public function __construct($json)
{
$type = Utils::returnValueIfExists($json, 'type');
$this->setType($type);
$authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->setAuthorizationCode($authorizationCode);
$authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->setAuthorizationDate($authorizationDate);
$nullifiedAmount = Utils::returnValueIfExists($json, 'nullified_amount');
$this->setNullifiedAmount($nullifiedAmount);
$balance = Utils::returnValueIfExists($json, 'balance');
$this->setBalance($balance);
$responseCode = Utils::returnValueIfExists($json, 'response_code');
$this->setResponseCode($responseCode);
$this->type = Utils::returnValueIfExists($json, 'type');
$this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->nullifiedAmount = Utils::returnValueIfExists($json, 'nullified_amount');
$this->balance = Utils::returnValueIfExists($json, 'balance');
$this->responseCode = Utils::returnValueIfExists($json, 'response_code');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Utils\Utils;

class MallTransactionStatusResponse
{
protected $buyOrder;
Expand All @@ -13,14 +15,13 @@ class MallTransactionStatusResponse

public function __construct($json)
{
print_r($json);
$this->buyOrder = $json['buy_order'] ?? null;
$this->cardDetail = $json['card_detail'] ?? null;
$this->cardNumber = $json['card_detail']['card_number'] ?? null;
$this->accountingDate = $json['accounting_date'] ?? null;
$this->transactionDate = $json['transaction_date'] ?? null;
$details = $json['details'] ?? null;
$this->buyOrder = Utils::returnValueIfExists($json, 'buyOrder');
$this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date');
$this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date');
$this->cardDetail = Utils::returnValueIfExists($json, 'card_detail');
$this->cardNumber = Utils::returnValueIfExists($this->cardDetail, 'card_number');

$details = Utils::returnValueIfExists($json, 'details');
$this->details = null;
if (is_array($details)) {
$this->details = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class TransactionCreateResponse

public function __construct($json)
{
$token = Utils::returnValueIfExists($json, 'token');
$this->setToken($token);
$this->token = Utils::returnValueIfExists($json, 'token');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ class TransactionInstallmentsResponse

public function __construct($json)
{
$installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount');
$this->setInstallmentsAmount($installmentsAmount);
$idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments');
$this->setIdQueryInstallments($idQueryInstallments);
$deferredPeriods = Utils::returnValueIfExists($json, 'deferred_periods');
$this->setDeferredPeriods($deferredPeriods);
$this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount');
$this->idQueryInstallments = Utils::returnValueIfExists($json, 'id_query_installments');
$this->deferredPeriods = Utils::returnValueIfExists($json, 'deferred_periods');
}

/**
Expand Down
18 changes: 6 additions & 12 deletions src/TransaccionCompleta/Responses/TransactionRefundResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ class TransactionRefundResponse

public function __construct($json)
{
$type = Utils::returnValueIfExists($json, 'type');
$this->setType($type);
$authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->setAuthorizationCode($authorizationCode);
$authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->setAuthorizationDate($authorizationDate);
$nullifiedAmount = Utils::returnValueIfExists($json, 'nullified_amount');
$this->setNullifiedAmount($nullifiedAmount);
$balance = Utils::returnValueIfExists($json, 'balance');
$this->setBalance($balance);
$responseCode = Utils::returnValueIfExists($json, 'response_code');
$this->setResponseCode($responseCode);
$this->type = Utils::returnValueIfExists($json, 'type');
$this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->authorizationDate = Utils::returnValueIfExists($json, 'authorization_date');
$this->nullifiedAmount = Utils::returnValueIfExists($json, 'nullified_amount');
$this->balance = Utils::returnValueIfExists($json, 'balance');
$this->responseCode = Utils::returnValueIfExists($json, 'response_code');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Transbank\TransaccionCompleta\Responses;

use Transbank\Utils\HasTransactionStatus;
use Transbank\Utils\Utils;

class TransactionStatusResponse
{
Expand All @@ -12,7 +13,7 @@ class TransactionStatusResponse

public function __construct($json)
{
$this->vci = isset($json['vci']) ? $json['vci'] : null;
$this->vci = Utils::returnValueIfExists($json, 'vci');
$this->setTransactionStatusFields($json);
}

Expand Down
8 changes: 0 additions & 8 deletions src/TransaccionCompleta/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace Transbank\TransaccionCompleta;

use Transbank\TransaccionCompleta\Responses\DeferredCaptureHistoryResponse;
use Transbank\TransaccionCompleta\Responses\IncreaseAmountResponse;
use Transbank\TransaccionCompleta\Responses\IncreaseAuthorizationDateResponse;
use Transbank\TransaccionCompleta\Responses\ReversePreAuthorizedAmountResponse;
use Transbank\TransaccionCompleta\Exceptions\TransactionCaptureException;
use Transbank\TransaccionCompleta\Exceptions\TransactionCommitException;
use Transbank\TransaccionCompleta\Exceptions\TransactionCreateException;
Expand All @@ -18,10 +14,6 @@
use Transbank\TransaccionCompleta\Responses\TransactionRefundResponse;
use Transbank\Utils\InteractsWithWebpayApi;
use Transbank\Webpay\Exceptions\WebpayRequestException;
use Transbank\Webpay\Exceptions\DeferredCaptureHistoryException;
use Transbank\Webpay\Exceptions\IncreaseAmountException;
use Transbank\Webpay\Exceptions\IncreaseAuthorizationDateException;
use Transbank\Webpay\Exceptions\ReversePreAuthorizedAmountException;
use Transbank\Webpay\Options;

/**
Expand Down
28 changes: 14 additions & 14 deletions src/Utils/HasTransactionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,20 @@ public function getAccountingDate()
*/
public function setTransactionStatusFields($json)
{
$this->amount = isset($json['amount']) ? $json['amount'] : null;
$this->status = isset($json['status']) ? $json['status'] : null;
$this->buyOrder = isset($json['buy_order']) ? $json['buy_order'] : null;
$this->sessionId = isset($json['session_id']) ? $json['session_id'] : null;
$this->cardDetail = isset($json['card_detail']) ? $json['card_detail'] : null;
$this->cardNumber = isset($json['card_detail']['card_number']) ? $json['card_detail']['card_number'] : null;
$this->accountingDate = isset($json['accounting_date']) ? $json['accounting_date'] : null;
$this->transactionDate = isset($json['transaction_date']) ? $json['transaction_date'] : null;
$this->authorizationCode = isset($json['authorization_code']) ? $json['authorization_code'] : null;
$this->paymentTypeCode = isset($json['payment_type_code']) ? $json['payment_type_code'] : null;
$this->responseCode = isset($json['response_code']) ? $json['response_code'] : null;
$this->installmentsAmount = isset($json['installments_amount']) ? $json['installments_amount'] : null;
$this->installmentsNumber = isset($json['installments_number']) ? $json['installments_number'] : null;
$this->balance = isset($json['balance']) ? $json['balance'] : null;
$this->amount = Utils::returnValueIfExists($json, 'amount');
$this->status = Utils::returnValueIfExists($json, 'status');
$this->buyOrder = Utils::returnValueIfExists($json, 'buy_order');
$this->sessionId = Utils::returnValueIfExists($json, 'session_id');
$this->cardDetail = Utils::returnValueIfExists($json, 'card_detail');
$this->cardNumber = Utils::returnValueIfExists($this->cardDetail, 'card_number');
$this->accountingDate = Utils::returnValueIfExists($json, 'accounting_date');
$this->transactionDate = Utils::returnValueIfExists($json, 'transaction_date');
$this->authorizationCode = Utils::returnValueIfExists($json, 'authorization_code');
$this->paymentTypeCode = Utils::returnValueIfExists($json, 'payment_type_code');
$this->responseCode = Utils::returnValueIfExists($json, 'response_code');
$this->installmentsAmount = Utils::returnValueIfExists($json, 'installments_amount');
$this->installmentsNumber = Utils::returnValueIfExists($json, 'installments_number');
$this->balance = Utils::returnValueIfExists($json, 'balance');

}

Expand Down
4 changes: 3 additions & 1 deletion src/Webpay/Modal/Responses/TransactionCreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Transbank\Webpay\Modal\Responses;

use Transbank\Utils\Utils;

class TransactionCreateResponse
{
/**
Expand All @@ -11,7 +13,7 @@ class TransactionCreateResponse

public function __construct(array $json)
{
$this->token = $json['token'];
$this->token = Utils::returnValueIfExists($json, 'token');
}

/**
Expand Down
Loading
Loading