Commit 2fa7b56d by Damien Moulard

finish payment process on front end

parent 8ee4625b
......@@ -158,3 +158,12 @@ Permettre la simulation du https en local :
Lancer le serveur local
**$ symfony server:start**
Compiler les assets (css & js) après modification pour tests
**$ yarn install** si besoin (première modif des assets)
**$ yarn run encore dev**
Compiler les assets avant de commit :
**$ yarn run encore prod**
......@@ -52,3 +52,53 @@ legend.required:after {
.invalid-feedback {
display: inline-block !important;
}
#code-digits-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 300px;
margin: 10px auto 30px auto;
}
.payment-code-button, .payment-code-correction-button {
display: inline-block;
background-color: white;
height: 80px;
width: 80px;
font-size: 1.5rem;
border: 3px solid #106a8c;
color: #117298;
font-weight: bold;
text-align: center;
text-decoration: none;
margin: 4px 2px;
/* margin: 6px 4px; */
border-radius: 50%;
}
.payment-code-button:active, .payment-code-correction-button:active {
background-color:#106a8c;
color: white;
}
.payment-code-button-placeholder {
height: 80px;
width: 80px;
}
#code-visual {
height: 60px;
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
}
#payment-validation-subheader {
display: flex;
justify-content: center;
font-style: italic;
margin-top: -10px;
margin-bottom: 20px;
}
\ No newline at end of file
......@@ -154,7 +154,7 @@ function showConfirmTransactionModal(div, form, montant, don, destinataire = nul
});
}
jQuery(document).ready(function() {
$(function() {
// Get the ul that holds the collection of groupes
$collectionHolder = $('.groupeprestas');
......@@ -466,12 +466,45 @@ jQuery(document).ready(function() {
}
});
$(".paiementDate").toggle($('#formSolidoumeItem_isRecurrent').is(':checked'))
$('#formSolidoumeItem_amount').slider()
$(".paiementDate").toggle($('#formSolidoumeItem_isRecurrent').is(':checked'));
$('#formSolidoumeItem_amount').slider();
$('#formSolidoumeItem_isRecurrent').click(function() {
$(".paiementDate").toggle(this.checked);
});
// Reset value on page loading (in case of second try)
$("#formEncaissement_payment_code").val('');
if ($("form[name='formEncaissement']").length > 0) {
let paymentValidationSubheaderText = `${$("#formEncaissement_adherent option:selected").text()} - Montant : ${$("#formEncaissement_montant").val()}`;
$("#payment-validation-subheader").text(paymentValidationSubheaderText);
}
/**
* On cashing payment, validation code screen, add digit to input when corresponding button clicked.
*/
$(".payment-code-button").on("click", function() {
// Get existing input
let code = $("#formEncaissement_payment_code").val();
// Add button value
code += this.dataset.value;
$("#formEncaissement_payment_code").val(code);
// Visual payment code representation
$("#code-visual").text("*".repeat(code.length));
});
$(".payment-code-correction-button").on("click", function() {
// Get existing input
let code = $("#formEncaissement_payment_code").val();
// Remove last char of code
code = code.slice(0, -1);
$("#formEncaissement_payment_code").val(code);
$("#code-visual").text("*".repeat(code.length));
});
// $('.js-datepicker').datepicker({
// closeText: 'Fermer',
// prevText: '<Préc',
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,10 +3,10 @@
"app": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/app.f88c3afa.js"
"/build/app.07dbfd30.js"
],
"css": [
"/build/app.f135e702.css"
"/build/app.0815270c.css"
]
},
"admin": {
......
{
"build/app.css": "/build/app.f135e702.css",
"build/app.js": "/build/app.f88c3afa.js",
"build/app.css": "/build/app.0815270c.css",
"build/app.js": "/build/app.07dbfd30.js",
"build/admin.css": "/build/admin.5dc0eea7.css",
"build/admin.js": "/build/admin.8a6adf4b.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
......
......@@ -175,6 +175,7 @@ class UserAdherentController extends FluxController
if (is_numeric($plainCode) && strlen($plainCode) >= 4 && strlen($plainCode) <= 8) {
$encoded = $encoder->encodePassword($this->getUser(), $plainCode);
printf($encoded);
$adherent->setPaymentCode($encoded);
$this->em->flush();
......
......@@ -27,6 +27,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserController extends AbstractController
{
......@@ -229,7 +230,7 @@ class UserController extends AbstractController
* @Route("/encaissement", name="encaissement")
* @IsGranted("ROLE_PRESTATAIRE")
*/
public function encaissementAction(Request $request)
public function encaissementAction(Request $request, UserPasswordEncoderInterface $encoder)
{
$options = [];
......@@ -241,42 +242,51 @@ class UserController extends AbstractController
$data = $form->getData();
if ($form->isValid()) {
$code = $data["payment_code"];
$input_code = $data["payment_code"];
$validation = true; // As soon as the form is valid, we're in validation
if (empty($code)) {
if (empty($input_code)) {
// First step validated (set user & amount) -> go to validation
goto end;
}
// $adherent = $data["adherent"];
$adherent = $data["adherent"];
$adherent_code = $adherent->getPaymentCode();
// if adherent doesn't have a validation code
// if (is_null($adherent->payment_code)) {
// $this->addFlash(
// 'error',
// $this->translator->trans('L\'utilisateur n\'a pas encore défini un code de validation de paiement sur son espace personnel, il ne peut pas faire d'encaissement pour l'instant.')
// );
// goto end;
// }
if (is_null($adherent_code)) {
$this->addFlash(
'error',
$this->translator->trans('L\'utilisateur n\'a pas encore défini un code de validation de paiement sur son espace personnel, il ne peut pas payer en Monnaie Solidaire pour l\'instant.')
);
goto end;
}
// Check validation code
// printf($adherent->payment_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
$this->addFlash(
'error',
$this->translator->trans('Code incorrect')
);
// // if bad validation code
// $this->addFlash(
// 'error',
// $this->translator->trans('Le code de validation de l\'habitant est erroné') . ' ' . $form->getErrors()
// );
goto end;
}
// $validation = true;
// TODO: Check has enough
// TODO check if user has validation code / code is ok / user has enough
// ifok save transfer (transaction?)
// TODO : ifok save transfer (transaction?)
$this->addFlash(
'success',
$this->translator->trans('Bravo !')
);
} else {
$this->addFlash(
'error',
......
......@@ -6,7 +6,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
......@@ -34,7 +34,7 @@ class EncaissementFormType extends AbstractType
'attr' => [
'class' => 'form-control select2',
],
'placeholder' => 'Choisissez un adhérent',
'placeholder' => 'Choisissez un.e adhérent.e',
'required' => true,
'label' => 'Adherent :',
'choice_label' => 'name'
......@@ -42,10 +42,12 @@ class EncaissementFormType extends AbstractType
->add('montant', NumberType::class, [
'label' => 'Montant : ',
'required' => true,
'attr' => ['autocomplete' => 'off']
])
->add('payment_code', PasswordType::class, [
'label' => 'Code de validation : ',
->add('payment_code', HiddenType::class, [
'label' => 'Code de validation de l\'habitant.e : ',
'required' => false,
'attr' => ['autocomplete' => 'off']
])
->add('save', SubmitType::class, ['label' => 'Valider'])
;
......
......@@ -17,6 +17,7 @@ class SetPaymentCodeFormType extends AbstractType
->add('payment_code', PasswordType::class, [
'label' => 'Saisir mon nouveau code (4 à 8 chiffres)',
'required' => true,
'attr' => ['autocomplete' => 'off']
])
->add('save', SubmitType::class, ['label' => 'Valider'])
;
......
......@@ -3,22 +3,42 @@
{% block content %}
<div class='container' style='max-width: 800px;'>
{% include '@kohinos/block/breadcrumb.html.twig' with {'label': 'Encaissement'} %}
{% if validation == true %}
<h2 class='text-center w-100 mt-4 mb-4'>{{ "Code de validation de l'habitant"|trans }}</h2>
<div id="payment-validation-subheader"></div>
{% else %}
<h2 class='text-center w-100 mt-4 mb-4'>{{ "Encaissement"|trans }}</h2>
{% endif %}
<div class='text-center mb-5'>
{{ form_start(form) }}
{{ form_start(form, {'attr': {'autocomplete': 'off'}}) }}
{% if validation == true %}
<div id="code-visual"></div>
<div id="code-digits-container">
<button type="button" class="payment-code-button" data-value="1">1</button>
<button type="button" class="payment-code-button" data-value="2">2</button>
<button type="button" class="payment-code-button" data-value="3">3</button>
<button type="button" class="payment-code-button" data-value="4">4</button>
<button type="button" class="payment-code-button" data-value="5">5</button>
<button type="button" class="payment-code-button" data-value="6">6</button>
<button type="button" class="payment-code-button" data-value="7">7</button>
<button type="button" class="payment-code-button" data-value="8">8</button>
<button type="button" class="payment-code-button" data-value="9">9</button>
<button type="button" class="payment-code-correction-button">
<i class="fa fa-backspace"></i>
</button>
<button type="button" class="payment-code-button" data-value="0">0</button>
<div class="payment-code-button-placeholder"></div>
</div>
<div style="display:none;">
{{ form_row(form.adherent) }}
{{ form_row(form.montant) }}
</div>
{{ form_row(form.payment_code) }}
{% else %}
{{ form_row(form.adherent) }}
{{ form_row(form.montant) }}
<div style="display:none;">
{{ form_row(form.payment_code) }}
</div>
{% endif %}
{{ form_end(form) }}
</div>
......
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