revbank/plugins/unlisted
2023-04-12 16:19:04 +02:00

34 lines
1.1 KiB
Perl

#!perl
HELP1 "unlisted" => "Buy unlisted product (manual entry)";
sub command :Tab(unlisted,donate) ($self, $cart, $command, @) {
$command eq 'unlisted' or $command eq 'donate' or return NEXT;
$self->{command} = $command;
my $prompt = $command eq 'donate' ? 'Amount' : 'Price';
return $prompt, \&amount;
}
sub amount($self, $cart, $arg, @) {
$self->{amount} = parse_amount($arg) or return REJECT, "Invalid amount.";
if ($self->{command} eq 'donate') {
return "Message ('x' for no message)", sub($self, $cart, $desc, @) {
$desc = $desc eq 'x' ? "" : " ($desc)";
$cart
->add(-$self->{amount}, "Donation$desc - THANK YOU!")
->add_contra("+donations", +$self->{amount}, "Donation by \$you");
return ACCEPT;
}
}
return "Please provide a short description", sub($self, $cart, $desc, @) {
$cart
->add(-$self->{amount}, "Unlisted: $desc")
->add_contra("+sales/unlisted", +$self->{amount}, "Unlisted: $desc by \$you");
return ACCEPT;
};
}