Add 'void' command

This commit is contained in:
Juerd Waalboer 2023-01-19 05:25:31 +01:00
parent f479060576
commit 10d1965bf0
6 changed files with 128 additions and 9 deletions

View file

@ -5,8 +5,9 @@ products - RevBank plugin for selling products
=head1 SYNOPISIS
8710447032756 0.80 Festini Peer
4029764001807,clubmate 1.40 Club-Mate +pf
4029764001807,clubmate 1.40 Club-Mate +half +pf
pf 0.15@+pfand Pfand NRW-Flasche
+half -50% 50% discount \o/
=head1 DESCRIPTION

View file

@ -1,12 +1,11 @@
#!perl
# TODO:
# voiding of tokens
# querying of tokens
# expiry of tokens
use List::Util;
HELP void => "Destroy deposit tokens";
my $ttl = 100 * 86400; # expiry time in seconds
my $filename = "revbank.statiegeld";
@ -159,6 +158,9 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
$entry->quantity($available);
$warnings_by_type{$type}++;
}
if ($entry->attribute('statiegeld_VOID_TOKENS')) {
$cart->delete($entry);
}
splice @{ $tokens_by_type->{$type} }, 0, $entry->quantity;
$tokens_changed++;
@ -197,3 +199,33 @@ sub hook_user_info ($class, $username, @) {
@info = ("none") if not @info;
print "Deposit tokens: ", join(", ", @info), "\n";
}
sub command($self, $cart, $command, @) {
$command eq 'void' or return NEXT;
my $found =0;
for my $entry ($cart->entries('plugin')) {
next if $entry->attribute('plugin') ne 'statiegeld';
$found++;
}
$found or return REJECT, "Add deposit returns first.";
return "\e[31;1mDeposit token destruction mode.\e[0m\n\n"
. "The tokens will be deleted irrevokably and you will NOT RECEIVE THE MONEY.\n"
. "Type 'yes' if you are sure", \&void;
}
sub void :Tab(yes,no) ($self, $cart, $input, @) {
if ($input ne 'yes') {
print "Destruction cancelled.\n";
return ACCEPT;
}
for my $entry ($cart->entries('plugin')) {
next if $entry->attribute('plugin') ne 'statiegeld';
$entry->attribute('statiegeld_VOID_TOKENS', 1);
}
print "\e[31;1mDeposit token destruction mode activated.\e[0m\n";
return ACCEPT;
}