JBAS-2118 Lost payments auth for webstaff WIP
authorBill Erickson <berickxx@gmail.com>
Thu, 8 Nov 2018 22:28:37 +0000 (17:28 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

index e62cd3e..e3d1e1d 100644 (file)
@@ -28,7 +28,7 @@ function($q , egCore , egWorkLog , patronSvc) {
     }
 
     service.applyPayment = function(
-        type, payments, note, check, cc_args, patron_credit) {
+        type, payments, note, check, cc_args, patron_credit, refundable_args) {
 
         return egCore.net.request(
             'open-ils.circ',
@@ -40,6 +40,7 @@ function($q , egCore , egWorkLog , patronSvc) {
                 check_number : check,
                 payments : payments,
                 patron_credit : patron_credit,
+                refundable_args: refundable_args,
                 cc_args : cc_args
             },
             patronSvc.current.last_xact_id()
@@ -384,7 +385,8 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
                 function(item) {return item.id == xactId})[0];
 
             var stopFines = gridItem['circulation.stop_fines'];
-            if (stopFines === 'LOST') {
+            var ciTime = gridItem['circulation.checkin_time'];
+            if (stopFines === 'LOST' && !ciTime) {
                 console.debug("Processing lost payment transaction ", xactId);
                 lostXacts.push(xactId);
             }
@@ -394,21 +396,62 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
             return $q.when(payments);
         }
 
+        return checkSecondaryAuth().then(
+            function(authKey) {
+                return {
+                    secondary_auth_key: authKey,
+                    transactions: lostXacts.map(
+                        function(id) {return {xact: id}})
+                };
+            },
+            function() { return $q.reject(); }
+        );
+    }
+
+    function checkSecondaryAuth(deferred) {
+
+        if (!deferred) {
+           // Create the deferred object on the first run of this function.
+           deferred = $q.defer();
+        }
+
+        showSecondaryAuthDialog().then(
+            function(authKey) {
+                if (authKey) {
+                    deferred.resolve(authKey);
+                } else {
+                    return checkSecondaryAuth(deferred);
+                }
+            }, 
+            function() {
+                deferred.reject();
+            }
+        );
+
+        return deferred.promise;
+    }
+
+    // Returns promise.
+    // Resolves to true on auth success, false on auth failure, and
+    // rejects on Cancel.
+    function showSecondaryAuthDialog() {
+            
         return $uibModal.open({
             templateUrl : './circ/patron/t_lost_payment_auth',
             backdrop: 'static',
             controller : [
                         '$scope','$uibModalInstance',
                 function($scope , $uibModalInstance) {
-                    $scope.context = {
-                        username: '',
-                        password: ''
-                    };
+                    $scope.context = {username: '',password: ''};
 
                     $scope.ok = function() {
-                        console.log($scope.context.username);
-                        console.log($scope.context.password);
-                        $uibModalInstance.close(payments);
+                        getSecondaryAuthKey(
+                            $scope.context.username, $scope.context.password
+                        ).then(
+                            function(res) {
+                                $uibModalInstance.close(res);
+                            }
+                        );
                     }
 
                     $scope.cancel = function() {
@@ -419,6 +462,34 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
         }).result;
     }
 
+    function getSecondaryAuthKey(username, password) {
+
+        console.log('Checking secondary auth for ' + username);
+
+        return egCore.net.request(
+            'open-ils.circ',
+            'open-ils.circ.staff.secondary_auth.ldap',
+            egCore.auth.token(), username, password
+        ).then(function(result) {
+            var evt = egCore.evt.parse(result);
+            console.log('2nd auth returned', result);
+
+            if (evt) {
+                if (evt.textcode === 'LDAP_AUTH_FAILED') {
+                    console.log("Secondary auth failed for " + username);
+                } else {
+                    alert(evt);
+                }
+            } else if (typeof result === 'string') {
+                console.debug('Secondary auth succeeded with ' + result);
+                return result;
+            }
+
+            return null;
+        });
+    }
+
+
     // generates payments, collects user note if needed, and sends payment
     // to server.
     function sendPayment(note, cc_args) {
@@ -429,11 +500,11 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
 
         // KCLS prompt for lost payment authorization.
         handleLostPayAuth(make_payments)
-        .then(function(make_payments) {
+        .then(function(refundable_args) {
         // NOTE: avoiding indentation to reduce variation with stock.
 
-        billSvc.applyPayment($scope.payment_type, 
-            make_payments, note, $scope.check_number, cc_args, patron_credit)
+        billSvc.applyPayment($scope.payment_type, make_payments, note, 
+            $scope.check_number, cc_args, patron_credit, refundable_args)
         .then(
             function(payment_ids) {