Skip to content

Commit

Permalink
new: Add a checkbox for renouncing to the right of withdrawal
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Sep 19, 2024
1 parent c002bad commit d7e564a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
4 changes: 4 additions & 0 deletions public/static/style/components/forms/labels.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ label {
color: var(--color-green-gable);
font-weight: bold;
}

.label--normal {
font-weight: normal;
}
14 changes: 14 additions & 0 deletions src/controllers/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public function renew(Request $request): Response
/** @var string */
$tariff = $request->param('tariff', '');

$right_of_withdrawal = $request->paramBoolean('right_of_withdrawal');

if (!\Minz\Csrf::validate($request->param('csrf', ''))) {
return Response::badRequest('subscriptions/init.phtml', [
'contribution_price' => models\Payment::contributionPrice(),
Expand All @@ -113,6 +115,18 @@ public function renew(Request $request): Response
return Response::redirect('account profile');
}

if (!$right_of_withdrawal) {
return Response::badRequest('subscriptions/init.phtml', [
'contribution_price' => models\Payment::contributionPrice(),
'account' => $account,
'amount' => $amount,
'ongoing_payment' => $account->ongoingPayment(),
'errors' => [
'right_of_withdrawal' => 'Vous devez cocher cette case pour continuer',
],
]);
}

if (in_array($tariff, ['solidarity', 'stability', 'contribution'])) {
$preferred_tariff = $tariff;
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/services/InvoicePDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public function createPDF(string $filepath): void
$this->addCustomerInformation($this->customer, $this->GetY());
$this->addPurchases($this->purchases, $this->GetY() + 20);
$this->addTotalPurchases($this->total_purchases, $this->GetY() + 20);
$this->addRenunciationWithdrawalRight($this->GetY() + 60);

// Make sure that the parent directories exist
$dirname = pathinfo($filepath, PATHINFO_DIRNAME);
Expand Down Expand Up @@ -244,6 +245,21 @@ private function addTotalPurchases(array $infos, int $y_position): void
$this->Cell(25, 10, $this->pdfDecode($infos['ttc']), 0, 1);
}

private function addRenunciationWithdrawalRight(int $y_position): void
{
$this->SetY($y_position);
$this->SetFont('', 'I', 11);

$lines = [
'Pour rappel, en vertu de l’article L221-28 du Code de la Consommation, vous avez renoncé à votre droit de',
'rétractation pour bénéficier de votre abonnement à Flus.',
];

foreach ($lines as $line) {
$this->Cell(0, 5, $this->pdfDecode($line), 0, 1);
}
}

// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function Footer(): void
{
Expand Down
33 changes: 16 additions & 17 deletions src/views/subscriptions/init.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,29 @@
</div>

<div class="panel panel--grey panel--rounded flow">
<p class="form-group__caption">
Vous devez accepter les
<a href="<?= url('cgv') ?>" target="_blank" rel="noopener noreferrer nofollow">
Conditions Générales de Vente</a>.
Vous serez ensuite redirigé·e vers le prestataire de paiement
Stripe.
</p>
<?php if (isset($errors['right_of_withdrawal'])): ?>
<p class="form-group__error" id="right-of-withdrawal-error">
Erreur&nbsp;:
<?= $errors['right_of_withdrawal'] ?>
</p>
<?php endif; ?>

<input
id="cgv"
name="accept_cgv"
id="right-of-withdrawal"
name="right_of_withdrawal"
type="checkbox"
required
<?php if (isset($errors['right_of_withdrawal'])): ?>
aria-invalid="true"
aria-errormessage="right-of-withdrawal-error"
<?php endif; ?>
/>

<label for="cgv">
Accepter les Conditions Générales de Vente
<label class="label--normal" for="right-of-withdrawal">
Je renonce expressément à mon droit de rétractation de
14 jours pour les prestations dont je bénéficierais
avant l’écoulement de ce délai
</label>

<?php if (isset($errors['cgv'])): ?>
<p class="form-group__error">
<?= $errors['cgv'] ?>
</p>
<?php endif; ?>
</div>

<div class="text--center">
Expand Down
8 changes: 8 additions & 0 deletions tests/controllers/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function testRenewCreatesAPaymentAndRedirects(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down Expand Up @@ -184,6 +185,7 @@ public function testRenewConsidersManagedAccounts(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down Expand Up @@ -223,6 +225,7 @@ public function testRenewCreatesAcceptsAmountOfZero(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 0,
]);
Expand Down Expand Up @@ -253,6 +256,7 @@ public function testRenewRedirectsIfNoAddress(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down Expand Up @@ -283,6 +287,7 @@ public function testRenewFailsIfExpiresInMoreThanOneMonth(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down Expand Up @@ -317,6 +322,7 @@ public function testRenewFailsIfAmountIsInvalid(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 121,
]);
Expand Down Expand Up @@ -345,6 +351,7 @@ public function testRenewFailsIfNotConnected(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => \Minz\Csrf::generate(),
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down Expand Up @@ -375,6 +382,7 @@ public function testRenewFailsIfCsrfIsInvalid(array $address): void

$response = $this->appRun('POST', '/account/renew', [
'csrf' => 'not the token',
'right_of_withdrawal' => true,
'account_id' => $account->id,
'amount' => 10,
]);
Expand Down

0 comments on commit d7e564a

Please sign in to comment.