Merge branch '428-cmb-new-api-calls' into '424-cmb-release'

Add getPaymentMethods and getCancelReason API calls to rider API. Add...

See merge request jankstudio/resq!495
This commit is contained in:
Korina Cordero 2020-06-19 07:16:50 +00:00
commit fed9c95449
4 changed files with 124 additions and 3 deletions

View file

@ -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]

View file

@ -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();
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace App\Ramcar;
class CMBCancelReason extends NameValue
{
const ACCIDENT = 'accident';
const BREAKDOWN = 'breakdown';
const FUEL_RUNOUT = 'fuel_runout';
const WRONG_BATTERY_SIZE = 'wrong_battery_size';
const CUSTOMER_CANCEL = 'customer_cancel';
const OTHERS = 'others';
const COLLECTION = [
'accident' => 'Accident',
'breakdown' => 'Breakdown',
'fuel_runout' => 'Fuel Runout',
'wrong_battery_size' => 'Wrong Battery Size',
'customer_cancel' => 'Cancelled by Customer',
'others' => 'Others'
];
}

View file

@ -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 = [];