
Undoes 714b337
because github seems to no longer require chmod +x
for syntax highlighting extensionless files.
95 lines
2.4 KiB
Perl
95 lines
2.4 KiB
Perl
#!perl
|
|
|
|
# This plugin must at the end in the plugins file.
|
|
|
|
HELP "deposit <amount>" => "Deposit into an account";
|
|
|
|
sub command :Tab(deposit) {
|
|
my ($self, $cart, $command) = @_;
|
|
|
|
if ($command eq 'deposit') {
|
|
return "Amount to deposit into your account", \&amount;
|
|
}
|
|
|
|
if ($cart->select_items('is_deposit')) {
|
|
# No other plugin recognised the input, so it must be a new user.
|
|
$self->{new_user} = $command;
|
|
|
|
my $x = RevBank::Plugin::adduser->can("command")
|
|
? "Please use \e[4madduser\e[0m instead."
|
|
: "Please enable the \e[4madduser\e[0m plugin.";
|
|
warn "Creating accounts with \e[4mdeposit\e[m is deprecated. $x\n";
|
|
|
|
return "Add new account for user '$command'?", \&create;
|
|
}
|
|
|
|
return NEXT;
|
|
}
|
|
|
|
sub amount :Tab(13.37,42) {
|
|
my ($self, $cart, $amount) = @_;
|
|
|
|
$self->{amount} = parse_amount($amount)
|
|
or return REJECT, "Invalid amount";
|
|
|
|
call_hooks("deposit_methods", \my $message, $self->{deposit_methods} = {});
|
|
|
|
return $message . "How are we receiving this EUR $amount?", \&how
|
|
if keys %{ $self->{deposit_methods} };
|
|
|
|
$cart->add(undef, +$self->{amount}, "Deposit", { is_deposit => 1 });
|
|
return ACCEPT;
|
|
}
|
|
|
|
sub how :Tab(&how_tab) {
|
|
my ($self, $cart, $input) = @_;
|
|
|
|
my %methods = %{ $self->{deposit_methods} };
|
|
|
|
my $how = $self->{how} = $methods{$input}
|
|
or return REJECT, "'$input' is not a valid answer.";
|
|
|
|
$how->{_key} = $input;
|
|
|
|
if (@{ $how->{prompts} // [] }) {
|
|
return shift @{ $how->{prompts} }, \&how_prompt;
|
|
}
|
|
|
|
$cart->add(undef, +$self->{amount}, $how->{description}, { is_deposit => 1, method => $how->{_key} });
|
|
return ACCEPT;
|
|
}
|
|
|
|
sub how_tab {
|
|
my ($self) = @_;
|
|
return keys %{ $self->{deposit_methods} };
|
|
}
|
|
|
|
sub how_prompt {
|
|
my ($self, $cart, $input) = @_;
|
|
|
|
my $how = $self->{how};
|
|
|
|
push @{ $how->{answers} }, $input;
|
|
|
|
if (@{ $how->{prompts} }) {
|
|
return shift @{ $how->{prompts} }, \&how_prompt;
|
|
}
|
|
|
|
my $desc = sprintf $how->{description}, @{ $how->{answers} };
|
|
|
|
$cart->add(undef, +$self->{amount}, $desc, { is_deposit => 1, method => $how->{_key} });
|
|
return ACCEPT;
|
|
}
|
|
|
|
sub create :Tab(yes,no) {
|
|
my ($self, $cart, $yesno) = @_;
|
|
my $user = $self->{new_user};
|
|
|
|
if ($yesno eq "y" or $yesno eq "yes") {
|
|
RevBank::Users::create( $user );
|
|
$cart->checkout( $user );
|
|
return ACCEPT;
|
|
}
|
|
return ABORT;
|
|
}
|
|
|