Fix #7
This commit is contained in:
parent
31a1aa5c45
commit
f7a7a19d8d
5 changed files with 18 additions and 6 deletions
|
@ -75,6 +75,12 @@ sub size {
|
|||
sub checkout {
|
||||
my ($self, $user) = @_;
|
||||
|
||||
if ($self->entries('refuse_checkout')) {
|
||||
warn "Refusing to finalize deficient transaction.\n";
|
||||
$self->display;
|
||||
return;
|
||||
}
|
||||
|
||||
my $entries = $self->{entries};
|
||||
|
||||
my %deltas;
|
||||
|
@ -98,6 +104,7 @@ sub checkout {
|
|||
$self->empty;
|
||||
|
||||
sleep 1; # Ensure new timestamp/id for new transaction
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub entries {
|
||||
|
|
|
@ -27,9 +27,11 @@ sub hook_cart_changed {
|
|||
say "Pending:";
|
||||
$cart->display;
|
||||
|
||||
my $sum = $cart->sum;
|
||||
my $what = $sum > 0 ? "add %.2f" : "pay %.2f";
|
||||
say sprintf "Enter username to $what; type 'abort' to abort.", abs $sum;
|
||||
if (not $cart->entries('refuse_checkout')) {
|
||||
my $sum = $cart->sum;
|
||||
my $what = $sum > 0 ? "add %.2f" : "pay %.2f";
|
||||
say sprintf "Enter username to $what; type 'abort' to abort.", abs $sum;
|
||||
}
|
||||
}
|
||||
|
||||
sub hook_abort {
|
||||
|
|
|
@ -18,7 +18,10 @@ sub hook_prompt_idle {
|
|||
$readline->replace_line("");
|
||||
$readline->redisplay;
|
||||
|
||||
print "\e[33;2;1mTransaction incomplete.\e[0m Enter username to pay/finish or 'abort' to abort.\n";
|
||||
my $help = $cart->entries('refuse_checkout')
|
||||
? "Enter 'abort' to abort."
|
||||
: "Enter username to pay/finish or 'abort' to abort.";
|
||||
print "\e[33;2;1mTransaction incomplete.\e[0m $help\n";
|
||||
|
||||
$readline->restore_prompt;
|
||||
$readline->replace_line($text);
|
||||
|
|
|
@ -46,7 +46,7 @@ sub command {
|
|||
|
||||
return REJECT, $err_limit if $pre > $limit;
|
||||
$cart
|
||||
->add(0, "? (The next thing you add will be multiplied.)", { _repeat => 1 })
|
||||
->add(0, "? (The next thing you add will be multiplied.)", { _repeat => 1, refuse_checkout => 1 })
|
||||
->quantity($pre);
|
||||
return ACCEPT;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ sub command :Tab(list,ls,shame,USERS) {
|
|||
|
||||
return $self->balance($user) if not $cart->size;
|
||||
|
||||
$cart->checkout($user);
|
||||
$cart->checkout($user) or return REJECT, "Checkout failed.";
|
||||
|
||||
return ACCEPT;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue