Commit 8e9d69ac by Damien Moulard

fix payment with conventionnement errors & display remaining amount

parent b4013766
...@@ -507,6 +507,10 @@ $(function() { ...@@ -507,6 +507,10 @@ $(function() {
$(".presta-conventionnement-applied-text").hide(); $(".presta-conventionnement-applied-text").hide();
} }
/**
* If basket amount is set and valid, enable emlc amount field & hide errors if needed.
* Else display errors.
*/
function checkMontantPanier() { function checkMontantPanier() {
let input = $("#formEncaissement_montantPanier"); let input = $("#formEncaissement_montantPanier");
let val = input.val(); let val = input.val();
...@@ -538,12 +542,16 @@ $(function() { ...@@ -538,12 +542,16 @@ $(function() {
maxAmount = parseFloat(formEncaissementConventionnement) * basketAmount; maxAmount = parseFloat(formEncaissementConventionnement) * basketAmount;
$(".encaissment-emlc-max-amount").text(maxAmount); $(".encaissment-emlc-max-amount").text(maxAmount);
} }
checkMaxAmount();
} }
checkMontantPanier();
// enable emlc amount field if basket amount is set and valid checkMontantPanier();
$("#formEncaissement_montantPanier").on("input", checkMontantPanier); $("#formEncaissement_montantPanier").on("input", checkMontantPanier);
/**
* Check that emlc amount is valid depending on basket amount
*/
function checkMaxAmount() { function checkMaxAmount() {
function reset() { function reset() {
$("#formEncaissement_montant").removeClass('input-error'); $("#formEncaissement_montant").removeClass('input-error');
......
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,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"app": { "app": {
"js": [ "js": [
"/build/runtime.6ad5c9da.js", "/build/runtime.6ad5c9da.js",
"/build/app.29f72415.js" "/build/app.6ea8ce63.js"
], ],
"css": [ "css": [
"/build/app.04bd0e32.css" "/build/app.04bd0e32.css"
......
{ {
"build/app.css": "/build/app.04bd0e32.css", "build/app.css": "/build/app.04bd0e32.css",
"build/app.js": "/build/app.29f72415.js", "build/app.js": "/build/app.6ea8ce63.js",
"build/admin.css": "/build/admin.4de55830.css", "build/admin.css": "/build/admin.4de55830.css",
"build/admin.js": "/build/admin.86a2d986.js", "build/admin.js": "/build/admin.86a2d986.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js", "build/runtime.js": "/build/runtime.6ad5c9da.js",
......
...@@ -269,7 +269,7 @@ class UserController extends AbstractController ...@@ -269,7 +269,7 @@ class UserController extends AbstractController
$form = $this->createForm(EncaissementFormType::class, null, []); $form = $this->createForm(EncaissementFormType::class, null, []);
$form->handleRequest($request); $form->handleRequest($request);
$validation = false; $validation = false; // validation = user enters its code
$insufficientBalance = null; // if not null, will indicate for the template an insufficient founds situation $insufficientBalance = null; // if not null, will indicate for the template an insufficient founds situation
if ($form->isSubmitted()) { if ($form->isSubmitted()) {
...@@ -278,50 +278,55 @@ class UserController extends AbstractController ...@@ -278,50 +278,55 @@ class UserController extends AbstractController
if ($form->isValid()) { if ($form->isValid()) {
$adherent = $data["adherent"]; $adherent = $data["adherent"];
$adherent_code = $adherent->getPaymentCode(); $adherent_code = $adherent->getPaymentCode();
$input_code = $data["payment_code"];
// if adherent account isn't enabled // Perform first step checks
if (!$adherent->getUser()->isEnabled()) { if (empty($input_code)) {
$this->addFlash( // if adherent account isn't enabled
'error', if (!$adherent->getUser()->isEnabled()) {
$this->translator->trans('Le compte de l\'habitant·e est désactivé.') $this->addFlash(
); 'error',
$this->translator->trans('Le compte de l\'habitant·e est désactivé.')
goto end; );
}
// if adherent doesn't have a validation code
if (is_null($adherent_code)) {
$this->addFlash(
'error',
$this->translator->trans('L\'habitant·e n\'a pas encore défini un code de validation de paiement sur son espace personnel, il·elle ne peut pas payer en Monnaie Solidaire pour l\'instant.')
);
goto end;
}
// If entered amount is above maximum amount, depending on prestataire conventionnement goto end;
if ($conventionnementMode == true) { }
$transaction_amount = floatval($data["montant"]);
$montantPanier = floatval($form['montantPanier']->getData());
$maxAmount = $montantPanier * floatval($conventionnement);
if ($transaction_amount > $maxAmount) { // if adherent doesn't have a validation code
if (is_null($adherent_code)) {
$this->addFlash( $this->addFlash(
'error', 'error',
$this->translator->trans('Montant maximal en MonA dépassé. Veuillez modifier le montant en MonA.') $this->translator->trans('L\'habitant·e n\'a pas encore défini un code de validation de paiement sur son espace personnel, il·elle ne peut pas payer en Monnaie Solidaire pour l\'instant.')
); );
goto end; goto end;
} }
}
$input_code = $data["payment_code"]; // If entered amount is above maximum amount, depending on prestataire conventionnement
$validation = true; // When the form is submitted & valid, and the user account checks passed, we enter the validation process if ($conventionnementMode == true) {
$transaction_amount = floatval($data["montant"]);
$montantPanier = floatval($form['montantPanier']->getData());
$maxAmount = $montantPanier * floatval($conventionnement);
if ($transaction_amount > $maxAmount) {
$this->addFlash(
'error',
$this->translator->trans('Montant maximal en MonA dépassé. Veuillez modifier le montant en MonA.')
);
goto end;
}
}
// When the form is submitted & valid, and the user account checks passed, we enter the validation process
$validation = true;
if (empty($input_code)) {
// First step validated (set user & amount) -> go to validation // First step validated (set user & amount) -> go to validation
goto end; goto end;
} } else {
// We're in the validation process
$validation = true;
}
// Check validation code // Check validation code
// NOTE as we use password salt, the user must change his payment code if his password changes // NOTE as we use password salt, the user must change his payment code if his password changes
...@@ -365,7 +370,7 @@ class UserController extends AbstractController ...@@ -365,7 +370,7 @@ class UserController extends AbstractController
goto end; goto end;
} }
// Save transaction // No error at this point: save transaction
$flux = new TransactionAdherentPrestataire(); $flux = new TransactionAdherentPrestataire();
$flux->setExpediteur($adherent); $flux->setExpediteur($adherent);
...@@ -386,7 +391,15 @@ class UserController extends AbstractController ...@@ -386,7 +391,15 @@ class UserController extends AbstractController
$this->operationUtils->executeOperations($flux); $this->operationUtils->executeOperations($flux);
$this->em->flush(); $this->em->flush();
return $this->redirectToRoute('encaissementSuccess'); $redirectParams = [];
if ($form->has('montantPanier')) {
$transaction_amount = floatval($data["montant"]);
$montantPanier = floatval($form['montantPanier']->getData());
$redirectParams['remainingAmount'] = $montantPanier - $transaction_amount;
}
return $this->redirectToRoute('encaissementSuccess', $redirectParams);
} else { } else {
$this->addFlash( $this->addFlash(
'error', 'error',
...@@ -415,6 +428,13 @@ class UserController extends AbstractController ...@@ -415,6 +428,13 @@ class UserController extends AbstractController
*/ */
public function encaissementSuccessAction(Request $request) public function encaissementSuccessAction(Request $request)
{ {
return $this->render('@kohinos/tav/payment_done_page.html.twig', []); $templateData = [];
$remainingAmount = $request->query->get('remainingAmount');
if ($remainingAmount != '') {
$templateData['remainingAmount'] = $remainingAmount;
}
return $this->render('@kohinos/tav/payment_done_page.html.twig', $templateData);
} }
} }
...@@ -46,7 +46,7 @@ class EncaissementFormType extends AbstractType ...@@ -46,7 +46,7 @@ class EncaissementFormType extends AbstractType
'choice_label' => 'name' 'choice_label' => 'name'
]) ])
->add('montant', NumberType::class, [ ->add('montant', NumberType::class, [
'label' => "Montant en {$mlcName} : ", 'label' => "Montant à payer en {$mlcName} : ",
'required' => true, 'required' => true,
'attr' => ['autocomplete' => 'off'] 'attr' => ['autocomplete' => 'off']
]) ])
......
...@@ -71,6 +71,10 @@ ...@@ -71,6 +71,10 @@
<div style="display:none;"> <div style="display:none;">
{{ form_row(form.adherent) }} {{ form_row(form.adherent) }}
{{ form_row(form.montant) }} {{ form_row(form.montant) }}
{% if form.montantPanier is defined %}
{{ form_row(form.montantPanier) }}
{% endif %}
</div> </div>
{% else %} {% else %}
{{ form_row(form.adherent) }} {{ form_row(form.adherent) }}
...@@ -98,8 +102,14 @@ ...@@ -98,8 +102,14 @@
<script type="text/javascript"> <script type="text/javascript">
var formEncaissementValidation = '{{ validation }}'; var formEncaissementValidation = '{{ validation }}';
var KOH_MLC_NAME_SMALL = "{{ KOH_MLC_NAME_SMALL|default('') }}"; var KOH_MLC_NAME_SMALL = "{{ KOH_MLC_NAME_SMALL|default('') }}";
var formEncaissementConventionnement = '{{ conventionnement }}';
</script> </script>
{% if conventionnement is defined %}
<script type="text/javascript">
var formEncaissementConventionnement = '{{ conventionnement }}';
</script>
{% endif %}
{% endblock %} {% endblock %}
{% block footer %}{% endblock footer %} {% block footer %}{% endblock footer %}
\ No newline at end of file
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
{% block content %} {% block content %}
<div class='container' style='max-width: 800px;'> <div class='container' style='max-width: 800px;'>
<div class="payment-done-container"> <div class="payment-done-container">
<h1 class="text-center w-100 mt-4 payment-done-title">Paiement réussi !</h1> <h1 class="text-center w-100 mt-4 payment-done-title">
{{ 'Paiement réussi !'|trans }}
</h1>
<br/> <br/>
...@@ -20,6 +22,12 @@ ...@@ -20,6 +22,12 @@
<br/> <br/>
{% if remainingAmount is defined %}
<h5>{{ 'Reste à payer en euros :'|trans }} {{ remainingAmount }}</h5>
<br/>
{% endif %}
<a class='btn btn-xs btn-primary mt-4' href='{{ path('encaissement') }}'> <a class='btn btn-xs btn-primary mt-4' href='{{ path('encaissement') }}'>
{{ 'Nouvel encaissement'|trans }} {{ 'Nouvel encaissement'|trans }}
</a> </a>
......
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