deluser: Avoid a dummy transaction
This commit is contained in:
parent
9f34c00033
commit
be4abcb9dc
1 changed files with 8 additions and 13 deletions
21
deluser
21
deluser
|
@ -8,37 +8,32 @@ 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");
|
||||
$cart->size and return REJECT, "Deluser is not available mid-transaction.";
|
||||
|
||||
print(
|
||||
"\n",
|
||||
">>> YOU ARE ABOUT TO FORFEIT YOUR BALANCE AND DELETE YOUR ACCOUNT! <<<\n",
|
||||
"\n",
|
||||
"Type your name to finish.\n"
|
||||
);
|
||||
|
||||
return ACCEPT;
|
||||
return "Type your name to finish", \&deluser_account;
|
||||
}
|
||||
|
||||
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
|
||||
return if not defined $cart->{_deluser};
|
||||
|
||||
sub deluser_account($self, $cart, $account, @) {
|
||||
my $amount = RevBank::Accounts::balance($account);
|
||||
|
||||
return ABORT, "No such account: $account."
|
||||
if not defined $amount;
|
||||
return ABORT, "Can not delete an account with a negative balance."
|
||||
if ($amount < 0);
|
||||
|
||||
$cart->{_deluser} = 1;
|
||||
$cart
|
||||
->add(-$amount, "Forfeit remaining balance")
|
||||
->add_contra($contra, +$amount, "Delete account \$you");
|
||||
$cart->checkout($account);
|
||||
|
||||
# Not having this bare return here results in "returned an unsupported value". The returned
|
||||
# value seems to be a cart entry? Why?
|
||||
return;
|
||||
return ACCEPT;
|
||||
}
|
||||
|
||||
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue