diff --git a/src/Controller/ContributionController.php b/src/Controller/ContributionController.php index f7f7ca9..baa3150 100644 --- a/src/Controller/ContributionController.php +++ b/src/Controller/ContributionController.php @@ -15,6 +15,7 @@ use DateTime; use DateInterval; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Throwable; use Symfony\Component\Yaml\Yaml; class ContributionController extends AbstractController @@ -40,6 +41,43 @@ public function preferences(Request $request): Response { ]); } + /** + * @Route("/contribute-instellingen/verander-bankrekening", name="member_contribution_preferences_change_bank_account") + */ + public function changeBankAccount(MollieApiClient $mollieApiClient): Response + { + /** @var Member */ + $member = $this->getUser(); + + if ($member->getMollieCustomerId() !== null) + { + $customer = $mollieApiClient->customers->get($member->getMollieCustomerId()); + + if ($member->getMollieSubscriptionId() !== null) + { + $subscription = $mollieApiClient->subscriptions->getFor($customer, $member->getMollieSubscriptionId()); + $subscription->cancel(); + $member->setMollieSubscriptionId(null); + $this->getDoctrine()->getManager()->flush(); + } + + foreach ($customer->mandates()->getIterator() as $mandate) + { + try + { + $mandate->revoke(); + } + catch (Throwable $throwable) + {} + } + } + + $member->setCreateSubscriptionAfterPayment(true); + $this->getDoctrine()->getManager()->flush(); + + return $this->redirectToRoute('member_contribution_pay'); + } + /** * @Route("/contributie-betalen", name="member_contribution_pay") */ diff --git a/templates/user/contribution/automatic-collection.html.twig b/templates/user/contribution/automatic-collection.html.twig index 52c5c9f..2bc83a6 100644 --- a/templates/user/contribution/automatic-collection.html.twig +++ b/templates/user/contribution/automatic-collection.html.twig @@ -39,7 +39,9 @@
Wil je de automatische incasso stopzetten, en in plaats daarvan je contributie handmatig betalen? Klik dan op deze knop.
+ Automatische incasso stopzetten + Instellen met andere bankrekening {% else %}Contributie zal elk kwartaal automatisch van je rekening afgeschreven worden via automatisch incasso. diff --git a/templates/user/details.html.twig b/templates/user/details.html.twig index c5b22bc..0de2d49 100644 --- a/templates/user/details.html.twig +++ b/templates/user/details.html.twig @@ -111,6 +111,7 @@
Automatische incasso stopzetten + Instellen met andere bankrekening {% else %} {% if app.user.contributionCompleted(date()) %}