Commit e5c29138 by Damien Moulard

fix paiement payzen adhesion

parent 84b2bd30
......@@ -11,6 +11,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
......@@ -291,7 +292,7 @@ class FluxController extends AbstractController
/**
* Fonction de traitement du paiement, à appeler :
* - automatiquement lorsqu'un événement se produit sur le site de Paiement
* - automatiquement lorsqu'un événement se produit sur le site de Paiement (notification)
* - au retour sur le site par l'utilisateur
*
* @Route("/payment/done/", name="payment_done")
......@@ -301,56 +302,7 @@ class FluxController extends AbstractController
try {
$token = $this->payum->getHttpRequestVerifier()->verify($request);
} catch (\Exception $e) {
// Token expiré : retour sur site après paiement
// Get last payment
try {
$payment = $this->em->getRepository(Payment::class)->getUserLastPayment($this->getUser()->getId());
} catch (\Exception $e) {
return $this->redirectToRoute('index');
}
if (!is_null($payment)) {
if ($payment->getStatus() == GetHumanStatus::STATUS_CAPTURED || $payment->getStatus() == GetHumanStatus::STATUS_AUTHORIZED) {
$type = $payment->getDescription();
if (Payment::TYPE_ACHAT_MONNAIE_ADHERENT == $type || Payment::TYPE_ACHAT_MONNAIE_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Achat de monnaie locale bien effectué !')
);
} else if (Payment::TYPE_COTISATION_ADHERENT == $type || Payment::TYPE_COTISATION_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Cotisation bien reçue. Merci !')
);
} else if (Payment::TYPE_ADHESION == $type) {
$this->addFlash(
'success',
$this->translator->trans('Votre adhésion a bien été prise en compte, bienvenue !')
);
}
// Update payment status
$payment->setStatus($payment->getStatus().';done');
$this->em->persist($payment);
$this->em->flush();
} else if ($payment->getStatus() == GetHumanStatus::STATUS_CANCELED ||
$payment->getStatus() == GetHumanStatus::STATUS_EXPIRED ||
$payment->getStatus() == GetHumanStatus::STATUS_FAILED) {
$this->addFlash(
'error',
$this->translator->trans('La transaction a été annulée.')
);
$payment->setStatus($payment->getStatus().';done');
$this->em->persist($payment);
$this->em->flush();
}
}
// Token expired
return $this->redirectToRoute('index');
}
......@@ -362,8 +314,59 @@ class FluxController extends AbstractController
// Execute 'done' action according to payment status
$gateway->execute($status = new GetHumanStatus($token));
// Get payment & update status
// Get payment
$payment = $status->getFirstModel();
// Check for actual payment status. If not null or new: payment has already been processed.
if ($payment->getStatus() == GetHumanStatus::STATUS_CAPTURED || $payment->getStatus() == GetHumanStatus::STATUS_AUTHORIZED) {
// Invalidate token
$this->payum->getHttpRequestVerifier()->invalidate($token);
$type = $payment->getDescription();
if (Payment::TYPE_ACHAT_MONNAIE_ADHERENT == $type || Payment::TYPE_ACHAT_MONNAIE_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Achat de monnaie locale bien effectué !')
);
} else if (Payment::TYPE_COTISATION_ADHERENT == $type || Payment::TYPE_COTISATION_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Cotisation bien reçue. Merci !')
);
} else if (Payment::TYPE_ADHESION == $type) {
$this->addFlash(
'success',
$this->translator->trans('Votre adhésion a bien été prise en compte, bienvenue !')
);
// Connect new user
return $this->guardHandler
->authenticateUserAndHandleSuccess(
$this->em->getRepository(User::class)->findOneBy(array('id' => $payment->getClientId())),
$request,
$this->authenticator,
'main'
);
}
return $this->redirectToRoute('index');
} else if ($payment->getStatus() == GetHumanStatus::STATUS_CANCELED ||
$payment->getStatus() == GetHumanStatus::STATUS_EXPIRED ||
$payment->getStatus() == GetHumanStatus::STATUS_FAILED) {
// Invalidate token
$this->payum->getHttpRequestVerifier()->invalidate($token);
$this->addFlash(
'error',
$this->translator->trans('La transaction a été annulée.')
);
return $this->redirectToRoute('index');
}
// We got here, payment hasn't been processed, we're in the notification process. Update payment status and go on.
$payment->setStatus($status->getValue());
$this->em->persist($payment);
$this->em->flush();
......@@ -507,53 +510,9 @@ class FluxController extends AbstractController
MLCEvents::FLUX,
new FluxEvent($flux)
);
// Add flash message here too in case Gataway doesn't notify
if (Payment::TYPE_ACHAT_MONNAIE_ADHERENT == $type || Payment::TYPE_ACHAT_MONNAIE_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Achat de monnaie locale bien effectué !')
);
} else if (Payment::TYPE_COTISATION_ADHERENT == $type || Payment::TYPE_COTISATION_PRESTA == $type) {
$this->addFlash(
'success',
$this->translator->trans('Cotisation bien reçue. Merci !')
);
} else if (Payment::TYPE_ADHESION == $type) {
$this->addFlash(
'success',
$this->translator->trans('Votre adhésion a bien été prise en compte, bienvenue !')
);
}
// Invalidate token
$this->payum->getHttpRequestVerifier()->invalidate($token);
} else if ($status->getValue() == GetHumanStatus::STATUS_CANCELED ||
$status->getValue() == GetHumanStatus::STATUS_EXPIRED ||
$status->getValue() == GetHumanStatus::STATUS_FAILED) {
$this->addFlash(
'error',
$this->translator->trans('La transaction a été annulée.')
);
$this->payum->getHttpRequestVerifier()->invalidate($token);
}
if (Payment::TYPE_ADHESION == $type) {
// Auto login after adhesion
return $this->guardHandler
->authenticateUserAndHandleSuccess(
$user,
$request,
$this->authenticator,
'main'
);
} else {
return $this->redirectToRoute('index');
}
return new Response('ok', Response::HTTP_OK);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment