From 3ed65e7fc6095cd1c50f492ea51e6133106929e3 Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Thu, 24 Oct 2024 04:05:20 +0800 Subject: [PATCH] Move all points logic from paymongo listener to gateway transaction listener #799 --- .../CustomerAppAPI/SubscriptionController.php | 23 +------------------ .../GatewayTransactionListener.php | 2 ++ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/src/Controller/CustomerAppAPI/SubscriptionController.php b/src/Controller/CustomerAppAPI/SubscriptionController.php index 08f9c9a5..d6efb6f8 100644 --- a/src/Controller/CustomerAppAPI/SubscriptionController.php +++ b/src/Controller/CustomerAppAPI/SubscriptionController.php @@ -13,8 +13,6 @@ use App\Entity\CustomerVehicle; use App\Ramcar\SubscriptionStatus; use App\Entity\GatewayTransaction; use App\Ramcar\TransactionStatus; -use App\Service\FCMSender; -use App\Service\LoyaltyConnector; use DateTime; class SubscriptionController extends ApiController @@ -205,7 +203,7 @@ class SubscriptionController extends ApiController ]); } - public function finalizeSubscription(Request $req, $id, PayMongoConnector $pm, LoyaltyConnector $lc, FCMSender $fcmclient) + public function finalizeSubscription(Request $req, $id, PayMongoConnector $pm) { // check requirements $validity = $this->validateRequest($req); @@ -228,7 +226,6 @@ class SubscriptionController extends ApiController ]); if (empty($sub_obj)) { - error_log("no sub found!"); return new ApiResponse(false, 'Invalid subscription provided.'); } @@ -281,24 +278,6 @@ class SubscriptionController extends ApiController $this->em->flush(); } - - // compute loyalty points to be added - // TODO: get a proper matrix for this. right now we are using a flat multiplier for demo purposes - $points_amount = ($gt->getAmount() / 100) * $this->getParameter('loyalty_php_point_multiplier'); - - // add loyalty points - $points_res = $lc->updatePoints($cust, $points_amount); - if ($points_res['success']) { - // notify the customer that points were added - $fcmclient->sendLoyaltyEvent( - $cust, - "loyalty_fcm_title_add_points", - "loyalty_fcm_body_add_points", - [], - [], - ['%points%' => number_format($points_amount)], - ); - } // response return new ApiResponse(true, '', [ diff --git a/src/EntityListener/GatewayTransactionListener.php b/src/EntityListener/GatewayTransactionListener.php index 67668a6f..1034dcd0 100644 --- a/src/EntityListener/GatewayTransactionListener.php +++ b/src/EntityListener/GatewayTransactionListener.php @@ -48,6 +48,8 @@ class GatewayTransactionListener $prev_value = $field_changes[0] ?? null; $new_value = $field_changes[1] ?? null; + error_log($prev_value . " vs " . $new_value); + // only do something if the status has changed to paid if ($prev_value !== $new_value && $new_value === TransactionStatus::PAID) { // determine if we will add loyalty points for this transaction