Commit 502980aa by Damien Moulard

WIP: reccurent payment

parent 58636b48
......@@ -63,14 +63,18 @@ class CaptureAction implements ActionInterface, GatewayAwareInterface, GenericTo
}
// TODO : here ?
// Set recurrent payment data if needed
$payment = $request->getFirstModel();
if ('paiement_recurrent_cotisation_tav' == $payment->getDescription()) { // TODO right way to check type
if (true == $payment->getIsRecurrent()) {
$model['vads_page_action'] = 'REGISTER_PAY_SUBSCRIBE';
$model['vads_sub_amount'] = "1000"; // TODO get params
$model['vads_sub_amount'] = strval($payment->getRecurrenceAmount()); // 1000 for 10.00 EUR
$model['vads_sub_currency'] = $model['vads_currency'];
$model['vads_sub_effect_date'] = (new \DateTime('now', new \DateTimeZone('UTC')))->format('Ymd');
$model['vads_sub_effect_date'] = (new \DateTime('tomorrow', new \DateTimeZone('UTC')))->format('Ymd'); // tomorrow, to avoid duplicate payment this day
$model['vads_sub_desc'] = 'RRULE:FREQ=DAILY;INTERVAL=1;COUNT=2';
// $model['vads_sub_desc'] = 'RRULE:FREQ=MONTHLY;COUNT=12;BYMONTHDAY=10';
// $monthsCount = $payment->getRecurrenceMonthsCount();
// $monthDay = $payment->getRecurrenceMonthDay();
// $model['vads_sub_desc'] = "RRULE:FREQ=MONTHLY;COUNT={$monthsCount};BYMONTHDAY={$monthDay}";
}
}
......
......@@ -126,7 +126,6 @@ class Api
$data = $this
->getRequestOptionsResolver()
->resolve(array_replace($data, [
'vads_page_action' => 'PAYMENT',
'vads_version' => 'V2',
]));
......
......@@ -114,6 +114,13 @@ class PaymentController extends AbstractController
$payment->setClientEmail($this->getUser()->getEmail());
}
if ($type == Payment::TYPE_PAIEMENT_RECURRENT_COTISATION_TAV) {
$payment->setRecurrenceAmount($form->get('montant')->getData() * 100);
$payment->setIsRecurrent(true);
$payment->setRecurrenceMonthsCount($form->get('nombreMois')->getData());
$payment->setRecurrenceMonthDay($form->get('jourPrelevement')->getData());
}
$storage->update($payment);
$captureToken = $this->payum->getTokenFactory()->createCaptureToken(
......
......@@ -56,6 +56,26 @@ class Payment extends BasePayment
protected $extra_data;
/**
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $isRecurrent;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $recurrenceMonthsCount;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $recurrenceMonthDay;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $recurrenceAmount;
/**
* @return string
*/
public function getStatus(): ?string
......@@ -114,4 +134,52 @@ class Payment extends BasePayment
return $this;
}
public function getIsRecurrent(): ?bool
{
return $this->isRecurrent;
}
public function setIsRecurrent(bool $isRecurrent): self
{
$this->isRecurrent = $isRecurrent;
return $this;
}
public function getRecurrenceMonthsCount(): ?int
{
return $this->recurrenceMonthsCount;
}
public function setRecurrenceMonthsCount(?int $recurrenceMonthsCount): self
{
$this->recurrenceMonthsCount = $recurrenceMonthsCount;
return $this;
}
public function getRecurrenceMonthDay(): ?int
{
return $this->recurrenceMonthDay;
}
public function setRecurrenceMonthDay(?int $recurrenceMonthDay): self
{
$this->recurrenceMonthDay = $recurrenceMonthDay;
return $this;
}
public function getRecurrenceAmount(): ?int
{
return $this->recurrenceAmount;
}
public function setRecurrenceAmount(?int $recurrenceAmount): self
{
$this->recurrenceAmount = $recurrenceAmount;
return $this;
}
}
<?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 Version20240321105448 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 payment ADD is_recurrent TINYINT(1) DEFAULT \'0\' NOT NULL, ADD recurrence_months_count INT DEFAULT NULL, ADD recurrence_month_day INT DEFAULT NULL, ADD recurrence_amount INT DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE payment DROP is_recurrent, DROP recurrence_months_count, DROP recurrence_month_day, DROP recurrence_amount');
}
}
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