From 4f5560f6f7472a757ed71c9a4611ddab1690b7f3 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Sun, 11 Aug 2024 15:05:20 +0800 Subject: [PATCH] Update subscription fee endpoint to be specific to each vehicle model #799 --- config/routes/apiv2.yaml | 2 +- config/services.yaml | 1 - src/Controller/BatterySizeController.php | 2 +- .../CustomerAppAPI/SubscriptionController.php | 24 +++++++++---------- .../CustomerAppAPI/VehicleController.php | 2 +- src/Entity/BatterySize.php | 12 +++++----- templates/battery-size/form.html.twig | 8 +++---- translations/messages.en.yaml | 2 +- 8 files changed, 26 insertions(+), 27 deletions(-) diff --git a/config/routes/apiv2.yaml b/config/routes/apiv2.yaml index 1ceba391..8fef53b4 100644 --- a/config/routes/apiv2.yaml +++ b/config/routes/apiv2.yaml @@ -322,7 +322,7 @@ apiv2_static_content: # subscription apiv2_subscription_fee: - path: /apiv2/subscription/fee + path: /apiv2/subscription/{vid}/fee controller: App\Controller\CustomerAppAPI\SubscriptionController::getRecurringFee methods: [GET] diff --git a/config/services.yaml b/config/services.yaml index 093ecf2d..6e24ee74 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -17,7 +17,6 @@ parameters: ios_app_version: "%env(IOS_APP_VERSION)%" insurance_premiums_banner_url: "%env(INSURANCE_PREMIUMS_BANNER_URL)%" enabled_hub_filters: "%env(ENABLED_HUB_FILTERS)%" - subscription_recurring_fee: "%env(SUBSCRIPTION_RECURRING_FEE)%" subscription_paymongo_public_key: "%env(SUBSCRIPTION_PAYMONGO_PUBLIC_KEY)%" services: diff --git a/src/Controller/BatterySizeController.php b/src/Controller/BatterySizeController.php index 1f428a4d..5af7730e 100644 --- a/src/Controller/BatterySizeController.php +++ b/src/Controller/BatterySizeController.php @@ -131,7 +131,7 @@ class BatterySizeController extends Controller ->setTIPricePremium($req->request->get('tip_premium')) ->setTIPriceOther($req->request->get('tip_other')) ->setTIPriceLazada($req->request->get('tip_lazada')) - ->setSubMSRP($req->request->get('sub_msrp')); + ->setSubRecurringFee($req->request->get('sub_recurring_fee')); } public function addSubmit(Request $req, ValidatorInterface $validator) diff --git a/src/Controller/CustomerAppAPI/SubscriptionController.php b/src/Controller/CustomerAppAPI/SubscriptionController.php index b86b410d..9ef275d1 100644 --- a/src/Controller/CustomerAppAPI/SubscriptionController.php +++ b/src/Controller/CustomerAppAPI/SubscriptionController.php @@ -5,11 +5,11 @@ namespace App\Controller\CustomerAppAPI; use Symfony\Component\HttpFoundation\Request; use Catalyst\ApiBundle\Component\Response as ApiResponse; -use App\Entity\CustomerVehicle; +use App\Entity\Vehicle; class SubscriptionController extends ApiController { - public function getRecurringFee(Request $req, $cv_id) + public function getRecurringFee(Request $req, $vid) { // check requirements $validity = $this->validateRequest($req); @@ -18,22 +18,22 @@ class SubscriptionController extends ApiController return new ApiResponse(false, $validity['error']); } - // get customer vehicle - $cv = $this->em->getRepository(CustomerVehicle::class)->find($cv_id); - - // check if it exists - if ($cv == null) { - return new ApiResponse(false, 'Vehicle does not exist.'); + // get vehicle + $vehicle = $this->em->getRepository(Vehicle::class)->find($vid); + if ($vehicle == null) { + return new ApiResponse(false, 'Invalid vehicle.'); } - // check if it's owned by customer - if ($cv->getCustomer()->getID() != $this->session->getCustomer()->getID()) { - return new ApiResponse(false, 'Invalid vehicle.'); + // get compatible batteries + $batts = $vehicle->getActiveBatteries(); + + if (!empty($batts)) { + $fee = $batts[0]->getSize()->getSubRecurringFee() ?? 0; } // response return new ApiResponse(true, '', [ - 'amount' => $this->getParameter('subscription_recurring_fee'), + 'amount' => $fee, ]); } diff --git a/src/Controller/CustomerAppAPI/VehicleController.php b/src/Controller/CustomerAppAPI/VehicleController.php index 0b5fdc57..c0ce272f 100644 --- a/src/Controller/CustomerAppAPI/VehicleController.php +++ b/src/Controller/CustomerAppAPI/VehicleController.php @@ -393,7 +393,7 @@ class VehicleController extends ApiController // TODO: possibly refactor this bit // if no valid previous JO is found, base the trade-in value on recommended batteries if (!$previous_jo_found) { - $comp_batteries = $cv->getVehicle()->getBatteries(); + $comp_batteries = $cv->getVehicle()->getActiveBatteries(); // get the lowest trade-in value from the list of batteries if (!empty($comp_batteries)) { diff --git a/src/Entity/BatterySize.php b/src/Entity/BatterySize.php index cd79067f..3d7112fc 100644 --- a/src/Entity/BatterySize.php +++ b/src/Entity/BatterySize.php @@ -61,7 +61,7 @@ class BatterySize /** * @ORM\Column(type="decimal", precision=7, scale=2, nullable=true) */ - protected $sub_msrp; + protected $sub_recurring_fee; public function __construct() { @@ -70,7 +70,7 @@ class BatterySize $this->tip_premium = 0; $this->tip_other = 0; $this->tip_lazada = 0; - $this->sub_msrp = 0; + $this->sub_recurring_fee = 0; } public function getID() @@ -156,14 +156,14 @@ class BatterySize return $this->tip_lazada; } - public function setSubMSRP($sub_msrp) + public function setSubRecurringFee($sub_recurring_fee) { - $this->sub_msrp = $sub_msrp; + $this->sub_recurring_fee = $sub_recurring_fee; return $this; } - public function getSubMSRP() + public function getSubRecurringFee() { - return $this->sub_msrp; + return $this->sub_recurring_fee; } } diff --git a/templates/battery-size/form.html.twig b/templates/battery-size/form.html.twig index 44e52e3f..2138c5ab 100644 --- a/templates/battery-size/form.html.twig +++ b/templates/battery-size/form.html.twig @@ -81,12 +81,12 @@
-
diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index bb02c767..6fde186c 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -9,7 +9,7 @@ battery_size_tradein_brand: Trade-in Motolite battery_size_tradein_premium: Trade-in Premium battery_size_tradein_other: Trade-in Other battery_size_tradein_lazada: Trade-in Lazada -battery_Size_sub_msrp: Subscription MSRP +battery_Size_sub_recurring_fee: Subscription Recurring Fee add_cust_vehicle_battery_info: This vehicle is using a Motolite battery jo_title_pdf: Motolite Res-Q Job Order country_code_prefix: '+63'