Commit a4fcb34f by Yvon

A TESTER : check for existing not ended and not expired recurring payment : warn…

A TESTER : check for existing not ended and not expired recurring payment : warn user and block new payment if exists
parent 8ac275d6
...@@ -128,6 +128,11 @@ class UserAdherentController extends FluxController ...@@ -128,6 +128,11 @@ class UserAdherentController extends FluxController
* Returns error message or null if no error. * Returns error message or null if no error.
*/ */
private function paiementCotisTavValidation($flux) { private function paiementCotisTavValidation($flux) {
//Look for existing recurring payment
if($reason = $this->tavCotisationsUtils->checkExistingRecurringPayment($flux)) {
return $reason;
}
// Look for existing cotisation // Look for existing cotisation
if ($this->tavCotisationsUtils->checkExistingCotisation($flux)) { if ($this->tavCotisationsUtils->checkExistingCotisation($flux)) {
return "Cotisation déjà payée ce mois-ci."; return "Cotisation déjà payée ce mois-ci.";
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Entity; namespace App\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Payum\Core\Model\Payment as BasePayment; use Payum\Core\Model\Payment as BasePayment;
use Ramsey\Uuid\Doctrine\UuidGenerator; use Ramsey\Uuid\Doctrine\UuidGenerator;
...@@ -182,4 +183,53 @@ class Payment extends BasePayment ...@@ -182,4 +183,53 @@ class Payment extends BasePayment
return $this; return $this;
} }
/**
* Return null in case of error
* Returns true if payment is already ended or CB expired
* Returns false otherwise
*
* @param $reason
* @return bool|null
*/
public function isRecurringPaymentEndedOrExpired(&$reason)
{
if(!$this->details
|| !array_key_exists('vads_effective_creation_date',$this->details)
|| !array_key_exists('vads_expiry_year',$this->details)
|| !array_key_exists('vads_effective_creation_date',$this->details)
) {
$reason = "Attribut détails vide ou clés absentes.";
return null;
}
$firstDayOfcreationMonth = DateTime::createFromFormat(
'YMd',substr($this->details,0,6) . "01"
);
$day = $this->getRecurrenceMonthDay() ? $this->getRecurrenceMonthDay() - 1 : 0; //if not set assume first day of month (not a big deal anyway)
$dateOfFirstOccurenceAfterInitialPayment = $firstDayOfcreationMonth->modify(
$day . " days next month"
);
$paymentEndDate = $this->getRecurrenceMonthsCount() ?
$dateOfFirstOccurenceAfterInitialPayment->modify(
"+" . ($this->getRecurrenceMonthsCount() - 1) //minus one because initial payment is not considered by payzen as the first occurence
)
: null; //assume no end date if recurrenceMonthsCount not set
//Now check expiry date
$expiryDate = DateTime::createFromFormat(
'Ym',$this->details['vads_expiry_year'] . $this->details['vads_expiry_month']
);
$now = new DateTime();
if($paymentEndDate && $paymentEndDate < $expiryDate) {
//Compare now with payment end date
$reason = "Dernière échéance le : " . $paymentEndDate->format('d/m/Y');
return $now >= $paymentEndDate;
} else {
//Compare now with expiry date
$reason = "Expiration du moyen de paiement le : " . $expiryDate->format('d/m/Y');
return $now >= $expiryDate;
}
}
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Utils; namespace App\Utils;
use App\Entity\Adherent; use App\Entity\Adherent;
use App\Entity\Payment;
use App\Entity\Siege; use App\Entity\Siege;
use App\Entity\Flux; use App\Entity\Flux;
use App\Entity\CotisationTavReversement; use App\Entity\CotisationTavReversement;
...@@ -44,6 +45,23 @@ class TAVCotisationUtils ...@@ -44,6 +45,23 @@ class TAVCotisationUtils
return count($existing) > 0; return count($existing) > 0;
} }
public function checkExistingRecurringPayment(Flux $flux)
{
$recurringPayments = $this->em->getRepository(Payment::class)->findBy([
'isRecurrent' => true,
'clientEmail' => $flux->getDestinataire()->getUser()->getEmail(),
]);
$res = "";
foreach($recurringPayments as $p) {
$reason = "";
if($p->isRecurringPaymentEndedOrExpired($reason) !== true) {
$res .= ($reason . " ");
}
}
return $res;
}
/** /**
* First method to calculate allowance: * First method to calculate allowance:
* according to a contribution rate defined in user's profile (ProfilDeCotisation). * according to a contribution rate defined in user's profile (ProfilDeCotisation).
......
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