diff --git a/src/EntityListener/GatewayTransactionListener.php b/src/EntityListener/GatewayTransactionListener.php index c9007aaf..0dd6966d 100644 --- a/src/EntityListener/GatewayTransactionListener.php +++ b/src/EntityListener/GatewayTransactionListener.php @@ -58,17 +58,20 @@ class GatewayTransactionListener 'gateway_transaction' => $gt_obj, ]); - if (!empty($obj)) { + // make sure the object exists and has not been processed yet + if (!empty($obj) && $obj->getStatus === InsuranceApplicationStatus::CREATED) { // mark as paid $obj->setDatePay(new DateTime()); $obj->setStatus(InsuranceApplicationStatus::PAID); $this->em->flush(); - } - // flag on api as paid - $result = $this->ic->tagApplicationPaid($obj->getExtTransactionId()); - if (!$result['success'] || $result['response']['transaction_code'] !== 'GR004') { - error_log("INSURANCE MARK AS PAID FAILED FOR " . $obj->getID() . ": " . $result['error']['message']); + // flag on api as paid + $result = $this->ic->tagApplicationPaid($obj->getExtTransactionId()); + + // something went wrong with insurance api + if (!$result['success'] || $result['response']['transaction_code'] !== 'GR004') { + error_log("INSURANCE MARK AS PAID FAILED FOR " . $obj->getID() . ": " . $result['error']['message']); + } } } }