Add function to transform ClientData into the format required by insurance. Modify test command. #727

This commit is contained in:
Korina Cordero 2023-01-11 07:55:11 +00:00
parent 8d2ac35c09
commit 0675637b52
3 changed files with 84 additions and 46 deletions

View file

@ -9,6 +9,8 @@ use Symfony\Component\Console\Output\OutputInterface;
use App\Service\InsuranceConnector; use App\Service\InsuranceConnector;
use App\Insurance\ClientData;
class TestInsuranceConnectorCommand extends Command class TestInsuranceConnectorCommand extends Command
{ {
protected $insurance; protected $insurance;
@ -29,43 +31,42 @@ class TestInsuranceConnectorCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$client_info = [ $client_data = new ClientData();
'client_type' => 'I',
'first_name' => '',
'middle_name' => 'Resq',
'surname' => 'Customer',
'corporate_name' => 'Customer, Test Resq'
];
$client_contact_info = [ // set client info part
'address_number' => '112', $client_data->setClientType('I')
'address_street' => 'Test Street', ->setFirstName('Test')
'address_building' => 'Test Building', ->setMiddleName('Resq')
'address_barangay' => 'Legaspi Village', ->setSurname('Customer')
'address_city' => 'Makati City', ->setCorporateName('Customer, Test Resq');
'address_province' => 'Metro Manila',
'zipcode' => '1200',
'mobile_number' => '09171234567',
'email_address' => 'test.resq@gmail.com'
];
$car_info = [ // set the client contact info part
'make' => 'HYUNDAI', $client_data->setAddressNumber('113')
'model' => 'ACCENT', ->setAddressStreet('Test Street')
'series' => '1.4 A/T', ->setAddressBuilding('Test Building')
'color' => 'PHANTOM BLACK', ->setAddressBarangay('Legaspi Village')
'plate_number' => 'ABC1234', ->setAddressCity('Makati City')
'mv_file_number' => '123456789012345', ->setAddressProvince('Metro Manila')
'motor_number' => 'E31TE-0075268', ->setZipcode('1200')
'serial_chasis' => 'PA0SEF210K0075701', ->setMobileNumber('09171234567')
'year_model' => '2020', ->setEmailAddress('test.resq@gmail.com');
'mv_type_id' => 1,
'body_type' => 'SEDAN',
'is_public' => false,
'line' => 'pcoc'
];
$result = $this->insurance->createApplication($client_info, $client_contact_info, $car_info); // set the car info part
$client_data->setMake('HYUNDAI')
->setModel('ACCENT')
->setSeries('1.4 A/T')
->setColor('PHANTOM BLACK')
->setPlateNumber('ABC1234')
->setMvFileNumber('123456789012345')
->setMotorNumber('E31TE-0075268')
->setSerialChassis('PA0SEF210K0075701')
->setYearModel('2020')
->setMvTypeID(1)
->setBodyType('SEDAN')
->setLine('pcoc')
->setPublic(false);
$result = $this->insurance->processApplication($client_data);
error_log(json_encode($result)); error_log(json_encode($result));

View file

@ -147,13 +147,13 @@ class ClientData
return $this->address_street; return $this->address_street;
} }
public function setAdddressBuilding($address_building) public function setAddressBuilding($address_building)
{ {
$this->address_building = $address_building; $this->address_building = $address_building;
return $this; return $this;
} }
public function getAdddressBuilding() public function getAddressBuilding()
{ {
return $this->address_building; return $this->address_building;
} }

View file

@ -24,7 +24,7 @@ class InsuranceConnector
$this->token = $token; $this->token = $token;
} }
public function createClientData(ClientData $client_data) public function processApplication(ClientData $client_data)
{ {
// transform ClientData into the format needed for insurance application // transform ClientData into the format needed for insurance application
$client_info = [ $client_info = [
@ -43,13 +43,13 @@ class InsuranceConnector
'address_city' => $client_data->getAddressCity(), 'address_city' => $client_data->getAddressCity(),
'address_province' => $client_data->getAddressProvince(), 'address_province' => $client_data->getAddressProvince(),
'zipcode' => $client_data->getZipcode(), 'zipcode' => $client_data->getZipcode(),
'mobile_number' => $cilent_data->getMobileNumber(), 'mobile_number' => $client_data->getMobileNumber(),
'email_address' => $client_data->getEmailAddress(), 'email_address' => $client_data->getEmailAddress(),
]; ];
$car_info = [ $car_info = [
'make' => $client_data->getMake(), 'make' => $client_data->getMake(),
'model' => $client_data->getModel(),, 'model' => $client_data->getModel(),
'series' => $client_data->getSeries(), 'series' => $client_data->getSeries(),
'color' => $client_data->getColor(), 'color' => $client_data->getColor(),
'plate_number' => $client_data->getPlateNumber(), 'plate_number' => $client_data->getPlateNumber(),
@ -69,12 +69,17 @@ class InsuranceConnector
'car_info' => $car_info, 'car_info' => $car_info,
]; ];
$result = $this->createApplication($app_data); $result = $this->sendApplication($app_data);
// TODO: error handling $app_result = json_decode($result, true);
// process response received from insurance
$res = $this->checkApplicationResult($app_result);
return $res;
} }
protected function createApplication($body) protected function sendApplication($body)
{ {
$body_text = json_encode($body); $body_text = json_encode($body);
@ -83,13 +88,45 @@ class InsuranceConnector
$res = $this->curlPost('api/v1/ctpl/applications', $body_text, $token); $res = $this->curlPost('api/v1/ctpl/applications', $body_text, $token);
$app_res = json_decode($res, true); return $res;
}
// check result protected function checkApplicationResult($app_result)
if ($app_res == null) {
if ($app_result == null)
{
// insurance api returned an empty json
return []; return [];
}
return $app_res; // check if message is set
$message = '';
if (isset($app_result['message']))
$message = $app_result['message'];
// check if id is set
$id = '';
if (isset($app_result['id']))
$id = $app_result['id'];
// check if status is set, meaning, there's an error
$status = '';
if (isset($app_result['status']))
$status = 'error';
else
$status = 'success';
$data = [
'id' => $id
];
$processed_result = [
'status' => $status,
'message' => $message,
'data' => $data,
];
return $processed_result;
} }
protected function generateAuthToken($username, $password) protected function generateAuthToken($username, $password)