From: Bill Erickson Date: Mon, 2 Nov 2020 22:54:34 +0000 (-0500) Subject: LP1901930 Payments support X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=07d5c1a5f50502cea04ff5e8e503e4939b18d02f;p=working%2FEvergreen.git LP1901930 Payments support Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index 348f4d85bc..a8fcc30f24 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -534,8 +534,10 @@ sub handle_payment { 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'); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Payment.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Payment.pm index 062be095f4..145d46a453 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Payment.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Payment.pm @@ -25,6 +25,7 @@ sub apply_payment { ])->[0]; return $details unless $card; + my $user = $card->usr; if ($params{fee_id}) { @@ -43,7 +44,8 @@ sub pay_one_transaction { 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; @@ -78,7 +80,7 @@ sub pay_multi_transactions { } 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; @@ -87,34 +89,34 @@ sub pay_multi_transactions { 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; @@ -125,7 +127,7 @@ sub pay_multi_transactions { # 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}; @@ -138,7 +140,7 @@ sub send_payments { $register_login = $parts[1]; } } - + my $args = { userid => $user->id, note => $register_login ?