Commit 472721ab by Damien Moulard

WIP connect CB payment to tav cotis

parent d63df04c
......@@ -132,6 +132,8 @@ class PaymentController extends AbstractController
$this->em->persist($captureToken);
$this->em->flush();
// print_r($captureToken->getTargetUrl());
return $this->redirect($captureToken->getTargetUrl());
}
......@@ -156,7 +158,7 @@ class PaymentController extends AbstractController
if ($payment->getStatus() == GetHumanStatus::STATUS_NEW) {
// 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));
} else {
// Invalidate token
......@@ -191,6 +193,11 @@ class PaymentController extends AbstractController
$this->authenticator,
'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 ||
$payment->getStatus() == GetHumanStatus::STATUS_EXPIRED ||
......
......@@ -166,19 +166,25 @@ class UserAdherentController extends FluxController
$flux->setDon(null);
}
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
// TODO redirect to paiement
return $this->forward('App\Controller\PaymentController::preparePaymentAction', [
'form' => $form,
'type' => Payment::TYPE_PAIEMENT_COTISATION_TAV // TODO
]);
// Apply cotisation rate, create new flux
$this->tavCotisationsUtils->applyTauxCotisation($flux);
// $this->em->persist($flux);
// $this->operationUtils->executeOperations($flux);
// // Apply cotisation rate, create new flux
// $this->tavCotisationsUtils->applyTauxCotisation($flux);
$this->em->flush();
$this->addFlash(
'success',
$this->translator->trans('Cotisation payée ! [Paiement via Payzen temporairement désactivé]')
);
// $this->em->flush();
// $this->addFlash(
// 'success',
// $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', [
......
......@@ -17,6 +17,7 @@ class Payment extends BasePayment
const TYPE_COTISATION_ADHERENT = 'cotisation_adherent';
const TYPE_COTISATION_PRESTA = 'cotisation_presta';
const TYPE_ADHESION = 'adhesion';
const TYPE_PAIEMENT_COTISATION_TAV = 'paiement_cotisation_tav';
/**
* @var \Ramsey\Uuid\UuidInterface
......
......@@ -31,28 +31,37 @@ use App\Entity\AchatMonnaiePrestataire;
use App\Entity\CotisationAdherent;
use App\Entity\CotisationPrestataire;
use App\Entity\Don;
use App\Utils\OperationUtils;
use App\Utils\TAVCotisationUtils;
class PaymentStatusExtension implements ExtensionInterface
{
private $em;
protected $eventDispatcher;
protected $serializer;
protected $userManager;
private $eventDispatcher;
private $serializer;
private $userManager;
private $operationUtils;
private $tavCotisationsUtils;
/**
* PaymentStatusExtension constructor.
*
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher,
SerializerInterface $serializer,
UserManagerInterface $userManager)
{
public function __construct(
EntityManagerInterface $em,
EventDispatcherInterface $eventDispatcher,
SerializerInterface $serializer,
UserManagerInterface $userManager,
OperationUtils $operationUtils,
TAVCotisationUtils $tavCotisationsUtils
) {
$this->em = $em;
$this->eventDispatcher = $eventDispatcher;
$this->serializer = $serializer;
$this->userManager = $userManager;
$this->operationUtils = $operationUtils;
$this->tavCotisationsUtils = $tavCotisationsUtils;
}
/**
......@@ -244,20 +253,46 @@ class PaymentStatusExtension implements ExtensionInterface
$payment->setClientId($user->getId());
$payment->setExtraData('');
$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 {
// Bad request
}
$this->em->persist($flux);
$this->em->flush();
$this->operationUtils->executeOperations($flux);
$this->eventDispatcher->dispatch(
MLCEvents::FLUX,
new FluxEvent($flux)
);
if (Payment::TYPE_PAIEMENT_COTISATION_TAV == $type) {
// Apply cotisation rate, create new flux
$this->tavCotisationsUtils->applyTauxCotisation($flux);
}
// Invalidate (delete) notify token after payment is captured
$this->em->remove($token);
$this->em->flush();
}
}
......
......@@ -32,16 +32,20 @@ class TAVCotisationUtils
*/
public function checkExistingCotisation(Flux $flux)
{
$first_day_this_month = date('Y-m-01');
$last_day_this_month = date('Y-m-t');
// FOR TESTS PURPOSES
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(
$flux->getDestinataire(),
$first_day_this_month,
$last_day_this_month
);
// $existing = $this->em->getRepository(Flux::class)->getTavCotisationsBetweenDates(
// $flux->getDestinataire(),
// $first_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