Prevent success handler from catching failed paymongo payment attempts #801

This commit is contained in:
Ramon Gutierrez 2024-05-31 06:49:55 +08:00
parent 75b2ada03f
commit ad841a7e25

View file

@ -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([