Skip to content

Commit 3f1f6eb

Browse files
committed
Fix /pay, output success/fail message as a reply (not a popup!)
Also: Allow members to go negative up to £5 (and warn)
1 parent c3dd8e3 commit 3f1f6eb

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/AccessSystem/Schema/Result/Person.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,14 @@ sub add_debit {
601601
}
602602
if($amount =~/\D/) {
603603
return (0, 'Amount must be a positive integer of pence');
604-
} elsif($self->balance_p < $amount) {
604+
} elsif($self->balance_p + 400 < $amount) {
605605
return (0, 'Not enough money for that transaction');
606606
} else {
607607
my $tr = $self->create_related('transactions', {
608608
reason => $reason,
609609
amount_p => -1*$amount,
610610
});
611-
611+
612612
return (1, 'Success', $self->balance_p);
613613
}
614614
}

lib/AccessSystem/TelegramBot.pm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,17 @@ sub pay ($self, $text, $message, $args = undef) {
10041004
} elsif ($args->[1] eq 'cancel') {
10051005
## ended selections - cancel whole thing
10061006
delete $self->waiting_on_response->{$message->from->id};
1007-
return $message->answer('Canceled');
1007+
return $message->reply('Cancelled');
10081008
} elsif ($args->[1] eq 'pay') {
10091009
## ended selections create transaction
10101010
delete $self->waiting_on_response->{$message->from->id};
1011-
my ($status, $msg) = $member->add_debit($waiting->{total},
1012-
join(",",@{$waiting->{products}}));
1013-
return $message->answer($msg);
1011+
my ($status, $msg, $bal) = $member->add_debit(
1012+
$waiting->{total},
1013+
join(",",@{$waiting->{products}}));
1014+
if($bal < 0) {
1015+
$msg = 'Paid: Your balance is now negative, £5 is the maximum you can go below 0, please pay some in. Use /balance to check.';
1016+
}
1017+
return $message->reply($msg);
10141018
}
10151019
} else {
10161020
$self->waiting_on_response->{$message->from->id} = {

0 commit comments

Comments
 (0)