From 6473c2e344cef84d09ae254f067fcfc131080be8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 19 Jun 2020 07:14:12 +0000 Subject: [PATCH] Add getPaymentMethods and getCancelReason API calls to rider API. Add phone_landline to the JO responses. #428 --- config/routes/cmb_rider_api.yaml | 10 ++++ src/Controller/CMBRAPIController.php | 48 +++++++++++++++++++ src/Ramcar/CMBCancelReason.php | 22 +++++++++ .../RiderAPIHandler/CMBRiderAPIHandler.php | 47 ++++++++++++++++-- 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 src/Ramcar/CMBCancelReason.php diff --git a/config/routes/cmb_rider_api.yaml b/config/routes/cmb_rider_api.yaml index cb291bef..77942ca2 100644 --- a/config/routes/cmb_rider_api.yaml +++ b/config/routes/cmb_rider_api.yaml @@ -139,3 +139,13 @@ cmb_rapi_jo_ongoing: path: /cmbrapi/joongoing controller: App\Controller\CMBRAPIController::getOngoingJobOrder methods: [GET] + +cmb_rapi_payment_methods: + path: /cmbrapi/paymentmethods + controller: App\Controller\CMBRAPIController::getPaymentMethods + methods: [GET] + +cmb_rapi_cancel_reasons: + path: /cmbrapi/cancelreasons + controller: App\Controller\CMBRAPIController::getCancelReasons + methods: [GET] diff --git a/src/Controller/CMBRAPIController.php b/src/Controller/CMBRAPIController.php index 30d70ed0..328b7952 100644 --- a/src/Controller/CMBRAPIController.php +++ b/src/Controller/CMBRAPIController.php @@ -691,4 +691,52 @@ class CMBRAPIController extends Controller return $res->getReturnResponse(); } + public function getPaymentMethods(Request $req, RiderAPIHandlerInterface $rapi_handler) + { + $res = new NewAPIResult(); + + $data = $rapi_handler->getPaymentMethods($req); + + if (isset($data['error'])) + { + $message = $data['error']; + $title = $data['title']; + + $res->setError(true) + ->setErrorTitle($title) + ->setErrorMessage($message); + } + else + { + $res->setData($data); + } + + // response + return $res->getReturnResponse(); + } + + public function getCancelReasons(Request $req, RiderAPIHandlerInterface $rapi_handler) + { + $res = new NewAPIResult(); + + $data = $rapi_handler->getCancelReasons($req); + + if (isset($data['error'])) + { + $message = $data['error']; + $title = $data['title']; + + $res->setError(true) + ->setErrorTitle($title) + ->setErrorMessage($message); + } + else + { + $res->setData($data); + } + + // response + return $res->getReturnResponse(); + } + } diff --git a/src/Ramcar/CMBCancelReason.php b/src/Ramcar/CMBCancelReason.php new file mode 100644 index 00000000..b681a40a --- /dev/null +++ b/src/Ramcar/CMBCancelReason.php @@ -0,0 +1,22 @@ + 'Accident', + 'breakdown' => 'Breakdown', + 'fuel_runout' => 'Fuel Runout', + 'wrong_battery_size' => 'Wrong Battery Size', + 'customer_cancel' => 'Cancelled by Customer', + 'others' => 'Others' + ]; +} diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 22d3dc34..f82b6198 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -11,8 +11,9 @@ use App\Ramcar\TradeInType; use App\Ramcar\JOStatus; use App\Ramcar\CMBJOEventType; use App\Ramcar\InvoiceStatus; -use App\Ramcar\ModeOfPayment; +use App\Ramcar\CMBModeOfPayment; use App\Ramcar\InvoiceCriteria; +use App\Ramcar\CMBCancelReason; use App\Service\RiderAPIHandlerInterface; use App\Service\RedisClientProvider; @@ -426,6 +427,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface 'first_name' => $cust->getFirstName(), 'last_name' => $cust->getLastName(), 'phone_mobile' => $this->country_code . $cust->getPhoneMobile(), + 'phone_landline' => $this->country_code . $cust->getPhoneLandline(), ], 'vehicle' => [ 'manufacturer' => $v->getManufacturer()->getName(), @@ -563,6 +565,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface 'first_name' => $cust->getFirstName(), 'last_name' => $cust->getLastName(), 'phone_mobile' => $this->country_code . $cust->getPhoneMobile(), + 'phone_landline' => $this->country_code . $cust->getPhoneLandline(), ], 'vehicle' => [ 'manufacturer' => $v->getManufacturer()->getName(), @@ -673,6 +676,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface 'first_name' => $cust->getFirstName(), 'last_name' => $cust->getLastName(), 'phone_mobile' => $this->country_code . $cust->getPhoneMobile(), + 'phone_landline' => $this->country_code . $cust->getPhoneLandline(), ], 'vehicle' => [ 'manufacturer' => $v->getManufacturer()->getName(), @@ -1120,8 +1124,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // check mode of payment $mode = $req->request->get('mode_of_payment'); - if (!ModeOfPayment::validate($mode)) - $mode = ModeOfPayment::CASH; + if (!CMBModeOfPayment::validate($mode)) + $mode = CMBModeOfPayment::CASH; $jo->setModeOfPayment($mode); // generate new invoice @@ -1745,6 +1749,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface 'first_name' => $cust->getFirstName(), 'last_name' => $cust->getLastName(), 'phone_mobile' => $this->country_code . $cust->getPhoneMobile(), + 'phone_landline' => $this->country_code . $cust->getPhoneLandline(), ], 'vehicle' => [ 'manufacturer' => $v->getManufacturer()->getName(), @@ -1778,6 +1783,42 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + public function getPaymentMethods(Request $req) + { + $required_params = []; + $data = $this->checkParamsAndKey($req, $required_params); + if (isset($data['error'])) + { + $data['title'] = 'Failed Get Payment Methods'; + return $data; + } + + $data = [ + 'payment_methods' => CMBModeOfPayment::getCollection(), + ]; + + return $data; + + } + + public function getCancelReasons(Request $req) + { + $required_params = []; + $data = $this->checkParamsAndKey($req, $required_params); + if (isset($data['error'])) + { + $data['title'] = 'Failed Get Cancel Reasons'; + return $data; + } + + $data = [ + 'cancel_reasons' => CMBCancelReason::getCollection(), + ]; + + return $data; + + } + protected function checkMissingParameters(Request $req, $params = []) { $missing = [];