Commit 83738085 by Yvon Kerdoncuff

block user if another starting payment has been found

parent 4d371b7e
......@@ -54,15 +54,6 @@ class PaymentController extends AbstractController
*/
public function preparePaymentAction(Form $form, $type, $extra_data = null)
{
/* @var PaymentRepository $repo */
$repo = $this->em->getRepository(Payment::class);
//Redirect to starting payment page if a valid starting payment page exists
$url = $repo->findUrlOfValidStartingPayment($this->getUser()->getUsername());
$this->em->flush(); //save status updates when looking to valid starting payment page
if ($url) {
return $this->redirect($url);
}
// Enregistre les données du Flux en json, pour l'enregistrer une fois le paiement validé
$serializer = $this->container->get('serializer');
$toSerialize = Payment::TYPE_ADHESION == $type ? $form->get('cotisation')->getData() : $form->getData();
......
......@@ -50,8 +50,11 @@ class PaymentRepository extends ServiceEntityRepository
* If we find a valid starting Payment, we will return the payzen URL used to start the payment.
* We mark as unvalid Payment that are unvalid when we check them.
*/
public function findUrlOfValidStartingPayment($clientEmail)
public function findValidStartingPayment($clientEmail)
{
//At first, this method was created to return the url of an existing starting payment.
//As we don't know how to use this url to redirect the user to the existing payment page,
//we simply return the datetime when the payment will be expired.
$candidates = $this->findBy([
'clientEmail' => $clientEmail,
'startingPaymentAnalysisStatus' => null,
......@@ -73,10 +76,14 @@ class PaymentRepository extends ServiceEntityRepository
if ($timeout < new \DateTime()) {
$p->setStartingPaymentAnalysisStatus('TIMEOUT');
} else {
return $url;
return $timeout;
}
}
//Note : some fields updates are done in this method to exclude non-candidate payment from future research.
//We may not want to flush here so flushing will probably not occur when an ongoing starting payment is found,
//but it will occur only when the payment process succeeds, which is fine.
//no valid payment found
return '';
return null;
}
}
......@@ -12,6 +12,7 @@ use App\Entity\Flux;
use App\Entity\CotisationTavReversement;
use App\Entity\CotisationTavPrelevement;
use App\Enum\MoyenEnum;
use App\Repository\PaymentRepository;
use App\Utils\CustomEntityManager;
use Payum\Core\Request\GetHumanStatus;
use Symfony\Component\Security\Core\Security;
......@@ -38,14 +39,23 @@ class TAVCotisationUtils
*/
public function preventCotisationDuplication(Adherent $adherent)
{
$email = $adherent->getUser()->getEmail();
//Look for existing recurring payment
if($reason = $this->checkExistingRecurringPayment($adherent->getUser()->getEmail())) {
if($reason = $this->checkExistingRecurringPayment($email)) {
return implode(" ", array_column($reason,'reason'));
}
//Look for existing cotisation
if ($this->checkExistingCotisation($adherent)) {
return "Cotisation déjà payée ce mois-ci.";
}
//Look for possible Payzen starting payment (neither finished nor expired yet)
/* @var PaymentRepository $repo */
$repo = $this->em->getRepository(Payment::class);
$foundStartingPaymentTimeout = $repo->findValidStartingPayment($email);
if ($foundStartingPaymentTimeout) {
return "Détection d'un possible paiement en cours. Merci de réessayer à partir de "
. $foundStartingPaymentTimeout->format("H:i:s") . ".";
}
return "";
}
......
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