Skip to content

Commit

Permalink
Add membership cancellation for Mollie (#200)
Browse files Browse the repository at this point in the history
Very primitive way of cancelling subscriptions. Not a fancy
solution but given the urgency I opted for a lesser-than-ideal
approach.
  • Loading branch information
rrooij authored Jul 18, 2024
1 parent adfcd00 commit 794a192
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

use Symfony\Component\HttpFoundation\{ BinaryFileResponse, ResponseHeaderBag };
use Mollie\Api\MollieApiClient;

use Symfony\Component\HttpFoundation\{ BinaryFileResponse, ResponseHeaderBag, Response };
use DateTime;

class MemberCrud extends AbstractCrudController
Expand Down Expand Up @@ -66,8 +68,30 @@ public function configureActions(Actions $actions): Actions {
->linkToCrudAction('export')
->setCssClass('btn btn-secondary')
->createAsGlobalAction();
$actions->add(Crud::PAGE_INDEX, $action);
$contributionEnabled = $this->getParameter('app.contributionEnabled');
if ($contributionEnabled) {
$actionCancelMollie = Action::new('cancel', 'Lidmaatschap stoppen', 'fa fa-dollar-sign')
->linkToCrudAction('cancelMembership')
->setCssClass('btn btn-secondary');
$actions->add(Crud::PAGE_EDIT, $actionCancelMollie);
}
return $actions;
}

return $actions->add(Crud::PAGE_INDEX, $action);
public function cancelMembership(AdminContext $adminContext, MollieApiClient $mollieApiClient): Response
{
$member = $adminContext->getEntity()->getInstance();
if ($member->getMollieSubscriptionId() === null)
{
return new Response('Membership already cancelled');
}
$customer = $mollieApiClient->customers->get($member->getMollieCustomerId());
$subscription = $mollieApiClient->subscriptions->getFor($customer, $member->getMollieSubscriptionId());
$subscription->cancel();
$member->setMollieSubscriptionId(null);
$em->flush();
return new Response('Membership cancelled succesfully');
}

public function export(AdminContext $adminContext): BinaryFileResponse
Expand Down

0 comments on commit 794a192

Please sign in to comment.