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, @) {
|
sub command :Tab(deluser) ($self, $cart, $command, @) {
|
||||||
$command eq 'deluser' or return NEXT;
|
$command eq 'deluser' or return NEXT;
|
||||||
|
$cart->size and return REJECT, "Deluser is not available mid-transaction.";
|
||||||
$cart->{_deluser} = 1;
|
|
||||||
|
|
||||||
# Ensure a transaction is triggered by adding one item to the cart.
|
|
||||||
$cart->add(0, "Forfeit remaining balance");
|
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"\n",
|
"\n",
|
||||||
">>> YOU ARE ABOUT TO FORFEIT YOUR BALANCE AND DELETE YOUR ACCOUNT! <<<\n",
|
">>> YOU ARE ABOUT TO FORFEIT YOUR BALANCE AND DELETE YOUR ACCOUNT! <<<\n",
|
||||||
"\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, @) {
|
sub deluser_account($self, $cart, $account, @) {
|
||||||
return if not defined $cart->{_deluser};
|
|
||||||
|
|
||||||
my $amount = RevBank::Accounts::balance($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."
|
return ABORT, "Can not delete an account with a negative balance."
|
||||||
if ($amount < 0);
|
if ($amount < 0);
|
||||||
|
|
||||||
|
$cart->{_deluser} = 1;
|
||||||
$cart
|
$cart
|
||||||
->add(-$amount, "Forfeit remaining balance")
|
->add(-$amount, "Forfeit remaining balance")
|
||||||
->add_contra($contra, +$amount, "Delete account \$you");
|
->add_contra($contra, +$amount, "Delete account \$you");
|
||||||
|
$cart->checkout($account);
|
||||||
|
|
||||||
# Not having this bare return here results in "returned an unsupported value". The returned
|
return ACCEPT;
|
||||||
# value seems to be a cart entry? Why?
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
|
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue