Commit 7e5dcd51 by Damien Moulard

cancel recurrent payment in kohinos from adherent admin

parent 38241d8e
......@@ -133,9 +133,36 @@ $(document).ready(function() {
}
if($(".fixBalanceAdherentFormPart").length > 0) {
$(".fixBalanceAdherentFormPart").parent().parent().hide();
$("div[id$='_idmlc']").append(
"<br/><input type='button' id='showFieldsToFixBalance' onclick='$(\".fixBalanceAdherentFormPart\").parent().parent().show();' value='Afficher les champs pour corriger le solde'> </input>"
if (!$(".fixBalanceAdherentFormPart").parent().parent().hasClass('has-error')) {
$(".fixBalanceAdherentFormPart").parent().parent().hide();
}
$(".fixBalanceAdherentFormPart").first().parent().parent().before(
"<div class='form-group'><input class='btn btn-primary' type='button' id='showFieldsToFixBalance' value='Afficher les champs pour corriger le solde'></input></div>"
);
$('#showFieldsToFixBalance').on('click', function (e) {
$(".fixBalanceAdherentFormPart").parent().parent().toggle();
});
}
if($(".cancelRecurrentPaymentFormPart").length > 0) {
if (!$(".cancelRecurrentPaymentFormPart").parent().parent().hasClass('has-error')) {
$(".cancelRecurrentPaymentFormPart").parent().parent().hide();
}
// Add descriptive text
$(".cancelRecurrentPaymentFormPart").first().parent().parent().prepend(
`<p class="help-block">${$(".recurrentPaymentReason").first().val()}</p> <p class="help-block">Cette action va indiquer au kohinos que le paiement récurrent Payzen a été résilié manuellement de façon anticipée.</p>`
)
// Add hide/show button with event handler
$(".cancelRecurrentPaymentFormPart").first().parent().parent().before(
"<div class='form-group'><input class='btn btn-primary' type='button' id='showFieldsToCancelRecurringPayment' value='Afficher les champs pour annuler le paiment récurrent en cours'></input></div>"
);
$('#showFieldsToCancelRecurringPayment').on('click', function (e) {
$(".cancelRecurrentPaymentFormPart").parent().parent().toggle();
});
}
});
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.
......@@ -12,7 +12,7 @@
"admin": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/admin.3edfb527.js"
"/build/admin.a08fea06.js"
],
"css": [
"/build/admin.4de55830.css"
......
......@@ -2,7 +2,7 @@
"build/app.css": "/build/app.8a3f698b.css",
"build/app.js": "/build/app.3644f7b2.js",
"build/admin.css": "/build/admin.4de55830.css",
"build/admin.js": "/build/admin.3edfb527.js",
"build/admin.js": "/build/admin.a08fea06.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
"build/images/fa-solid-900.svg": "/build/images/fa-solid-900.a838c42a.svg",
"build/images/fa-brands-400.svg": "/build/images/fa-brands-400.05d20183.svg",
......
......@@ -43,6 +43,7 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
......@@ -396,6 +397,32 @@ class AdherentAdmin extends AbstractAdmin
->end()
->end();
}
if ($reason = $this->tavCotisationUtils->checkExistingRecurringPayment($adherent->getUser()->getEmail())) {
$formMapper
->tab('General')
->with('Informations de cotisation')
->add('recurrentPaymentReason', HiddenType::class, [
'mapped' => false,
'data' => $reason,
'attr' => [
'class' => 'recurrentPaymentReason'
]
])
->add('cancelRecurrentPaymentPassword', TextType::class, [
'label' => 'Mot de passe pour annuler le paiement récurrent',
'mapped' => false,
'required' => false,
'data' => "",
'attr' => [
'autocomplete' => 'off',
'class' => 'cancelRecurrentPaymentFormPart'
],
// 'help' => "Cette action va indiquer au kohinos que le paiement récurrent Payzen a été résilié manuellement de façon anticipée."
])
->end()
->end();
}
}
}
......@@ -426,10 +453,12 @@ class AdherentAdmin extends AbstractAdmin
}
// try to fix balance if required
if($this->security->isGranted('ROLE_SUPER_ADMIN')
if(
$this->security->isGranted('ROLE_SUPER_ADMIN')
&& $event->getForm()->has('fixedBalance')
&& $event->getForm()->get('fixedBalance')->getData()
&& $event->getForm()->get('fixedBalance')->getData() >= 0) {
&& $event->getForm()->get('fixedBalance')->getData() >= 0
) {
$password = $this->getConfigurationPool()->getContainer()->getParameter('fix_balance_adherent_password');
//this password purpose is to be an additional warning for super admin and
//is not intended to be securely stored as only super admin can use this feature
......@@ -444,6 +473,24 @@ class AdherentAdmin extends AbstractAdmin
$em->flush();
}
}
// Cancel recurring payment
if(
$this->security->isGranted('ROLE_SUPER_ADMIN')
&& $event->getForm()->has('cancelRecurrentPaymentPassword')
&& $event->getForm()->get('cancelRecurrentPaymentPassword')->getData()
&& $event->getForm()->get('cancelRecurrentPaymentPassword')->getData() != ''
) {
$password = $this->getConfigurationPool()->getContainer()->getParameter('fix_balance_adherent_password');
//this password purpose is to be an additional warning for super admin and
//is not intended to be securely stored as only super admin can use this feature
if ($event->getForm()->get('cancelRecurrentPaymentPassword')->getData() !== $password) {
$event->getForm()->get('cancelRecurrentPaymentPassword')->addError(new FormError('Mot de passe incorrect.'));
} else {
$this->tavCotisationUtils->cancelExistingRecurringPayment($adherent->getUser()->getEmail());
}
}
}
});
parent::configureFormFields($formMapper);
......
......@@ -129,7 +129,7 @@ class UserAdherentController extends FluxController
*/
private function paiementCotisTavValidation($flux) {
//Look for existing recurring payment
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux)) {
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux->getDestinataire()->getUser()->getEmail())) {
return $reason;
}
......
......@@ -227,11 +227,11 @@ class Payment extends BasePayment
$now = new DateTime();
if ($paymentEndDate && $paymentEndDate < $paymentEndDateDueToExpiry) {
//Compare now with payment end date
$reason = "Paiement récurrent en cours jusqu'à dernière échéance le " . $paymentEndDate->format('d/m/Y') . ".";
$reason = "Paiement récurrent en cours de " . $this.recurrenceAmount() . "€ jusqu'à dernière échéance le " . $paymentEndDate->format('d/m/Y') . ".";
return $now >= $paymentEndDate;
} else {
//Compare now with expiry date
$reason = "Paiement récurrent en cours jusqu'à dernière échéance le " . $paymentEndDateDueToExpiry->format('d/m/Y') . " en raison de l'expiration du moyen de paiement.";
$reason = "Paiement récurrent en cours de " . $this.recurrenceAmount() . "€ jusqu'à dernière échéance le " . $paymentEndDateDueToExpiry->format('d/m/Y') . " en raison de l'expiration du moyen de paiement.";
return $now >= $paymentEndDateDueToExpiry;
}
}
......
......@@ -49,11 +49,16 @@ class TAVCotisationUtils
return count($existing) > 0;
}
public function checkExistingRecurringPayment(Flux $flux)
/**
* Returns a descriptive string of existong payment, or empty string
*
* @param String $userEmail
*/
public function checkExistingRecurringPayment($userEmail)
{
$recurringPayments = $this->em->getRepository(Payment::class)->findBy([
'isRecurrent' => true,
'clientEmail' => $flux->getDestinataire()->getUser()->getEmail(),
'clientEmail' => $userEmail,
]);
$res = "";
......@@ -63,7 +68,7 @@ class TAVCotisationUtils
&& $p->getStatus() !== GetHumanStatus::STATUS_CANCELED
&& $p->getStatus() !== GetHumanStatus::STATUS_EXPIRED
&& $p->getDetails()
&& array_key_exists('vads_identifier',$p->getDetails()) //some payment without vads_identifier have status NEW but are not real recurring payments
&& array_key_exists('vads_identifier',$p->getDetails()) //some payment without vads_identifier have status NEW, which are not valid payments
) {
//Everytime payzen sends a recurring payment notification, notification is
//caught by notifyRecurringPaymentAction, which does not update payment status.
......@@ -308,4 +313,33 @@ class TAVCotisationUtils
return false;
}
/**
* Mark active recurring payment(s) status as canceled.
*
* @param String $userEmail
*/
public function cancelExistingRecurringPayment($userEmail) {
$recurringPayments = $this->em->getRepository(Payment::class)->findBy([
'isRecurrent' => true,
'clientEmail' => $userEmail,
]);
foreach($recurringPayments as $p) {
if (
$p->getStatus() !== GetHumanStatus::STATUS_FAILED
&& $p->getStatus() !== GetHumanStatus::STATUS_CANCELED
&& $p->getStatus() !== GetHumanStatus::STATUS_EXPIRED
&& $p->getDetails()
&& array_key_exists('vads_identifier',$p->getDetails()) //some payment without vads_identifier have status NEW, which are not valid payments
) {
$reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) {
$p->setStatus(GetHumanStatus::STATUS_CANCELED);
$this->em->persist($p);
}
}
}
$this->em->flush();
}
}
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