Navigation Menu

Skip to content

Commit

Permalink
Throw exception instead of returning error array in PaymentRedirect
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed Jun 20, 2020
1 parent e95d469 commit 73159da
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/Controller/Component/EpsComponent.php
Expand Up @@ -12,6 +12,7 @@

use at\externet\eps_bank_transfer;

use EpsBankTransfer\Exceptions\EpsAnswerException;
use EpsBankTransfer\Plugin;
class EpsComponent extends Component
{
Expand Down Expand Up @@ -101,8 +102,8 @@ public function GetBanksArray($invalidateCache = false, $config = 'default')
* @throws \XmlValidationException when the returned BankResponseDetails does not validate against XSD
* @throws \SocketException when communication with SO fails
* @throws \UnexpectedValueException when using security suffix without security seed
* @return string BankResponseDetails
* @return array Error info array (ErrorCode, ErrorMsg) from the BankResponseDetails
* @throws \EpsBankTransfer\Exceptions\EpsAnswerException when BankResponseDetails contains an error
* @return returnvalue from Controller::redirect
*/
public function PaymentRedirect($remittanceIdentifier, $TransactionOkUrl, $TransactionNokUrl, $bic = null, $expirationMinutes = null)
{
Expand Down Expand Up @@ -154,10 +155,7 @@ public function PaymentRedirect($remittanceIdentifier, $TransactionOkUrl, $Trans
$errorCode = '' . $errorDetails->ErrorCode;
$errorMsg = '' . $errorDetails->ErrorMsg;
Plugin::WriteLog("FAILED: " . $logPrefix . ' Error ' . $errorCode . ' ' . $errorMsg);
return array(
'ErrorCode' => $errorCode,
'ErrorMsg' => $errorMsg
);
throw new EpsAnswerException($errorCode, $errorMsg);
}

Plugin::WriteLog("SUCCESS: " . $logPrefix);
Expand Down Expand Up @@ -224,7 +222,7 @@ public function HandleConfirmationUrl($eRemittanceIdentifier, $rawPostStream = '

$testMode = !empty($config['TestMode']);
try {
Plugin::GetSoCommunicator()->HandleConfirmationUrl(
Plugin::GetSoCommunicator($testMode)->HandleConfirmationUrl(
$confirmationCallbackWrapper,
$vitalityCheckCallbackWrapper,
$rawPostStream,
Expand Down
25 changes: 25 additions & 0 deletions src/Exceptions/EpsAnswerException.php
@@ -0,0 +1,25 @@
<?php

namespace EpsBankTransfer\Exceptions;

class EpsAnswerException extends \Exception
{
public $ErrorCode;
public $ErrorMsg;

public function __construct($errorCode, $errorMsg)
{
parent::__construct($errorMsg);
$this->ErrorCode = $errorCode;
$this->ErrorMsg = $errorMsg;
}

public function ToArray()
{
return
[
'ErrorCode' => $this->ErrorCode,
'ErrorMsg' => $this->ErrorMsg
];
}
}
9 changes: 7 additions & 2 deletions tests/TestCase/Controller/Component/EpsComponentTest.php
Expand Up @@ -202,9 +202,14 @@ public function testPaymentRedirectErrorResponse()
Plugin::GetSoCommunicator()->expects($this->once())
->method('SendTransferInitiatorDetails')
->will($this->returnValue(eps_bank_transfer\BaseTest::GetEpsData('BankResponseDetails004.xml')));
$actual = $this->Eps->PaymentRedirect('1234567890ABCDEFG', null, null);
$exception = null;
try {
$this->Eps->PaymentRedirect('1234567890ABCDEFG', null, null);
} catch (\EpsBankTransfer\Exceptions\EpsAnswerException $th) {
$exception = $th;
}
$expected = array('ErrorCode' => '004', 'ErrorMsg' => 'merchant not found!');
$this->assertEquals($expected, $actual);
$this->assertEquals($expected, $exception->ToArray());
}

public function testPaymentRedirectSuccess()
Expand Down

0 comments on commit 73159da

Please sign in to comment.