Improve error response from eWay gateway

This commit is contained in:
David Bomba 2022-04-19 14:53:19 +10:00
parent 7bbc2b7f9c
commit 6bffa1af10

View File

@ -168,18 +168,56 @@ class CreditCard
$response = $this->eway_driver->init()->eway->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); $response = $this->eway_driver->init()->eway->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);
nlog($response);
$this->logResponse($response); $this->logResponse($response);
$response_status = ErrorCode::getStatus($response->ResponseMessage); // if(!$response || !property_exists($response, 'ResponseMessage'))
// throw new PaymentFailed('The gateway did not return a valid response. Please check your gateway credentials.', 400);
if(!$response_status['success']){ // $response_status = ErrorCode::getStatus($response->ResponseMessage);
$this->eway_driver->sendFailureMail($response_status['message']); // if(!$response_status['success']){
throw new PaymentFailed($response_status['message'], 400); // if($response->getErrors())
// {
// $message = false;
// foreach ($response->getErrors() as $error) {
// $message = \Eway\Rapid::getMessage($error);
// }
// $return_message = $message ?: $response_status['message'];
// }
// $this->eway_driver->sendFailureMail($response_status['message']);
// throw new PaymentFailed($response_status['message'], 400);
// }
if($response->TransactionStatus)
$payment = $this->storePayment($response);
else {
$message = 'Error processing payment.';
if(isset($response->ResponseMessage))
$message .= " Gateway Error Code = {$response->ResponseMessage}";
if($response->getErrors())
{
foreach ($response->getErrors() as $error) {
$message = \Eway\Rapid::getMessage($error);
}
}
$this->eway_driver->sendFailureMail($message);
throw new PaymentFailed($message, 400);
} }
$payment = $this->storePayment($response);
return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]);
@ -257,21 +295,33 @@ class CreditCard
$response = $this->eway_driver->init()->eway->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); $response = $this->eway_driver->init()->eway->createTransaction(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction);
$response_status = ErrorCode::getStatus($response->ResponseMessage); if($response->TransactionStatus){
$this->logResponse($response, true);
$payment = $this->storePayment($response);
}
else {
if(!$response_status['success']){ $message = 'Error processing payment.';
if(isset($response->ResponseMessage))
$message .= " Gateway Error Code = {$response->ResponseMessage}";
if($response->getErrors())
{
foreach ($response->getErrors() as $error) {
$message = \Eway\Rapid::getMessage($error);
}
}
$this->logResponse($response, false); $this->logResponse($response, false);
$this->eway_driver->sendFailureMail($response_status['message']); $this->eway_driver->sendFailureMail($message);
throw new PaymentFailed($response_status['message'], 400); throw new PaymentFailed($message, 400);
} }
$this->logResponse($response, true);
$payment = $this->storePayment($response);
return $payment; return $payment;
} }
} }