From 84a49ab7364769488c3397ec97bdda7da033d852 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 13 Nov 2009 14:15:07 +0000 Subject: [PATCH] new API call that fetches all payments for a given user, with optional limits/filters git-svn-id: svn://svn.open-ils.org/ILS/trunk@14899 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 3fc2702434..176eb2ec1f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -3558,5 +3558,60 @@ sub really_delete_user { +__PACKAGE__->register_method ( + method => 'user_payments', + api_name => 'open-ils.actor.user.payments.retrieve', + stream => 1, + signature => q/ + Returns all payments for a given user. Default order is newest payments first. + @param auth Authentication token + @param user_id The user ID + @param filters An optional hash of filters, including limit, offset, and order_by definitions + / +); + +sub user_payments { + my($self, $conn, $auth, $user_id, $filters) = @_; + $filters ||= {}; + + my $e = new_editor(authtoken => $auth); + return $e->die_event unless $e->checkauth; + + my $user = $e->retrieve_actor_user($user_id) or return $e->event; + return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS', $user->home_ou); + + # Find all payments for all transactions for user $user_id + my $query = { + select => {mp => ['id']}, + from => 'mp', + where => { + xact => { + in => { + select => {mbt => ['id']}, + from => 'mbt', + where => {usr => $user_id} + } + } + }, + order_by => [{ # by default, order newest payments first + class => 'mp', + field => 'payment_ts', + direction => 'desc' + }] + }; + + for (qw/order_by limit offset/) { + $query->{$_} = $filters->{$_} if defined $filters->{$_}; + } + + my $payment_ids = $e->json_query($query); + $conn->respond($e->retrieve_money_payment($_->{id})) for @$payment_ids; + + return undef; +} + + + + 1; -- 2.11.0