From 5e3344bffd51e6870150ef029b75b866fe84452c Mon Sep 17 00:00:00 2001 From: Jess Robinson Date: Mon, 21 Sep 2026 21:27:37 +0100 Subject: [PATCH] Do not close member accounts if we cannot fetch bank transactions --- lib/AccessSystem/Schema/Result/Person.pm | 14 ++++++++++-- script/from_bank.pl | 27 +++++++++++++++++++----- script/membership_payments.pl | 17 ++++++++++++++- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/AccessSystem/Schema/Result/Person.pm b/lib/AccessSystem/Schema/Result/Person.pm index 4eb16bbd..34ce4ed8 100644 --- a/lib/AccessSystem/Schema/Result/Person.pm +++ b/lib/AccessSystem/Schema/Result/Person.pm @@ -524,7 +524,8 @@ Emails are sent for: =cut sub create_payment { - my ($self, $OVERLAP_DAYS) = @_; + my ($self, $OVERLAP_DAYS, $no_new_bank_data) = @_; + $no_new_bank_data ||= 0; my $schema = $self->result_source->schema; my $dt_parser = $schema->storage->datetime_parser; @@ -586,7 +587,7 @@ sub create_payment { } } - if($current_bal < $self->dues) { + if($current_bal < $self->dues ) { # Expanded for fees update 2025: # If previously valid, and payment (intention) is less than dues (which have changed!) # and actually expired (during overlap), convert to donor-tier, fees to 0, store old tier/fees @@ -628,6 +629,7 @@ sub create_payment { warn "Member " . $self->bank_ref . " not covered fees, converted to Donor Tier"; return; } + # Normal fail - intended to pay enough for tier but.. didnt? (Presumably stopped paying) warn "Member " . $self->bank_ref . " balance not enough for another month.\n"; # Remind when actually expired, 5 days into the overlap @@ -637,6 +639,14 @@ sub create_payment { # has (or is about to) expire # this will only send once! my $last = $self->last_payment; + + if($no_new_bank_data) { + # can't determine fail because we didnt get any new bank data + # add a day to last payment expiry if close to expiry: + $last->update({ expires_on_date => $last->expires_on_date->add(days => 1)}); + return; + } + my $expiry = $self->real_expiry($OVERLAP_DAYS); my $paid_date = sprintf("%s, %d %s %d", $last->paid_on_date->day_abbr, diff --git a/script/from_bank.pl b/script/from_bank.pl index 4b43a086..f65b71af 100755 --- a/script/from_bank.pl +++ b/script/from_bank.pl @@ -5,9 +5,26 @@ $ENV{BARCLAYSCRAPE} ||= '/usr/src/extern/barclayscrape'; $ENV{ACCESS_HOME} ||= '/usr/src/extern/hackspace/AccessSystem'; my $today = DateTime->now()->ymd(); -system("$ENV{BARCLAYSCRAPE}/barclayscrape.js --otp $ENV{CODE} get_ofx $ENV{ACCESS_HOME}"); -system("cp 20845883789160.ofx $ENV{ACCESS_HOME}/ofx/$today.ofx"); -system("scp -P 2222 $ENV{ACCESS_HOME}/ofx/$today.ofx castaway\@inside.swindon-makerspace.org:/opt/AccessSystem/ofx/"); -system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/update_payments.pl"'); -system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl"'); +if(-e '20845883789160.ofx') { + my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat('20845883789160.ofx'); + my $dt = DateTime->from_epoch(epoch => $atime); + if($dt->add(days => 1) < DateTime->now()) { + system('rm 20845883789160.ofx'); + } +} +chdir($ENV{BARCLAYSCRAPE}); +system("node barclayscrape.js --no-headless get_ofx $ENV{ACCESS_HOME}"); +chdir($ENV{ACCESS_HOME}); +if(-e '20845883789160.ofx') { + system("cp 20845883789160.ofx $ENV{ACCESS_HOME}/ofx/$today.ofx"); + system("scp -P 2222 $ENV{ACCESS_HOME}/ofx/$today.ofx castaway\@inside.swindon-makerspace.org:/opt/AccessSystem/ofx/"); + system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/update_payments.pl"'); + system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl"'); +} else { + print "NO NEW BANK DATA!\n"; + system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl --no_bank_transactions"'); +} system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/send_communications.pl"'); + diff --git a/script/membership_payments.pl b/script/membership_payments.pl index 37ea31c0..76801e96 100644 --- a/script/membership_payments.pl +++ b/script/membership_payments.pl @@ -7,6 +7,7 @@ use lib "$ENV{CATALYST_HOME}/lib"; use AccessSystem::Schema; use OFX::Parse; +use Getopt::Long; =head1 NAME membership_payments @@ -63,6 +64,20 @@ =head2 TWEAKS die "Please set the CATALYST_HOME environment variable and try again\n"; } +=head2 --no_bank_transactions + +The script is called with this argument if we could not fetch new +transactions from the bank, instead of emailing expir(ed|ing) members +it should add them a day's grace to compensate for our lack of data. + +=cut + +my $no_bank_transactions = 0; +GetOptions( + 'no_bank_transactions' => \$no_bank_transactions, + ); + + my $OVERLAP_DAYS = 14; # Read config to get db connection info: @@ -76,7 +91,7 @@ =head2 TWEAKS my $people_rs = $schema->resultset('Person'); while (my $person = $people_rs->next) { next if $person->parent_id; - $person->create_payment($OVERLAP_DAYS); + $person->create_payment($OVERLAP_DAYS, $no_bank_transactions); } # Update membership table, based on current validity of members: