[open-ils-commits] r14899 - trunk/Open-ILS/src/perlmods/OpenILS/Application (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Nov 13 09:15:08 EST 2009


Author: erickson
Date: 2009-11-13 09:15:07 -0500 (Fri, 13 Nov 2009)
New Revision: 14899

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
new API call that fetches all payments for a given user, with optional limits/filters

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2009-11-13 05:24:42 UTC (rev 14898)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2009-11-13 14:15:07 UTC (rev 14899)
@@ -3558,5 +3558,60 @@
 
 
 
+__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;
 



More information about the open-ils-commits mailing list