Commit 472721ab by Damien Moulard

WIP connect CB payment to tav cotis

parent d63df04c
...@@ -132,6 +132,8 @@ class PaymentController extends AbstractController ...@@ -132,6 +132,8 @@ class PaymentController extends AbstractController
$this->em->persist($captureToken); $this->em->persist($captureToken);
$this->em->flush(); $this->em->flush();
// print_r($captureToken->getTargetUrl());
return $this->redirect($captureToken->getTargetUrl()); return $this->redirect($captureToken->getTargetUrl());
} }
...@@ -156,7 +158,7 @@ class PaymentController extends AbstractController ...@@ -156,7 +158,7 @@ class PaymentController extends AbstractController
if ($payment->getStatus() == GetHumanStatus::STATUS_NEW) { if ($payment->getStatus() == GetHumanStatus::STATUS_NEW) {
// No notification arrived at this point: execute Notify action // No notification arrived at this point: execute Notify action
// TODO: notify token isn't deleted // TODO: notify token isn't deleted (still?)
$gateway->execute(new Notify($token)); $gateway->execute(new Notify($token));
} else { } else {
// Invalidate token // Invalidate token
...@@ -191,6 +193,11 @@ class PaymentController extends AbstractController ...@@ -191,6 +193,11 @@ class PaymentController extends AbstractController
$this->authenticator, $this->authenticator,
'main' 'main'
); );
} else if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type) {
$this->addFlash(
'success',
$this->translator->trans('Cotisation payée !')
);
} }
} else if ($payment->getStatus() == GetHumanStatus::STATUS_CANCELED || } else if ($payment->getStatus() == GetHumanStatus::STATUS_CANCELED ||
$payment->getStatus() == GetHumanStatus::STATUS_EXPIRED || $payment->getStatus() == GetHumanStatus::STATUS_EXPIRED ||
......
...@@ -166,19 +166,25 @@ class UserAdherentController extends FluxController ...@@ -166,19 +166,25 @@ class UserAdherentController extends FluxController
$flux->setDon(null); $flux->setDon(null);
} }
$this->em->persist($flux); // TODO redirect to paiement
$this->operationUtils->executeOperations($flux); return $this->forward('App\Controller\PaymentController::preparePaymentAction', [
'form' => $form,
'type' => Payment::TYPE_PAIEMENT_COTISATION_TAV // TODO
]);
// Apply cotisation rate, create new flux // $this->em->persist($flux);
$this->tavCotisationsUtils->applyTauxCotisation($flux); // $this->operationUtils->executeOperations($flux);
// // Apply cotisation rate, create new flux
// $this->tavCotisationsUtils->applyTauxCotisation($flux);
$this->em->flush(); // $this->em->flush();
$this->addFlash( // $this->addFlash(
'success', // 'success',
$this->translator->trans('Cotisation payée ! [Paiement via Payzen temporairement désactivé]') // $this->translator->trans('Cotisation payée ! [Paiement via Payzen temporairement désactivé]')
); // );
return $this->redirectToRoute('index'); // return $this->redirectToRoute('index');
} }
return $this->render('@kohinos/flux/transaction.html.twig', [ return $this->render('@kohinos/flux/transaction.html.twig', [
......
...@@ -17,6 +17,7 @@ class Payment extends BasePayment ...@@ -17,6 +17,7 @@ class Payment extends BasePayment
const TYPE_COTISATION_ADHERENT = 'cotisation_adherent'; const TYPE_COTISATION_ADHERENT = 'cotisation_adherent';
const TYPE_COTISATION_PRESTA = 'cotisation_presta'; const TYPE_COTISATION_PRESTA = 'cotisation_presta';
const TYPE_ADHESION = 'adhesion'; const TYPE_ADHESION = 'adhesion';
const TYPE_PAIEMENT_COTISATION_TAV = 'paiement_cotisation_tav';
/** /**
* @var \Ramsey\Uuid\UuidInterface * @var \Ramsey\Uuid\UuidInterface
......
...@@ -31,28 +31,37 @@ use App\Entity\AchatMonnaiePrestataire; ...@@ -31,28 +31,37 @@ use App\Entity\AchatMonnaiePrestataire;
use App\Entity\CotisationAdherent; use App\Entity\CotisationAdherent;
use App\Entity\CotisationPrestataire; use App\Entity\CotisationPrestataire;
use App\Entity\Don; use App\Entity\Don;
use App\Utils\OperationUtils;
use App\Utils\TAVCotisationUtils;
class PaymentStatusExtension implements ExtensionInterface class PaymentStatusExtension implements ExtensionInterface
{ {
private $em; private $em;
protected $eventDispatcher; private $eventDispatcher;
protected $serializer; private $serializer;
protected $userManager; private $userManager;
private $operationUtils;
private $tavCotisationsUtils;
/** /**
* PaymentStatusExtension constructor. * PaymentStatusExtension constructor.
* *
* @param EntityManagerInterface $em * @param EntityManagerInterface $em
*/ */
public function __construct(EntityManagerInterface $em, public function __construct(
EventDispatcherInterface $eventDispatcher, EntityManagerInterface $em,
SerializerInterface $serializer, EventDispatcherInterface $eventDispatcher,
UserManagerInterface $userManager) SerializerInterface $serializer,
{ UserManagerInterface $userManager,
OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils
) {
$this->em = $em; $this->em = $em;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->serializer = $serializer; $this->serializer = $serializer;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils;
} }
/** /**
...@@ -244,20 +253,46 @@ class PaymentStatusExtension implements ExtensionInterface ...@@ -244,20 +253,46 @@ class PaymentStatusExtension implements ExtensionInterface
$payment->setClientId($user->getId()); $payment->setClientId($user->getId());
$payment->setExtraData(''); $payment->setExtraData('');
$this->em->persist($payment); $this->em->persist($payment);
} else if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type) {
$flux = $this->serializer->deserialize(
$payment->getFluxData(),
AchatMonnaieAdherent::class,
'json',
['disable_type_enforcement' => true]
);
$exp = $this->em->getRepository(Siege::class)->find($flux_array['expediteur']);
$flux->setExpediteur($exp);
$dest = $this->em->getRepository(Adherent::class)->find($flux_array['destinataire']);
$flux->setDestinataire($dest);
$op = $this->em->getRepository(User::class)->find($flux_array['operateur']);
$flux->setOperateur($op);
$flux->setReconverti(true);
if (null != $flux->getDon()) {
$flux->getDon()->setType(Don::TYPE_DON_ADHERENT);
$flux->getDon()->setOperateur($op);
$flux->getDon()->setExpediteur($dest);
$flux->getDon()->setDestinataire($this->em->getRepository(Prestataire::class)->findOneBy(['mlc' => true]));
}
} else { } else {
// Bad request // Bad request
} }
$this->em->persist($flux); $this->em->persist($flux);
$this->em->flush(); $this->operationUtils->executeOperations($flux);
$this->eventDispatcher->dispatch( if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type) {
MLCEvents::FLUX, // Apply cotisation rate, create new flux
new FluxEvent($flux) $this->tavCotisationsUtils->applyTauxCotisation($flux);
); }
// Invalidate (delete) notify token after payment is captured // Invalidate (delete) notify token after payment is captured
$this->em->remove($token); $this->em->remove($token);
$this->em->flush();
} }
} }
......
...@@ -32,16 +32,20 @@ class TAVCotisationUtils ...@@ -32,16 +32,20 @@ class TAVCotisationUtils
*/ */
public function checkExistingCotisation(Flux $flux) public function checkExistingCotisation(Flux $flux)
{ {
$first_day_this_month = date('Y-m-01'); // FOR TESTS PURPOSES
$last_day_this_month = date('Y-m-t'); return false;
// $first_day_this_month = date('Y-m-01');
// $last_day_this_month = date('Y-m-t');
$existing = $this->em->getRepository(Flux::class)->getTavCotisationsBetweenDates( // $existing = $this->em->getRepository(Flux::class)->getTavCotisationsBetweenDates(
$flux->getDestinataire(), // $flux->getDestinataire(),
$first_day_this_month, // $first_day_this_month,
$last_day_this_month // $last_day_this_month
); // );
return count($existing) > 0; // return count($existing) > 0;
} }
/** /**
......
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