From feb44618127c2ef26ef556a3692db1962074d1b6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 28 Jun 2023 09:57:03 +1000 Subject: [PATCH] improve error handling with EWay --- app/PaymentDrivers/Eway/CreditCard.php | 36 +++++++------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/app/PaymentDrivers/Eway/CreditCard.php b/app/PaymentDrivers/Eway/CreditCard.php index f93057719b34..969aa3ec670b 100644 --- a/app/PaymentDrivers/Eway/CreditCard.php +++ b/app/PaymentDrivers/Eway/CreditCard.php @@ -70,12 +70,17 @@ class CreditCard $response = $this->eway_driver->init()->eway->createCustomer(\Eway\Rapid\Enum\ApiMethod::DIRECT, $transaction); - $response_status = ErrorCode::getStatus($response->ResponseMessage); + if(property_exists($response, 'ResponseMessage')) + $response_status = ErrorCode::getStatus($response->ResponseMessage); if (! $response_status['success']) { + $this->eway_driver->sendFailureMail($response_status['message']); - throw new PaymentFailed($response_status['message'], 400); + $this->logResponse($response); + + + throw new PaymentFailed($response_status['message'] ?? 'Unknown response from gateway, please contact you merchant.', 400); } //success @@ -94,6 +99,8 @@ class CreditCard $token = $this->eway_driver->storeGatewayToken($cgt, []); + $this->logResponse($response); + return $token; } @@ -135,7 +142,7 @@ class CreditCard $amount = array_sum(array_column($this->eway_driver->payment_hash->invoices(), 'amount')) + $this->eway_driver->payment_hash->fee_total; - $description = "Invoices: {$invoice_numbers} for {$amount} for client {$this->eway_driver->client->present()->name()}"; + // $description = "Invoices: {$invoice_numbers} for {$amount} for client {$this->eway_driver->client->present()->name()}"; $transaction = [ 'Payment' => [ @@ -152,29 +159,6 @@ class CreditCard $this->logResponse($response); - // if(!$response || !property_exists($response, 'ResponseMessage')) - // throw new PaymentFailed('The gateway did not return a valid response. Please check your gateway credentials.', 400); - - // $response_status = ErrorCode::getStatus($response->ResponseMessage); - - // if(!$response_status['success']){ - - // 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 {