diff --git a/public/static/style/components/forms/labels.css b/public/static/style/components/forms/labels.css index 0a48af83..6d992d7a 100644 --- a/public/static/style/components/forms/labels.css +++ b/public/static/style/components/forms/labels.css @@ -2,3 +2,7 @@ label { color: var(--color-green-gable); font-weight: bold; } + +.label--normal { + font-weight: normal; +} diff --git a/src/controllers/Subscriptions.php b/src/controllers/Subscriptions.php index d4444448..768b2f12 100644 --- a/src/controllers/Subscriptions.php +++ b/src/controllers/Subscriptions.php @@ -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(), @@ -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 { diff --git a/src/services/InvoicePDF.php b/src/services/InvoicePDF.php index 6832efec..7748808e 100644 --- a/src/services/InvoicePDF.php +++ b/src/services/InvoicePDF.php @@ -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); @@ -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 { diff --git a/src/views/subscriptions/init.phtml b/src/views/subscriptions/init.phtml index dfb269ae..d9a5bb73 100644 --- a/src/views/subscriptions/init.phtml +++ b/src/views/subscriptions/init.phtml @@ -198,30 +198,29 @@
-

- Vous devez accepter les - - Conditions Générales de Vente. - Vous serez ensuite redirigé·e vers le prestataire de paiement - Stripe. -

+ +

+ Erreur : + +

+ + aria-invalid="true" + aria-errormessage="right-of-withdrawal-error" + /> -
diff --git a/tests/controllers/SubscriptionsTest.php b/tests/controllers/SubscriptionsTest.php index c8443c1a..87e8c4aa 100644 --- a/tests/controllers/SubscriptionsTest.php +++ b/tests/controllers/SubscriptionsTest.php @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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, ]); @@ -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, ]);