From f7a7a19d8d4896cd5369a5527cf562b4aa540d0a Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Sun, 1 Mar 2020 06:16:08 +0100 Subject: [PATCH] Fix #7 --- lib/RevBank/Cart.pm | 7 +++++++ lib/RevBank/Messages.pm | 8 +++++--- plugins/idle | 5 ++++- plugins/repeat | 2 +- plugins/users | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/RevBank/Cart.pm b/lib/RevBank/Cart.pm index fd1f19b..6393c78 100644 --- a/lib/RevBank/Cart.pm +++ b/lib/RevBank/Cart.pm @@ -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 { diff --git a/lib/RevBank/Messages.pm b/lib/RevBank/Messages.pm index b8800f4..2b990fa 100644 --- a/lib/RevBank/Messages.pm +++ b/lib/RevBank/Messages.pm @@ -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 { diff --git a/plugins/idle b/plugins/idle index 484e8c5..245df7a 100644 --- a/plugins/idle +++ b/plugins/idle @@ -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); diff --git a/plugins/repeat b/plugins/repeat index 2374f03..a3d3da8 100644 --- a/plugins/repeat +++ b/plugins/repeat @@ -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; } diff --git a/plugins/users b/plugins/users index c919a2f..2ff752a 100644 --- a/plugins/users +++ b/plugins/users @@ -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; }