LP#1743262 CC external payment requires app. code
authorBill Erickson <berickxx@gmail.com>
Mon, 5 Feb 2018 21:24:38 +0000 (16:24 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 5 Feb 2018 22:06:27 +0000 (17:06 -0500)
1. Indicate in the CC form that the approval_code field is required,
   styled consistently with the patron edit app.

2. Prevent the form dialog from closing via Submit when no approval code
   is set.

3. Handle payment failures better by preventing the post-API code from
   running (i.e. receipt printing) when the API fails.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/circ/patron/t_cc_payment_dialog.tt2
Open-ILS/src/templates/staff/css/circ.css.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/bills.js

index 3a0ec69..e25bd86 100644 (file)
@@ -5,7 +5,7 @@
     [% l('Credit Card Information') %]
   </h4>
 </div>
-<div class="modal-body tight-vert-form">
+<div class="modal-body tight-vert-form" id="patron-pay-by-credit-form">
   <div class="panel panel-default">
     <div class="panel-heading">[% l('Credit Card Info') %]</div>
     <div class="panel-body">
@@ -45,7 +45,8 @@
         <div class="row form-group">
           <div class="col-md-4"><label>[% l('Approval Code') %]</label></div>
           <div class="col-md-8">
-            <input type='text' class="form-control" ng-model="context.cc.approval_code"/>
+            <input type='text' class="form-control" 
+              required ng-model="context.cc.approval_code"/>
           </div>
         </div>
       </div><!--cc-external-wrapper-->
index 9fb60e6..5bac645 100644 (file)
@@ -162,7 +162,8 @@ but the ones I'm finding aren't quite cutting it..*/
 /* Angular applies these classes based on the field's 
  * required and pattern settings */
 #patron-reg-container .ng-invalid,
-#patron-reg-container .ng-invalid-required {
+#patron-reg-container .ng-invalid-required,
+#patron-pay-by-credit-form .ng-invalid {
   background-color: yellow;
   color: red;
 }
index a7e9b64..abf120e 100644 (file)
@@ -40,6 +40,15 @@ function($q , egCore , egWorkLog , patronSvc) {
             patronSvc.current.last_xact_id()
         ).then(function(resp) {
             console.debug('payments: ' + js2JSON(resp));
+
+            if (evt = egCore.evt.parse(resp)) {
+                // Ideally, all scenarios that lead to this alert appearing
+                // will be avoided by the application logic.  Leave the alert
+                // in place now to root out any that remain to be addressed.
+                alert(evt);
+                return $q.reject(''+evt);
+            }
+
             var total = 0; angular.forEach(payments,function(p) { total += p[1]; });
             var msg;
             switch(type) {
@@ -58,8 +67,6 @@ function($q , egCore , egWorkLog , patronSvc) {
                     'total_amount' : total
                 }
             );
-            if (evt = egCore.evt.parse(resp)) 
-                return alert(evt);
 
             // payment API returns the update xact id so we can track it
             // for future payments without having to refresh the user.
@@ -321,15 +328,20 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
         var make_payments = generatePayments();
         billSvc.applyPayment($scope.payment_type, 
             make_payments, note, $scope.check_number, cc_args)
-        .then(function(payment_ids) {
+        .then(
+            function(payment_ids) {
 
-            if (!$scope.disable_auto_print && $scope.receipt_on_pay.isChecked) {
-                printReceipt(
-                    $scope.payment_type, payment_ids, make_payments, note);
-            }
+                if (!$scope.disable_auto_print && $scope.receipt_on_pay.isChecked) {
+                    printReceipt(
+                        $scope.payment_type, payment_ids, make_payments, note);
+                }
 
-            refreshDisplay();
-        })
+                refreshDisplay();
+            },
+            function(msg) {
+                console.error('Payment was rejected: ' + msg);
+            }
+        )
     }
 
     $scope.onReceiptOnPayChanged = function(){
@@ -586,6 +598,12 @@ function($scope , $q , $routeParams , egCore , egConfirmDialog , $location,
                     }
 
                     $scope.ok = function() {
+                        // CC payment form is not a <form>, 
+                        // so apply validation manually.
+                        if ( $scope.context.cc.where_process == 0 && 
+                            !$scope.context.cc.approval_code)
+                            return;
+
                         $uibModalInstance.close($scope.context.cc);
                     }