From 03c421bc4b37ac3fb31daff77efd2ba1667fd03d Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Fri, 1 May 2026 12:08:46 +0100 Subject: [PATCH] Move email sending until after payment has been created Fix bug: update_door_access needs an is_admin value --- lib/AccessSystem/Schema/Result/Allowed.pm | 1 + lib/AccessSystem/Schema/Result/Person.pm | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/AccessSystem/Schema/Result/Allowed.pm b/lib/AccessSystem/Schema/Result/Allowed.pm index 7acc781..7d75b4f 100644 --- a/lib/AccessSystem/Schema/Result/Allowed.pm +++ b/lib/AccessSystem/Schema/Result/Allowed.pm @@ -24,6 +24,7 @@ __PACKAGE__->add_columns( }, is_admin => { data_type => 'boolean', + default_value => 'false', }, pending_acceptance => { data_type => 'boolean', diff --git a/lib/AccessSystem/Schema/Result/Person.pm b/lib/AccessSystem/Schema/Result/Person.pm index 295a551..4eb16bb 100644 --- a/lib/AccessSystem/Schema/Result/Person.pm +++ b/lib/AccessSystem/Schema/Result/Person.pm @@ -666,14 +666,7 @@ sub create_payment { $self->create_communication('Your Swindon Makerspace membership has started', 'first_payment'); } - if($valid_date && $valid_date < $now) { - # renewed payments - force this one, should happen everytime - $self->create_communication('Your Swindon Makerspace membership has restarted', 'rejoin_payment', {}, 1); - # rejoined, so remove any "reminder" email, so that if they - # subsequently stop paying again, they get a new reminder (!) - my $r_email = $self->communications_rs->find({type => 'reminder_email'}); - $r_email->delete if $r_email; - } + my $is_rejoining = $valid_date && $valid_date < $now ? 1 : 0; # Only add $OVERLAP extra days if a first or renewal payment - these # ensure member remains valid if standing order is not an @@ -705,7 +698,15 @@ sub create_payment { paid_on_date => $now, expires_on_date => $expires_on, amount_p => $payment_size, - }); + }); + if ($is_rejoining) { + # renewed payments - force this one, should happen everytime + $self->create_communication('Your Swindon Makerspace membership has restarted', 'rejoin_payment', {}, 1); + # rejoined, so remove any "reminder" email, so that if they + # subsequently stop paying again, they get a new reminder (!) + my $r_email = $self->communications_rs->find({type => 'reminder_email'}); + $r_email->delete if $r_email; + } }); return 1; } @@ -954,7 +955,7 @@ sub update_door_access { # This entry should exist, but covid policy may have removed it.. my $door = $self->result_source->schema->the_door(); - my $door_allowed = $self->allowed->find_or_create({ tool_id => $door->id }); + my $door_allowed = $self->allowed->find_or_create({ tool_id => $door->id, is_admin => 0 }); $door_allowed->update({ pending_acceptance => 'false', accepted_on => DateTime->now()}); }