Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contribution): added option to change the amount of the subscription. #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Controller/ContributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ public function payContribution(Request $request, MollieApiClient $mollieApiClie
return $this->redirect($molliePayment->getCheckoutUrl(), 303);
}

/**
* @Route("/contributie-aanpassen", name="member_contribution_change_amount")
*/
public function changeContributionAmount(Request $request, MollieApiClient $mollieApiClient, bool $automaticCollection = false): Response
{
$member = $this->getUser();

$mollieCustomerId = $member->getMollieCustomerId();
$contributionAmount = $member->getContributionPerPeriodInEuros();
$subscriptionId = $member->getMollieSubscriptionId();
// update subscription amount
$updatedSubscription = $mollieApiClient->subscriptions->update($mollieCustomerId, $subscriptionId, [
'amount' => [
'currency' => 'EUR',
'value' => number_format($contributionAmount, 2, '.', '')
]
]);

return $this->redirectToRoute('member_details');
}

/**
* @Route("/api/webhook/mollie-contribution", name="member_contribution_mollie_webhook")
*/
Expand Down Expand Up @@ -229,6 +250,38 @@ public function automaticCollection(Request $request, LoggerInterface $logger):
]);
}

/**
* @Route("/automatische-incasso-aanpassen", name="member_contribution_automatic_collection_change_amount")
*/
public function automaticCollectionChangeAmount(Request $request, LoggerInterface $logger): Response
{
$projectRoot = $this->getParameter('kernel.project_dir');
$org_config = Yaml::parseFile($projectRoot . '/config/instances/' . $this->getParameter('app.organizationID') . '.yaml');

$form = $this->createForm(ContributionIncomeType::class, null, [
'contribution' => $org_config['contribution']
]);

$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$member = $this->getUser();
$member->setContributionPerPeriodInCents($form->getData());
$member->setContributionPeriod(Member::PERIOD_QUARTERLY);
$em->flush();

return $this->redirectToRoute('member_contribution_change_amount');
}

return $this->render('user/contribution/automatic-collection-change.html.twig', [
'success' => false,
'form' => $form->createView(),
'contribution' => $org_config['contribution'],
// The user is currently setting up contribution, so setting this false disables the contribution nagbar
'contributionEnabled' => false,
]);
}

/**
* @Route("/automatische-incasso/inschakelen", name="member_contribution_automatic_collection_enable")
*/
Expand Down
91 changes: 91 additions & 0 deletions templates/user/contribution/automatic-collection-change.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{% extends 'user/layout/members.html.twig' %}

{% block scripts %}
{{ parent() }}
<script>
function updateContribution() {
let other = document.querySelector('.other-amount');
if (document.querySelector('.choice :checked').value !== 0) {
other.value = '';
}
}
function updateOtherAmount() {
let other = document.querySelector('.other-amount');
if (other.value != '')
{
document.querySelector('.choice [value="0"]').checked = true;
}
}
document.addEventListener('change', e => {
if (e.target.closest) {
if (e.target.closest('.other-amount')) {
updateOtherAmount();
} else if (e.target.closest('.choices')) {
updateContribution();
}
}
})
</script>
{% endblock %}

{% block content %}
<div class="main-content">
<h1>Automatische incasso</h1>
<p>
Contributie zal elk kwartaal automatisch van je rekening afgeschreven worden via automatisch incasso.
Hoeveel je hierbij betaalt hangt af van je inkomen.
</p>

{% if contribution.tiers|length > 2 %}
<table class="table">
<thead>
<tr>
<th>Maandinkomen</th>
<th>Contributie</th>
</tr>
</thead>
<tbody>
{% for tier in contribution.tiers %}
{% if tier.amount is not same as(null) %}
<tr>
<td>{{ tier.description }}</td>
<td>€{{ (tier.amount / 100)|number_format(2, ',') }} per kwartaal (€{{ (tier.amount / 100 / 3)|number_format(2, ',') }} per maand)</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}

{% if form.vars.submitted and not form.vars.valid %}
<div class="error">
{{ form_errors(form) }}
</div>
{% endif %}

<p>
Selecteer wat er voor jou van toepassing is:
</p>
{{ form_start(form, { attr: { class: 'incomes' }}) }}
{{ form_row(form._token) }}

<div class="choices">
{% for option in form.contributionAmount %}
<div class="choice">
{{ form_widget(option) }}
<div class="choice-text">
{{ form_label(option, null, { required: false }) }}
{% if option.vars.value == 0 %}
<br />
{{ form_widget(form.otherAmount, { attr: { class: 'other-amount' } }) }} per kwartaal
{% endif %}
</div>
</div>
{% endfor %}
</div>

<button type="submit" class="button submit-button">Incasso bedrag aanpassen</button>
{{ form_end(form, {render_rest: false}) }}

</div>
{% endblock %}
1 change: 1 addition & 0 deletions templates/user/contribution/automatic-collection.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<a href="{{ url('member_contribution_automatic_collection_disable') }}" class="button">Automatische incasso stopzetten</a>
<a href="{{ url('member_contribution_preferences_change_bank_account') }}" class="button">Instellen met andere bankrekening</a>
<a href="{{ url('member_contribution_automatic_collection_change_amount') }}" class="button">Incasso bedrag aanpassen</a>
{% else %}
<p>
Contributie zal elk kwartaal automatisch van je rekening afgeschreven worden via automatisch incasso.
Expand Down
1 change: 1 addition & 0 deletions templates/user/details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

<a class="action-link" href="{{ url('member_contribution_automatic_collection') }}">Automatische incasso stopzetten</a>
<a class="action-link" href="{{ url('member_contribution_preferences_change_bank_account') }}" class="button">Instellen met andere bankrekening</a>
<a class="action-link" href="{{ url('member_contribution_automatic_collection_change_amount') }}">Incasso bedrag aanpassen</a>
{% else %}
{% if app.user.contributionCompleted(date()) %}
<p>
Expand Down
Loading