Move all points logic from paymongo listener to gateway transaction listener #799

This commit is contained in:
Ramon Gutierrez 2024-10-24 04:05:20 +08:00
parent f7ba91892b
commit 3ed65e7fc6
2 changed files with 3 additions and 22 deletions

View file

@ -13,8 +13,6 @@ use App\Entity\CustomerVehicle;
use App\Ramcar\SubscriptionStatus; use App\Ramcar\SubscriptionStatus;
use App\Entity\GatewayTransaction; use App\Entity\GatewayTransaction;
use App\Ramcar\TransactionStatus; use App\Ramcar\TransactionStatus;
use App\Service\FCMSender;
use App\Service\LoyaltyConnector;
use DateTime; use DateTime;
class SubscriptionController extends ApiController 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 // check requirements
$validity = $this->validateRequest($req); $validity = $this->validateRequest($req);
@ -228,7 +226,6 @@ class SubscriptionController extends ApiController
]); ]);
if (empty($sub_obj)) { if (empty($sub_obj)) {
error_log("no sub found!");
return new ApiResponse(false, 'Invalid subscription provided.'); return new ApiResponse(false, 'Invalid subscription provided.');
} }
@ -281,24 +278,6 @@ class SubscriptionController extends ApiController
$this->em->flush(); $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 // response
return new ApiResponse(true, '', [ return new ApiResponse(true, '', [

View file

@ -48,6 +48,8 @@ class GatewayTransactionListener
$prev_value = $field_changes[0] ?? null; $prev_value = $field_changes[0] ?? null;
$new_value = $field_changes[1] ?? null; $new_value = $field_changes[1] ?? null;
error_log($prev_value . " vs " . $new_value);
// only do something if the status has changed to paid // only do something if the status has changed to paid
if ($prev_value !== $new_value && $new_value === TransactionStatus::PAID) { if ($prev_value !== $new_value && $new_value === TransactionStatus::PAID) {
// determine if we will add loyalty points for this transaction // determine if we will add loyalty points for this transaction