Skip to content

Commit

Permalink
Merge pull request #272 from TransbankDevelopers/fix/kiuwan-bugs-03
Browse files Browse the repository at this point in the history
fix: kiuwan bugs 03
  • Loading branch information
mvarlic authored Dec 6, 2023
2 parents c21da33 + dbbc4a4 commit 7ebe156
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 132 deletions.
21 changes: 18 additions & 3 deletions src/Patpass/PatpassByWebpay/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public function create($buyOrder, $sessionId, $amount, $returnUrl, $details)
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionCreateException::raise($exception);
throw new TransactionCreateException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionCreateResponse($response);
Expand All @@ -50,7 +55,12 @@ public function commit($token)
try {
$response = $this->sendRequest('PUT', $endpoint.'/'.$token, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionCommitException::raise($exception);
throw new TransactionCommitException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionCommitResponse($response);
Expand All @@ -64,7 +74,12 @@ public function status($token)
try {
$response = $this->sendRequest('GET', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionStatusException::raise($exception);
throw new TransactionStatusException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionStatusResponse($response);
Expand Down
14 changes: 12 additions & 2 deletions src/Patpass/PatpassComercio/Inscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public function start(
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw InscriptionStartException::raise($exception);
throw new InscriptionStartException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new InscriptionStartResponse($response);
Expand All @@ -111,7 +116,12 @@ public function status($token)
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw InscriptionStatusException::raise($exception);
throw new InscriptionStatusException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new InscriptionStatusResponse($response);
Expand Down
42 changes: 36 additions & 6 deletions src/TransaccionCompleta/MallTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public function create(
try {
$response = $this->sendRequest('POST', static::ENDPOINT_CREATE, $payload);
} catch (WebpayRequestException $exception) {
throw MallTransactionCreateException::raise($exception);
throw new MallTransactionCreateException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new MallTransactionCreateResponse($response);
Expand All @@ -80,7 +85,12 @@ public function installments(
return new MallTransactionInstallmentsResponse($response);
}, $details);
} catch (WebpayRequestException $exception) {
throw TransactionInstallmentsException::raise($exception);
throw new TransactionInstallmentsException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}
}

Expand All @@ -97,7 +107,12 @@ public function commit(
try {
$response = $this->sendRequest('PUT', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw MallTransactionCommitException::raise($exception);
throw new MallTransactionCommitException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new MallTransactionCommitResponse($response);
Expand All @@ -120,7 +135,12 @@ public function refund(
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw MallTransactionRefundException::raise($exception);
throw new MallTransactionRefundException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new MallTransactionRefundResponse($response);
Expand All @@ -133,7 +153,12 @@ public function status($token)
try {
$response = $this->sendRequest('GET', $endpoint, null);
} catch (WebpayRequestException $exception) {
throw MallTransactionStatusException::raise($exception);
throw new MallTransactionStatusException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new MallTransactionStatusResponse($response);
Expand Down Expand Up @@ -165,7 +190,12 @@ public function capture($token, $commerceCode, $buyOrder, $authorizationCode, $c
try {
$response = $this->sendRequest('PUT', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw MallTransactionCaptureException::raise($exception);
throw new MallTransactionCaptureException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new Responses\MallTransactionCaptureResponse($response);
Expand Down
42 changes: 36 additions & 6 deletions src/TransaccionCompleta/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public function create(
try {
$response = $this->sendRequest('POST', static::ENDPOINT_CREATE, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionCreateException::raise($exception);
throw new TransactionCreateException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionCreateResponse($response);
Expand Down Expand Up @@ -91,7 +96,12 @@ public function installments(
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionInstallmentsException::raise($exception);
throw new TransactionInstallmentsException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionInstallmentsResponse($response);
Expand Down Expand Up @@ -125,7 +135,12 @@ public function commit(
try {
$response = $this->sendRequest('PUT', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionCommitException::raise($exception);
throw new TransactionCommitException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionCommitResponse($response);
Expand All @@ -151,7 +166,12 @@ public function refund($token, $amount)
try {
$response = $this->sendRequest('POST', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionRefundException::raise($exception);
throw new TransactionRefundException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new TransactionRefundResponse($response);
Expand All @@ -172,7 +192,12 @@ public function status($token)
try {
$response = $this->sendRequest('GET', $endpoint, null);
} catch (WebpayRequestException $exception) {
throw TransactionStatusException::raise($exception);
throw new TransactionStatusException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new \Transbank\TransaccionCompleta\Responses\TransactionStatusResponse($response);
Expand Down Expand Up @@ -202,7 +227,12 @@ public function capture($token, $buyOrder, $authorizationCode, $captureAmount)
try {
$response = $this->sendRequest('PUT', $endpoint, $payload);
} catch (WebpayRequestException $exception) {
throw TransactionCaptureException::raise($exception);
throw new TransactionCaptureException($exception->getMessage(),
$exception->getTransbankErrorMessage(),
$exception->getHttpCode(),
$exception->getFailedRequest(),
$exception
);
}

return new Responses\TransactionCaptureResponse($response);
Expand Down
8 changes: 0 additions & 8 deletions src/Utils/InteractsWithWebpayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public function sendRequest($method, $endpoint, $payload = [])

/**
* @param Options $options
*
* @return $this
*/
public function loadOptions(Options $options = null)
{
Expand All @@ -72,8 +70,6 @@ public function loadOptions(Options $options = null)
}

$this->setOptions($options);

return $this;
}

/**
Expand All @@ -90,8 +86,6 @@ public function getOptions()
public function setOptions(Options $options)
{
$this->options = $options;

return $this;
}

/**
Expand All @@ -108,8 +102,6 @@ public function getRequestService()
public function setRequestService(RequestService $requestService = null)
{
$this->requestService = $requestService;

return $this;
}

/**
Expand Down
28 changes: 6 additions & 22 deletions src/Webpay/Exceptions/WebpayRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ public function __construct(
$message,
$tbkErrorMessage = null,
$httpCode = null,
TransbankApiRequest $failedRequest = null
TransbankApiRequest $failedRequest = null,
\Exception $previous = null
) {
$theMessage = isset($tbkErrorMessage) ? $tbkErrorMessage : $message;
if ($failedRequest !== null) {
$theMessage = $this->getExceptionMessage($message, $tbkErrorMessage, $httpCode, $failedRequest);
$theMessage = $this->getExceptionMessage($message, $tbkErrorMessage, $httpCode);
}

$this->message = $theMessage;
$this->transbankErrorMessage = $tbkErrorMessage;
$this->httpCode = $httpCode;
$this->failedRequest = $failedRequest;

parent::__construct($theMessage, $httpCode);
parent::__construct($theMessage, $httpCode, $previous);
}

/**
Expand All @@ -74,7 +75,7 @@ public function getTransbankErrorMessage()
public static function raise(WebpayRequestException $exception)
{
return new static($exception->getMessage(), $exception->getTransbankErrorMessage(), $exception->getHttpCode(),
$exception->getFailedRequest());
$exception->getFailedRequest(), $exception);
}

/**
Expand All @@ -97,38 +98,21 @@ public function getFailedRequest()
* @param $message
* @param $tbkErrorMessage
* @param $httpCode
* @param TransbankApiRequest|null $failedRequestCapturedData
*
* @return string
*/
protected function getExceptionMessage(
$message,
$tbkErrorMessage,
$httpCode,
TransbankApiRequest $failedRequestCapturedData = null
$httpCode
) {
if (!$tbkErrorMessage) {
$theMessage = $message;
} else {
$theMessage = 'API Response: "'.$tbkErrorMessage.'" ['.$httpCode.'] - '.static::$defaultMessage;
}

if ($possibleCause = $this->getPossibleCause($httpCode, $tbkErrorMessage, $failedRequestCapturedData)) {
return $theMessage.' - '.$possibleCause;
}

return $theMessage;
}

/**
* @param $httpCode
* @param $tbkErrorMessage
* @param TransbankApiRequest|null $failedRequestCapturedData
*
* @return null
*/
protected function getPossibleCause($httpCode, $tbkErrorMessage, TransbankApiRequest $failedRequestCapturedData = null)
{
return null;
}
}
Loading

0 comments on commit 7ebe156

Please sign in to comment.