Commit 3ae1d424 by Damien Moulard

save transaction & send mail for insufficient funds

parent 2fa7b56d
1 merge request!83574 payment from presta screen
......@@ -174,8 +174,8 @@ class UserAdherentController extends FluxController
$plainCode = $data->getPaymentCode();
if (is_numeric($plainCode) && strlen($plainCode) >= 4 && strlen($plainCode) <= 8) {
$encoded = $encoder->encodePassword($this->getUser(), $plainCode);
printf($encoded);
$encoded = crypt($plainCode, $this->getUser()->getSalt());
$adherent->setPaymentCode($encoded);
$this->em->flush();
......
......@@ -9,6 +9,7 @@ use App\Entity\GlobalParameter;
use App\Entity\Payment;
use App\Entity\Prestataire;
use App\Entity\User;
use App\Entity\TransactionAdherentPrestataire;
use App\Enum\MoyenEnum;
use App\Form\Type\CotiserFormType;
use App\Form\Type\DonAdherentFormType;
......@@ -24,10 +25,12 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Twig\Environment;
class UserController extends AbstractController
{
......@@ -36,14 +39,28 @@ class UserController extends AbstractController
private $security;
private $operationUtils;
private $cotisationUtils;
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator, Security $security, OperationUtils $operationUtils, CotisationUtils $cotisationUtils)
{
private $session;
private $mailer;
private $templating;
public function __construct(
EntityManagerInterface $em,
TranslatorInterface $translator,
Security $security,
OperationUtils $operationUtils,
CotisationUtils $cotisationUtils,
SessionInterface $session,
\Swift_Mailer $mailer,
Environment $templating
) {
$this->em = $em;
$this->translator = $translator;
$this->security = $security;
$this->operationUtils = $operationUtils;
$this->cotisationUtils = $cotisationUtils;
$this->session = $session;
$this->mailer = $mailer;
$this->templating = $templating;
}
/**
......@@ -264,14 +281,9 @@ class UserController extends AbstractController
}
// Check validation code
$encoded_input = $encoder->encodePassword($adherent->getUser(), $input_code);
printf('<p>encoded_input</p>');
printf($encoded_input);
printf('<p>adherent_code</p>');
printf($adherent_code);
if ($encoded_input != $adherent_code) {
// if bad validation code
// TODO as we use password salt, must change payment code if password changes
$encoded_input = crypt($input_code, $adherent->getUser()->getSalt());
if (!hash_equals($adherent_code, $encoded_input)) {
$this->addFlash(
'error',
$this->translator->trans('Code incorrect')
......@@ -280,13 +292,60 @@ class UserController extends AbstractController
goto end;
}
// TODO: Check has enough
// Check adherent has enough funds
$balance = $adherent->getEmlcAccount()->getBalance();
$transaction_amount = floatval($data["montant"]);
if ($balance < $transaction_amount) {
// Send mail for insufficient funds
$subject = 'Votre tentative de paiement en Monnaie Locale Solidaire : solde insuffisant !';
$mail = (new \Swift_Message($subject))
->setFrom($this->em->getRepository(GlobalParameter::class)->val(GlobalParameter::MLC_NOTIF_EMAIL))
->setTo($adherent->getUser()->getEmail())
->setBody(
$this->templating->render(
'@kohinos/email/tav/insufficient_funds.html.twig',
[
'subject' => $subject,
'montant' => $transaction_amount,
]
),
'text/html'
);
$this->mailer->send($mail);
$this->addFlash(
'error',
$this->translator->trans('Solde de l\'habitant insuffisant')
);
return $this->redirectToRoute('index');
}
// Save transaction
$flux = new TransactionAdherentPrestataire();
$flux->setExpediteur($adherent);
$presta = $this->session->get('_prestagere');
$presta = $this->em->getRepository(Prestataire::class)->findOneById($presta->getId());
$flux->setDestinataire($presta);
$flux->setOperateur($this->security->getUser());
$flux->setMontant($transaction_amount);
$flux->setMoyen(MoyenEnum::MOYEN_EMLC);
$now = (new \Datetime('now'))->format('d/m/Y H:i:s');
$flux->setReference('Achat en Monnaie Solidaire du ' . $now);
$this->em->persist($flux);
$this->operationUtils->executeOperations($flux);
$this->em->flush();
// TODO : ifok save transfer (transaction?)
$this->addFlash(
'success',
$this->translator->trans('Bravo !')
$this->translator->trans('Transaction réussie !')
);
return $this->redirectToRoute('index');
} else {
$this->addFlash(
'error',
......
{% extends '@kohinos/email/email_layout.html.twig' %}
{% set title %}{% spaceless %}
{{ subject }}
{% endspaceless %}
{% endset %}
{% block content %}
<h2 style="font-size: 18px; color: #111111; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-weight: bold; line-height: 1.2em; margin: 40px 0 10px;">
{{ 'Solde insuffisant'|trans }}
</h2><br/>
<p>
Une transaction d'un montant de {{ montant|number_format(2) }} vous a été refusée pour cause de solde insuffisant.
</p>
{% endblock %}
\ No newline at end of file
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