Commit db5e52e4 by Félicie

Merge branch '3583-payment-code' into 'develop'

set payment code from adherent homepage

See merge request cooperatic/kohinos-tav!5
parents 9a2d6212 65e49214
......@@ -14,10 +14,12 @@ use App\Form\Type\AchatMonnaieAdherentFormType;
use App\Form\Type\AdherentInfosFormType;
use App\Form\Type\TransactionAdherentAdherentFormType;
use App\Form\Type\TransactionAdherentPrestataireFormType;
use App\Form\Type\SetPaymentCodeFormType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserAdherentController extends FluxController
{
......@@ -156,4 +158,38 @@ class UserAdherentController extends FluxController
'datas' => $q,
]);
}
/**
* @Route("/adherent/set-payment-code", name="adherentSetPaymentCode")
* @IsGranted("ROLE_ADHERENT")
*/
public function setPaymentCodeAction(Request $request, UserPasswordEncoderInterface $encoder)
{
$adherent = $this->getUser()->getAdherent();
$form = $this->createForm(SetPaymentCodeFormType::class, $adherent);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$plainCode = $data->getPaymentCode();
if (is_numeric($plainCode) && strlen($plainCode) >= 4 && strlen($plainCode) <= 8) {
$encoded = $encoder->encodePassword($this->getUser(), $plainCode);
$adherent->setPaymentCode($encoded);
$this->em->flush();
$this->addFlash(
'success',
$this->translator->trans('Code de paiement modifié !')
);
} else {
$this->addFlash(
'error',
$this->translator->trans('Le code de paiement doit être composé de 4 à 8 chiffres.')
);
}
}
return $this->redirectToRoute('index');
}
}
......@@ -80,6 +80,11 @@ class Adherent extends AccountableObject implements AccountableInterface
*/
private $accounts;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentCode;
public function __construct()
{
$this->accounts = new ArrayCollection();
......@@ -224,4 +229,16 @@ class Adherent extends AccountableObject implements AccountableInterface
return 'Adhérent xxx';
}
public function getPaymentCode(): ?string
{
return $this->paymentCode;
}
public function setPaymentCode(?string $paymentCode): self
{
$this->paymentCode = $paymentCode;
return $this;
}
}
......@@ -50,6 +50,7 @@ use App\Form\Type\TransfertSiegeGroupeFormType;
use App\Form\Type\UserInfosFormType;
use App\Form\Type\VenteEmlcAdherentFormType;
use App\Form\Type\VenteEmlcPrestataireFormType;
use App\Form\Type\SetPaymentCodeFormType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Form\Type\ChangePasswordFormType;
use Symfony\Component\Form\FormFactoryInterface as FormF;
......@@ -433,4 +434,14 @@ class FormFactory
return $form->createView();
}
public function getSetPaymentCodeForm(User $user)
{
if (empty($user) || !$user->isGranted('ROLE_ADHERENT')) {
throw new \Exception('[FORM 23] Opération impossible !');
}
$form = $this->ff->create(SetPaymentCodeFormType::class, $user->getAdherent(), ['action' => $this->router->generate('adherentSetPaymentCode')]);
return $form->createView();
}
}
<?php
namespace App\Form\Type;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
class SetPaymentCodeFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('payment_code', PasswordType::class, [
'label' => 'Saisir mon nouveau code (4 à 8 chiffres)',
'required' => true,
])
->add('save', SubmitType::class, ['label' => 'Valider'])
;
}
public function getBlockPrefix()
{
return 'formSetPaymentCode';
}
}
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221121100031 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE adherent ADD payment_code VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT DEFAULT NULL COMMENT \'(DC2Type:personal_data)\'');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE adherent DROP payment_code');
$this->addSql('ALTER TABLE prestataire CHANGE iban iban LONGTEXT CHARACTER SET utf8mb3 DEFAULT NULL COLLATE `utf8mb3_general_ci` COMMENT \'(DC2Type:personal_data)\'');
}
}
......@@ -52,6 +52,7 @@ class FormExtension extends AbstractExtension
new \Twig_SimpleFunction('getAchatMonnaieAConfirmerPrestataireForm', [$this, 'getAchatMonnaieAConfirmerPrestataireForm']),
new \Twig_SimpleFunction('getTicketFixPrintForm', [$this, 'getTicketFixPrintForm']),
new \Twig_SimpleFunction('getTicketFixDestroyForm', [$this, 'getTicketFixDestroyForm']),
new \Twig_SimpleFunction('getSetPaymentCodeForm', [$this, 'getSetPaymentCodeForm']),
];
}
......@@ -199,4 +200,9 @@ class FormExtension extends AbstractExtension
{
return $this->container->get('app.formfactory')->getTicketFixDestroyForm($user);
}
public function getSetPaymentCodeForm(User $user)
{
return $this->container->get('app.formfactory')->getSetPaymentCodeForm($user);
}
}
......@@ -4,6 +4,10 @@
{% set esoldelabel = 'Solde e-mlc'|trans %}
{% include '@kohinos/block/solde.html.twig' with {'compte': app.user.adherent.emlcAccount.balance, 'soldelabel': esoldelabel, 'currency' : 'e'~(KOH_MLC_SYMBOL|default(''))} %}
{% if tav_env == 1 %}
{% include '@kohinos/tav/block/payment_code.html.twig' %}
{% endif %}
{% if KOH_USE_PAYZEN == 'true' or KOH_USE_HELLOASSO == 'true' %}
{% include '@kohinos/adherent/block/achat_monnaie.html.twig' %}
{% else %}
......
{% extends '@kohinos/block/block_collapse.html.twig' %}
{% block blocktitle %}
<i class="fa fa-clipboard-list mr-4"></i> {{ 'Mon code de paiement'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% set form = getSetPaymentCodeForm(app.user) %}
{{ form_start(form) }}
{{ form_row(form.payment_code) }}
{{ form_end(form) }}
{% endblock blockcontent %}
\ 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