diff --git a/config/services.yaml b/config/services.yaml index dd3c2d0f..e85c0d86 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -282,3 +282,9 @@ services: App\Service\WarrantySerialLoadLogger: arguments: $em: "@doctrine.orm.entity_manager" + + # FCM sender + App\Service\FCMSender: + arguments: + $server_key: "%env(FCM_SERVER_KEY)%" + $sender_id: "%env(FCM_SENDER_ID)%" diff --git a/src/Command/UpdateUnacceptedJobOrdersCommand.php b/src/Command/UpdateUnacceptedJobOrdersCommand.php index 119e59cc..b7bfeb0c 100644 --- a/src/Command/UpdateUnacceptedJobOrdersCommand.php +++ b/src/Command/UpdateUnacceptedJobOrdersCommand.php @@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManagerInterface; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Entity\JobOrder; use App\Entity\Rider; @@ -24,14 +25,16 @@ class UpdateUnacceptedJobOrdersCommand extends Command // NOTE: for resq2 app protected $mclientv2; + protected $fcmclient; - public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { $this->em = $em; $this->mclient = $mclient; // NOTE: for resq2 app $this->mclientv2 = $mclientv2; + $this->fcmclient = $fcmclient; parent::__construct(); } @@ -50,6 +53,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command // NOTE: for resq2 app $mclientv2 = $this->mclientv2; + $fcmclient = $this->fcmclient; // TODO: get the timeout limit from .env $timeout = 3; @@ -120,6 +124,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); } $rider = $jo->getRider(); diff --git a/src/Controller/CAPI/RiderAppController.php b/src/Controller/CAPI/RiderAppController.php index f3d124c6..1d6db9ac 100644 --- a/src/Controller/CAPI/RiderAppController.php +++ b/src/Controller/CAPI/RiderAppController.php @@ -28,6 +28,7 @@ use App\Service\RedisClientProvider; use App\Service\RiderCache; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\WarrantyHandler; use App\Service\JobOrderHandlerInterface; use App\Service\InvoiceGeneratorInterface; @@ -438,7 +439,7 @@ class RiderAppController extends APIController } - public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function cancelJobOrder(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { $required_params = ['jo_id']; @@ -486,6 +487,7 @@ class RiderAppController extends APIController // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); $data = []; return new APIResponse(true, 'Job order requeued.', $data); @@ -652,7 +654,7 @@ class RiderAppController extends APIController } - public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function arrive(Request $req, EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { $required_params = ['jo_id']; @@ -704,6 +706,7 @@ class RiderAppController extends APIController // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived"); $data = []; return new APIResponse(true, 'Rider arrived at customer location.', $data); @@ -756,7 +759,7 @@ class RiderAppController extends APIController } public function payment(Request $req, EntityManagerInterface $em, JobOrderHandlerInterface $jo_handler, - RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, TranslatorInterface $translator) + RisingTideGateway $rt, WarrantyHandler $wh, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, TranslatorInterface $translator) { $required_params = ['jo_id']; @@ -880,6 +883,7 @@ class RiderAppController extends APIController // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled"); $data = []; return new APIResponse(true, 'Job order paid and fulfilled.', $data); diff --git a/src/Controller/CustomerAppAPI/JobOrderController.php b/src/Controller/CustomerAppAPI/JobOrderController.php index 3c7a8572..4ddb40ee 100644 --- a/src/Controller/CustomerAppAPI/JobOrderController.php +++ b/src/Controller/CustomerAppAPI/JobOrderController.php @@ -9,6 +9,7 @@ use CrEOF\Spatial\PHP\Types\Geometry\Point; use App\Service\InvoiceGeneratorInterface; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\RiderTracker; use App\Service\GeofenceTracker; use App\Service\MapTools; @@ -475,6 +476,7 @@ class JobOrderController extends ApiController MapTools $map_tools, InventoryManager $im, MQTTClientApiv2 $mclientv2, + FCMSender $fcmclient, RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger, HubSelector $hub_select, @@ -841,6 +843,7 @@ class JobOrderController extends ApiController 'event' => 'outlet_assign', ]; $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); $rah->assignJobOrder($jo, $jo->getRider()); } @@ -859,6 +862,7 @@ class JobOrderController extends ApiController 'event' => 'outlet_assign', ]; $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); } $this->em->flush(); @@ -933,6 +937,7 @@ class JobOrderController extends ApiController MapTools $map_tools, InventoryManager $im, MQTTClientApiv2 $mclientv2, + FCMSender $fcmclient, RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger, HubSelector $hub_select, @@ -1185,6 +1190,7 @@ class JobOrderController extends ApiController 'event' => 'outlet_assign', ]; $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); $rah->assignJobOrder($jo, $jo->getRider()); } diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 957cbca6..990b7553 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -22,6 +22,7 @@ use App\Service\GISManagerInterface; use App\Service\MapTools; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Service\InventoryManager; use App\Service\HubSelector; @@ -354,7 +355,7 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id) + public function processingSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id) { $this->denyAccessUnlessGranted('jo_proc.list', null, 'No access.'); @@ -362,7 +363,7 @@ class JobOrderController extends Controller $error_array = []; try { - $error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient, $mclientv2); + $error_array = $jo_handler->dispatchJobOrder($req, $id, $mclient, $mclientv2, $fcmclient); } catch (AccessDeniedHttpException $e) { @@ -421,7 +422,7 @@ class JobOrderController extends Controller } - public function assigningSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTCLient $mclient, APNSClient $aclient, $id) + public function assigningSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTCLient $mclient, FCMSender $fcmclient, APNSClient $aclient, $id) { $this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.'); @@ -481,7 +482,7 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, $id) + public function fulfillmentSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, FCMSender $fcmclient, $id) { $this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.'); @@ -540,7 +541,7 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function openHubSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id) + public function openHubSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id) { $this->denyAccessUnlessGranted('jo_open.list', null, 'No access.'); @@ -549,7 +550,7 @@ class JobOrderController extends Controller try { - $error_array = $jo_handler->setHub($req, $id, $mclient, $mclientv2); + $error_array = $jo_handler->setHub($req, $id, $mclient, $mclientv2, $fcmclient); } catch (NotFoundHttpException $e) { @@ -598,7 +599,7 @@ class JobOrderController extends Controller return $this->render($template, $params); } - public function openRiderSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id) + public function openRiderSubmit(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id) { $this->denyAccessUnlessGranted('jo_open.list', null, 'No access.'); @@ -607,7 +608,7 @@ class JobOrderController extends Controller try { - $error_array = $jo_handler->setRider($req, $id, $mclient, $mclientv2); + $error_array = $jo_handler->setRider($req, $id, $mclient, $mclientv2, $fcmclient); } catch (NotFoundHttpException $e) { @@ -681,7 +682,7 @@ class JobOrderController extends Controller ]); } - public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, $id) + public function cancelJobOrder(Request $req, JobOrderHandlerInterface $jo_handler, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, $id) { $this->denyAccessUnlessGranted('joborder.cancel', null, 'No access.'); @@ -698,7 +699,7 @@ class JobOrderController extends Controller try { - $jo_handler->cancelJobOrder($req, $id, $mclient, $mclientv2); + $jo_handler->cancelJobOrder($req, $id, $mclient, $mclientv2, $fcmclient); } catch (NotFoundHttpException $e) { diff --git a/src/Controller/TAPI/JobOrderController.php b/src/Controller/TAPI/JobOrderController.php index 0e046449..64436a43 100644 --- a/src/Controller/TAPI/JobOrderController.php +++ b/src/Controller/TAPI/JobOrderController.php @@ -34,6 +34,7 @@ use App\Service\InvoiceGeneratorInterface; use App\Service\RisingTideGateway; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\GeofenceTracker; use App\Service\InventoryManager; use App\Service\RiderAssignmentHandlerInterface; @@ -74,6 +75,7 @@ class JobOrderController extends APIController // TODO: break this monolithic method down public function requestJobOrder(Request $req, InvoiceGeneratorInterface $ic, GeofenceTracker $geo, InventoryManager $im, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, + FCMSender $fcmclient, RiderAssignmentHandlerInterface $rah, PromoLogger $promo_logger, HubSelector $hub_select, HubDistributor $hub_dist, HubFilterLogger $hub_filter_logger, HubFilteringGeoChecker $hub_geofence, EntityManagerInterface $em) @@ -356,6 +358,7 @@ class JobOrderController extends APIController // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); $rah->assignJobOrder($jo, $jo->getRider()); } @@ -378,6 +381,7 @@ class JobOrderController extends APIController // NOTE: for resq2 app $mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); } $em->flush(); diff --git a/src/Service/FCMSender.php b/src/Service/FCMSender.php new file mode 100644 index 00000000..01d72252 --- /dev/null +++ b/src/Service/FCMSender.php @@ -0,0 +1,92 @@ +client = new FcmClient($server_key, $sender_id); + $this->translator = $translator; + } + + public function send($recipients, $title, $body, $data = [], $color = null, $sound = null, $badge = null) + { + $notification = new Notification(); + $notification->setTitle($title) + ->setBody($body); + + foreach ($recipients as $recipient) { + $notification->addRecipient($recipient); + } + + if (!empty($color)) { + $notification->setColor($color); + } + + if (!empty($sound)) { + $notification->setSound($sound); + } + + if (!empty($color)) { + $notification->setColor($color); + } + + if (!empty($badge)) { + $notification->setBadge($badge); + } + + if (!empty($data)) { + $notification->addDataArray($data); + } + + return $this->client->send($notification); + } + + public function sendJoEvent(JobOrder $job_order, $title, $body, $data = []) + { + // get all v2 sessions + $sessions = []; + $cust_user = $job_order->getCustomer()->getCustomerUser(); + if (!empty($cust_user)) { + $sessions = $cust_user->getMobileSessions(); + } + + if (empty($sessions)) { + error_log("no sessions to send fcm notification to"); + return; + } + + $device_ids = []; + + // send to every customer session + foreach ($sessions as $sess) { + $device_id = $sess->getDevicePushID(); + + error_log($sess->getID()); + + if (!empty($device_id)) { + // send fcm notification + $device_ids[] = $device_id; + } + } + + if (empty($device_ids)) { + error_log("no devices to send fcm notification to"); + return; + } + + // send fcm notification + $result = $this->send($device_ids, $this->translator->trans($title), $this->translator->trans($body), $data); + + return $result; + } +} diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 45f1a2cd..43a7becb 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -47,6 +47,7 @@ use App\Service\CustomerHandlerInterface; use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Service\MapTools; @@ -669,7 +670,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // dispatch job order - public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { // get object data $em = $this->em; @@ -797,6 +798,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); } return $error_array; @@ -1031,7 +1033,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // cancel job order - public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { // get object data $em = $this->em; @@ -1075,10 +1077,11 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_cancelled", "jo_fcm_body_cancelled", ['reason' => $cancel_reason]); } // set hub for job order - public function setHub($req, $id, $mclient, $mclientv2) + public function setHub($req, $id, $mclient, $mclientv2, $fcmclient) { // get object data $em = $this->em; @@ -1181,6 +1184,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); } return $error_array; @@ -1282,7 +1286,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // set rider for job order - public function setRider($req, $id, $mclient, $mclientv2) + public function setRider($req, $id, $mclient, $mclientv2, $fcmclient) { // initialize error list $error_array = []; @@ -1385,6 +1389,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned"); } return $error_array; diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 3b6d7cac..a8e75781 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -58,6 +58,7 @@ use App\Service\RiderAssignmentHandlerInterface; use App\Service\WarrantyHandler; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Service\MapTools; use App\Service\RisingTideGateway; @@ -804,7 +805,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } // dispatch job order - public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { // get object data $em = $this->em; @@ -985,7 +986,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); - + $fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); // update redis hub jo count $this->hub_dist->incrementJoCountForHub($hub); @@ -1342,7 +1343,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } // cancel job order - public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2) + public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient) { // get object data $em = $this->em; @@ -1390,10 +1391,11 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_cancelled", "jo_fcm_body_cancelled", ['reason' => $cancel_reason]); } // set hub for job order - public function setHub($req, $id, $mclient, $mclientv2) + public function setHub($req, $id, $mclient, $mclientv2, $fcmclient) { // get object data $em = $this->em; @@ -1570,6 +1572,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); // update redis hub_jo_count for hub // decrement old hub's count and increment new hub's count @@ -1678,7 +1681,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } // set rider for job order - public function setRider($req, $id, $mclient, $mclientv2) + public function setRider($req, $id, $mclient, $mclientv2, $fcmclient) { // initialize error list $error_array = []; @@ -1854,6 +1857,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface // NOTE: for resq2 app $mclientv2->sendEvent($obj, $payload); + $fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned"); } return $error_array; diff --git a/src/Service/JobOrderHandlerInterface.php b/src/Service/JobOrderHandlerInterface.php index b1b708a8..17041c06 100644 --- a/src/Service/JobOrderHandlerInterface.php +++ b/src/Service/JobOrderHandlerInterface.php @@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\Request; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Service\MapTools; use App\Service\HubSelector; @@ -30,7 +31,7 @@ interface JobOrderHandlerInterface public function processOneStepJobOrder(Request $req, int $id); // dispatch job order - public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2); + public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient); // assign job order public function assignJobOrder(Request $req, int $id); @@ -39,16 +40,16 @@ interface JobOrderHandlerInterface public function fulfillJobOrder(Request $req, int $id); // cancel job order - public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2); + public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient); // set hub for job order - public function setHub(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2); + public function setHub(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient); // reject hub for job order public function rejectHub(Request $req, int $id); // set rider for job order - public function setRider(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2); + public function setRider(Request $req, int $id, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient); // unlock processor public function unlockProcessor(int $id); diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 5c8bde50..e35ab643 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -19,6 +19,7 @@ use App\Service\RedisClientProvider; use App\Service\RiderCache; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\WarrantyHandler; use App\Service\JobOrderHandlerInterface; use App\Service\InvoiceGeneratorInterface; @@ -44,6 +45,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface protected $country_code; protected $mclient; protected $mclientv2; + protected $fcmclient; protected $wh; protected $jo_handler; protected $ic; @@ -51,7 +53,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface public function __construct(EntityManagerInterface $em, RedisClientProvider $redis, EncoderFactoryInterface $ef, RiderCache $rcache, - string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, + string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler, InvoiceGeneratorInterface $ic) { @@ -62,6 +64,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $this->country_code = $country_code; $this->mclient = $mclient; $this->mclientv2 = $mclientv2; + $this->fcmclient = $fcmclient; $this->wh = $wh; $this->jo_handler = $jo_handler; $this->ic = $ic; @@ -429,6 +432,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $this->fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); return $data; } @@ -473,6 +477,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $this->fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived"); return $data; } @@ -589,6 +594,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $this->fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled"); return $data; } diff --git a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php index 2dea0044..64624b2a 100644 --- a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php @@ -22,6 +22,7 @@ use App\Service\RedisClientProvider; use App\Service\RiderCache; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\WarrantyHandler; use App\Service\JobOrderHandlerInterface; use App\Service\InvoiceGeneratorInterface; @@ -49,6 +50,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface protected $country_code; protected $mclient; protected $mclientv2; + protected $fcmclient; protected $wh; protected $jo_handler; protected $ic; @@ -58,7 +60,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface public function __construct(EntityManagerInterface $em, RedisClientProvider $redis, EncoderFactoryInterface $ef, RiderCache $rcache, - string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, + string $country_code, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler, InvoiceGeneratorInterface $ic, RisingTideGateway $rt, RiderTracker $rider_tracker, TranslatorInterface $translator) @@ -70,6 +72,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface $this->country_code = $country_code; $this->mclient = $mclient; $this->mclientv2 = $mclientv2; + $this->fcmclient = $fcmclient; $this->wh = $wh; $this->jo_handler = $jo_handler; $this->ic = $ic; @@ -471,6 +474,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $this->fcmclient->sendJoEvent($jo, "jo_fcm_title_outlet_assign", "jo_fcm_body_outlet_assign"); return $data; } @@ -515,6 +519,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $this->fcmclient->sendJoEvent($jo, "jo_fcm_title_driver_arrived", "jo_fcm_body_driver_arrived"); return $data; } @@ -672,6 +677,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($jo, $payload); + $fcmclient->sendJoEvent($jo, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled"); return $data; } diff --git a/src/Service/RiderAssignmentHandler/CMBRiderAssignmentHandler.php b/src/Service/RiderAssignmentHandler/CMBRiderAssignmentHandler.php index 40a3b5b6..e6ff0664 100644 --- a/src/Service/RiderAssignmentHandler/CMBRiderAssignmentHandler.php +++ b/src/Service/RiderAssignmentHandler/CMBRiderAssignmentHandler.php @@ -7,6 +7,7 @@ use Doctrine\ORM\EntityManagerInterface; use App\Service\RiderAssignmentHandlerInterface; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Entity\JobOrder; @@ -20,12 +21,14 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface protected $aclient; protected $mclient; protected $mclientv2; + protected $fcmclient; - public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient) + public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, APNSClient $aclient) { $this->em = $em; $this->mclient = $mclient; $this->mclientv2 = $mclientv2; + $this->fcmclient = $fcmclient; $this->aclient = $aclient; } @@ -42,6 +45,7 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($obj, $payload); + $this->fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned"); // check if rider is available if ($rider->isAvailable()) @@ -73,6 +77,7 @@ class CMBRiderAssignmentHandler implements RiderAssignmentHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($obj, $payload); + $this->fcmclient->sendJoEvent($obj, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled"); // send fulfill/complete event to rider $this->mclient->sendRiderEvent($obj, $payload); diff --git a/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php b/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php index bf5e8651..80e8d89c 100644 --- a/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php +++ b/src/Service/RiderAssignmentHandler/ResqRiderAssignmentHandler.php @@ -9,6 +9,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; use App\Service\RiderAssignmentHandlerInterface; use App\Service\MQTTClient; use App\Service\MQTTClientApiv2; +use App\Service\FCMSender; use App\Service\APNSClient; use App\Entity\JobOrder; @@ -22,13 +23,15 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface protected $aclient; protected $mclient; protected $mclientv2; + protected $fcmclient; protected $translator; - public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, APNSClient $aclient, TranslatorInterface $translator) + public function __construct(EntityManagerInterface $em, MQTTClient $mclient, MQTTClientApiv2 $mclientv2, FCMSender $fcmclient, APNSClient $aclient, TranslatorInterface $translator) { $this->em = $em; $this->mclient = $mclient; $this->mclientv2 = $mclientv2; + $this->fcmclient = $fcmclient; $this->aclient = $aclient; $this->translator = $translator; } @@ -46,6 +49,7 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($obj, $payload); + $this->fcmclient->sendJoEvent($obj, "jo_fcm_title_driver_assigned", "jo_fcm_body_driver_assigned"); // check if rider is available if ($rider->isAvailable()) @@ -79,6 +83,7 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface // NOTE: for resq2 app $this->mclientv2->sendEvent($obj, $payload); + $this->fcmclient->sendJoEvent($obj, "jo_fcm_title_fulfilled", "jo_fcm_body_fulfilled"); // send fulfill/complete event to rider $this->mclient->sendRiderEvent($obj, $payload); diff --git a/translations/resq.messages.en.yaml b/translations/resq.messages.en.yaml index c0fb8ca1..44826f23 100644 --- a/translations/resq.messages.en.yaml +++ b/translations/resq.messages.en.yaml @@ -25,3 +25,15 @@ image_jo_pdf: /public/assets/images/logo-resq.png default_lat: 14.6091 default_long: 121.0223 default_region: ph + +# fcm jo status updates +jo_fcm_title_outlet_assign: Looking for riders +jo_fcm_title_driver_assigned: Rider found +jo_fcm_title_driver_arrived: Rider nearby +jo_fcm_title_cancelled: Order cancelled +jo_fcm_title_fulfilled: Thank you! +jo_fcm_body_outlet_assign: We're assigning a rider for your order, please wait. +jo_fcm_body_driver_assigned: A rider is on their way. +jo_fcm_body_driver_arrived: Your order is almost there! +jo_fcm_body_cancelled: Your order has been cancelled. +jo_fcm_body_fulfilled: Order complete! Your receipt is ready. \ No newline at end of file