From ad841a7e258f4b4813a3cef2360a45508d12e2ec Mon Sep 17 00:00:00 2001 From: Ramon Gutierrez Date: Fri, 31 May 2024 06:49:55 +0800 Subject: [PATCH] Prevent success handler from catching failed paymongo payment attempts #801 --- src/Controller/PayMongoController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Controller/PayMongoController.php b/src/Controller/PayMongoController.php index 21cd864c..af698acd 100644 --- a/src/Controller/PayMongoController.php +++ b/src/Controller/PayMongoController.php @@ -11,6 +11,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use DateTime; + class PayMongoController extends Controller { protected $pm; @@ -45,10 +47,8 @@ class PayMongoController extends Controller switch ($event_name) { case "payment.paid": return $this->handlePaymentPaid($event); - break; case "payment.failed": - return $this->handlePaymentPaid($event); - break; + return $this->handlePaymentFailed($event); case "payment.refunded": // TODO: handle refunds case "payment.refund.updated": case "checkout_session.payment.paid": @@ -69,6 +69,7 @@ class PayMongoController extends Controller if (!empty($obj)) { // mark as paid $obj->setStatus(TransactionStatus::PAID); + $obj->setDatePay(new DateTime()); $this->em->flush(); } @@ -77,7 +78,7 @@ class PayMongoController extends Controller ]); } - protected function handlePaymentFailed(Request $req) + protected function handlePaymentFailed($event) { // TODO: do something about failed payments? return $this->json([