my ($session, $message) = @_;
my $config = $session->config;
- my $fee_type = $message->fixed_fields[1];
- my $pay_type = $message->fixed_fields[2];
+ my @fixed_fields = @{$message->{fixed_fields} || []};
+
+ my $fee_type = $fixed_fields[1];
+ my $pay_type = $fixed_fields[2];
my $pay_amount = $SC->get_field_value($message, 'BV');
my $patron_barcode = $SC->get_field_value($message, 'AA');
my $fee_id = $SC->get_field_value($message, 'CG');
])->[0];
return $details unless $card;
+
my $user = $card->usr;
if ($params{fee_id}) {
my $fee_id = $params{fee_id}; # action.billable_xact.id
- my $xact = $session->editor->retrieve_money_billable_xact_summary($fee_id);
+ my $xact =
+ $session->editor->retrieve_money_billable_transaction_summary($fee_id);
return unless $xact && $xact->usr == $user->id;
}
my $pay_amount = $params{pay_amount};
- my $amount_paid = $pay_amount;
+ my $amount_remaining = $pay_amount;
for my $xact (@$xacts) {
next if $xact->balance_owed <= 0;
my $xact_id = $xact->id;
my $balance_owed = $xact->balance_owed;
- if ($balance_owed >= $amount_paid) {
+ if ($balance_owed >= $amount_remaining) {
# We owe as much as or more than we have money left,
# so pay what we have left.
- $payment = $amount_paid;
- $amount_paid = 0;
+ $payment = $amount_remaining;
+ $amount_remaining = 0;
} else {
# This bill is for less than the amount we have
# left, so pay the full bill amount.
$payment = $balance_owed;
- $amount_paid = $U->fpdiff($amount_paid, $balance_owed);
+ $amount_remaining = $U->fpdiff($amount_remaining, $balance_owed);
}
push(@$payments, [$xact->id, $payment]);
- $amount_paid = sprintf("%.2f", $amount_paid);
+ $amount_remaining = sprintf("%.2f", $amount_remaining);
$balance_owed = sprintf("%.2f", $balance_owed);
$logger->info("SIP paid $payment on $xact_id with a ".
- "balance of $balance_owed and $amount_paid remaining");
+ "balance of $balance_owed and $amount_remaining remaining");
# Leave if we ran out of money.
- last if $amount_paid == 0;
+ last if $amount_remaining == 0;
}
- if ($amount_paid == 0) {
+ if ($amount_remaining > 0) {
# TODO strings
$details->{screen_msg} = 'Overpayment not allowed';
return;
# Takes array ref of array ref of [xact_id, payment_amount] to pay in batch.
sub send_payments {
- my ($session, $details, $user, $payments, %params);
+ my ($session, $details, $user, $payments, %params) = @_;
my $pay_type = $params{pay_type};
my $register_login = $params{register_login};
$register_login = $parts[1];
}
}
-
+
my $args = {
userid => $user->id,
note => $register_login ?