49 lines
1.3 KiB
Perl
49 lines
1.3 KiB
Perl
#!perl
|
|
|
|
use List::Util qw(any);
|
|
|
|
HELP1 "deluser <name>" => "Delete an account";
|
|
|
|
my $contra = "+donations";
|
|
|
|
sub command :Tab(deluser) ($self, $cart, $command, @) {
|
|
$command eq 'deluser' or return NEXT;
|
|
|
|
$cart->{_deluser} = 1;
|
|
|
|
# Ensure a transaction is triggered by adding one item to the cart.
|
|
$cart->add(0, "Forfeit remaining balance");
|
|
|
|
print(
|
|
"\n",
|
|
">>> YOU ARE ABOUT TO FORFEIT YOUR BALANCE AND DELETE YOUR ACCOUNT! <<<\n",
|
|
"\n",
|
|
"Type your name to finish.\n"
|
|
);
|
|
|
|
return ACCEPT;
|
|
}
|
|
|
|
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
|
|
return if not defined $cart->{_deluser};
|
|
|
|
my $amount = RevBank::Accounts::balance($account);
|
|
|
|
return ABORT, "Can not delete an account with a negative balance."
|
|
if ($amount < 0);
|
|
|
|
$cart
|
|
->add(-$amount, "Forfeit remaining balance")
|
|
->add_contra($contra, +$amount, "Delete account \$you");
|
|
|
|
# Not having this bare return here results in "returned an unsupported value". The returned
|
|
# value seems to be a cart entry? Why?
|
|
return;
|
|
}
|
|
|
|
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
|
|
return if not defined $cart->{_deluser};
|
|
|
|
RevBank::Accounts::delete($account);
|
|
print "\nAccount $account deleted.\n";
|
|
}
|