From 38262151e8d564ca0780932ad76117003fe86ffe Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Wed, 11 Oct 2023 17:06:37 +0800 Subject: [PATCH] Add dates to vehicle info insurance info #761 --- .../CustomerAppAPI/VehicleController.php | 5 +++++ src/Controller/InsuranceController.php | 7 +++++++ src/Entity/InsuranceApplication.php | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/Controller/CustomerAppAPI/VehicleController.php b/src/Controller/CustomerAppAPI/VehicleController.php index 446f43b3..24d28a4f 100644 --- a/src/Controller/CustomerAppAPI/VehicleController.php +++ b/src/Controller/CustomerAppAPI/VehicleController.php @@ -323,6 +323,8 @@ class VehicleController extends ApiController $iobj = $cv->getLatestInsuranceApplication(); if (!empty($iobj)) { $gt = $iobj->getGatewayTransaction(); + $date_complete = $iobj->getDateComplete(); + $date_expire = $iobj->getDateExpire(); $insurance = [ 'id' => $iobj->getID(), @@ -332,6 +334,9 @@ class VehicleController extends ApiController 'checkout_url' => $gt->getMetadata()['checkout_url'], 'transaction_status' => $gt->getStatus(), 'premium_amount' => (string)bcdiv($gt->getAmount(), 100), // NOTE: hard expressing as string so it's consistent + 'date_submit' => $iobj->getDateSubmit()->format('Y-m-d H:i:s'), + 'date_complete' => $date_complete ? $date_complete->format('Y-m-d H:i:s') : null, + 'date_expire' => $date_expire ? $date_expire->format('Y-m-d H:i:s') : null, ]; // get information changelog diff --git a/src/Controller/InsuranceController.php b/src/Controller/InsuranceController.php index 91b1b855..c4fd4800 100644 --- a/src/Controller/InsuranceController.php +++ b/src/Controller/InsuranceController.php @@ -73,9 +73,16 @@ class InsuranceController extends Controller { $obj = $this->getApplication($payload['id']); + $now = new DateTime; + + // TODO: replacing this with actual callback response once provided + $expiry = $now->modify('+1 year'); + if (!empty($obj)) { // mark as completed $obj->setStatus(InsuranceApplicationStatus::COMPLETED); + $obj->setDateComplete($now); + $obj->setDateExpire($expiry); $obj->setCOC($payload['coc_url']); $this->em->flush(); diff --git a/src/Entity/InsuranceApplication.php b/src/Entity/InsuranceApplication.php index c9c19bef..3887e259 100644 --- a/src/Entity/InsuranceApplication.php +++ b/src/Entity/InsuranceApplication.php @@ -74,6 +74,12 @@ class InsuranceApplication */ protected $date_complete; + // date the application is set to expire + /** + * @ORM\Column(type="datetime", nullable=true) + */ + protected $date_expire; + // external transaction id /** * @ORM\Column(type="string", length=255, nullable=true) @@ -91,6 +97,7 @@ class InsuranceApplication $this->date_submit = new DateTime(); $this->date_pay = null; $this->date_complete = null; + $this->date_expire = null; $this->metadata = []; } @@ -185,6 +192,17 @@ class InsuranceApplication return $this->date_complete; } + public function setDateExpire(DateTime $date) + { + $this->date_expire = $date; + return $this; + } + + public function getDateExpire() + { + return $this->date_expire; + } + public function setExtTransactionId($transaction_id) { $this->ext_transaction_id = $transaction_id;