revbank/plugins/revspace_saldo
Juerd Waalboer eed0db7897 Cleanup: use subroutine signatures, remove deprecated methods.
The signatures feature has been "experimental" since Perl 5.20 (May 2014), but
expected to stay. After 8 years I'm ready to take the risk :)

Have added Perl v5.28 (June 2018) as the minimum requirement, even though the
current revbank should work with 5.20, to see if this bothers any users. Perl
v5.28 is in Debian "buster", which is now oldstable.
2021-12-03 18:00:34 +01:00

44 lines
1.2 KiB
Perl

#!perl
use POSIX qw(strftime);
sub _box(@lines) {
print(
"#" x 79, "\n",
(map { sprintf("## %-73s ##\n", $_) } @lines),
"#" x 79, "\n"
);
}
sub hook_checkout_done($class, $cart, $user, $transaction_id, @) {
defined $user or return; # hacks like 'undo' don't have an acting user
my $balance = RevBank::Users::balance($user) or return;
my $since = RevBank::Users::since($user);
if ($balance < -13.37) {
_box(
"Hoi $user,",
"",
"Je saldo is $balance en dus lager dan toegestaan. Graag meteen aanvullen!",
"Zodra je een positief saldo hebt, mag je weer producten kopen.",
"",
"Bedankt!",
"-- Het bestuur",
);
} elsif (
defined $since
and $since =~ /^-\@(.*)/
and $1 lt strftime('%Y-%m-%d_%H:%M:%S', localtime(time() - 14 * 86400))
) {
_box(
"Hoi $user,",
"",
"Je staat al sinds $1 negatief, dus meer dan 2 weken. Deelnemers",
"mogen rood staan, maar niet langdurig. Wil je je saldo even aanvullen?",
"",
"Bedankt!",
"-- Het bestuur",
);
}
}