PageSourceSearch

https://wlivestock.com/app/views/account/manage/accountManageBillingController.js?v=buster20250808

js wlivestock.com collected 2026-10-04 06:05:11 UTC 21,005 bytes, 473 lines download raw bytes

1app.controller('accountManageBillingController', ['$rootScope', '$scope', '$state', 'lookupService', '$stateParams', '$timeout', '$q', 'localStorageService', 'permissionsService', 'authenticationService', 'authorizeDotNetService', 'lists', 'adminCompanySettingsService',
2    function ($rootScope, $scope, $state, lookupService, $stateParams, $timeout, $q, localStorageService, permissionsService, authenticationService, authorizeDotNetService, lists, adminCompanySettingsService) {
3
4        $scope.initializePage = function () {
5            $scope.$parent.activeChildView = $state.current.name.replace('accountManage.', '');
6
7            // Check to make sure they are logged in as a user        
8            permissionsService.isAuthenticated().then(function (results) {
9                if (!results.data) {
10                    popMessage("error", "Not Authorized", "You are not authorized to view this page. Please login to continue.");
11                    authenticationService.logout();
12                    $state.go('accountLogin');
13                } else {
14
15                    //Prepare Drop Downs
16                    $scope.months = lists.months;
17
18                    var thisYear = (new Date()).getFullYear();
19                    for (i = thisYear; i < thisYear + 10; i++) {
20                        $scope.years.push({ id: i, text: i.toString() });
21                    }
22
23                    $scope.states = lists.states;
24
25                    $scope.bankAccountTypes = [{ id: 'checking', text: 'Checking' }, { id: 'savings', text: 'Savings' }];
26
27                    //Figure out if there's any information we should be using to load the payment directive
28                    if ($stateParams.paymentCorrelationInfo != null && $stateParams.paymentCorrelationInfo.length > 0) {
29                        try {
30                            var reasonType = $stateParams.paymentCorrelationInfo.split(',')[0].trim().toLowerCase();
31                            var correlationKey = $stateParams.paymentCorrelationInfo.split(',')[1].trim().toLowerCase();
32
33                            //TODO: Add any other future payment reasons into this case statement
34                            switch (reasonType) {
35                                case "invoice":
36                                    $scope.invoiceIdForPaymentDirective = correlationKey;
37                                    if ($scope.invoiceIdForPaymentDirective > -1) {
38                                        $scope.showMakePayment = true;
39                                    }
40                                    break;
41                            }
42                        } catch (e) { }
43                    }
44
45                    $scope.getBillingInfo();
46
47                }
48            }, function (error) {
49                popApiErrorMessage(error);
50            });
51        };        
52
53        $scope.getBillingInfo = function () {
54
55            //PZ -- Go see if we should be showing the e-Check section            
56            adminCompanySettingsService.getShowAchECheck().then(function (results) {
57
58                $scope.showAchECheck = true;
59
60                try {
61                    $scope.showAchECheck = results.data.auctionCompanySettings[0] == null ? true : results.data.auctionCompanySettings[0].value == 'True';
62                } catch (e) { }
63
64            }, function (error) {
65                popApiErrorMessage(error);
66            });
67
68
69            authorizeDotNetService.getCustomerProfileId().then(function (results) {
70
71                if (results.data.customerProfile && results.data.customerProfile.length > 0) {
72                    $scope.authorizeDotNetCustomerProfileId = results.data.customerProfile[0].authorizeDotNetCustomerProfileId;
73
74                }
75
76                authorizeDotNetService.getCustomerPaymentProfiles($scope.includeDeactivatedPaymentProfiles).then(function (results) {
77
78                    $scope.validPaymentProfileFound = false;
79
80                    $scope.customerPaymentProfiles = results.data.customerPaymentProfiles;
81
82                    $.each(results.data.customerPaymentProfiles, function (index, paymentProfile) {
83
84                        if (paymentProfile.paymentProfileType == 'credit
84Card') {
85                            //make sure it's not expired
86
87                            var pad = "00";
88                            var nextMonthFromCardExpirationDate = getNextMonth(paymentProfile.cardExpirationYear + '-' + (pad + paymentProfile.cardExpirationMonth).slice(-pad.length) + '-01');
89
90                            if (moment() <= nextMonthFromCardExpirationDate) {
91                                if (paymentProfile.active) {
92                                    $scope.validPaymentProfileFound = true;
93                                }
94                                paymentProfile.isExpired = false;
95                            } else {
96                                paymentProfile.isExpired = true;
97                            }
98                        }
99
100                        //if (paymentProfile.paymentProfileType == 'eCheck') {
101
102                        //    //PZ Removed. Stored Echeck accounts are not valid for bidding
103                        //    if (paymentProfile.active) {
104                        //        //$scope.validPaymentProfileFound = true;
105                        //    }
106
107
108                        //}
109
110
111                    });
112
113                    if (!$scope.validPaymentProfileFound && ($scope.user.isAllowedToBidWithoutValidCreditCard == null || $scope.user.isAllowedToBidWithoutValidCreditCard == 'False')) {
114                        if ($scope.badges.billing.length == 0) {
115                            $scope.badges.billing.push({ message: 'Enter a valid credit card.' });
116                        }
117                    } else {
118                        $scope.badges.billing = [];
119                    }
120
121
122                    $scope.pageIsLoaded = true;
123
124                }, function (error) {
125                    popApiErrorMessage(error);
126                    $scope.pageIsLoaded = true;
127                });
128
129            }, function (error) {
130                popApiErrorMessage(error);
131                $scope.pageIsLoaded = true;
132            });
133        };
134
135        $scope.addCreditCard = function () {
136            $scope.customerPaymentProfiles.unshift(
137                {
138                    isEditing: true,
139                    isViewingPayments: false,
140                    paymentProfileType: 'creditCard',
141                    cardNumber: '',
142                    cardExpirationMonth: "",
143                    cardExpirationYear: "",
144                    billToFirstName: "",
145                    billToLastName: "",
146                    billToAddress: "",
147                    billToCity: "",
148                    billToState: "",
149                    billToZip: "",
150                    payments: [],
151                    paymentsPageNumber: 1,
152                    paymentsPageSize: 25
153                }
154            );
155
156            $scope.isAddingNewCreditCard = true;
157        };
158
159        $scope.cancelAddCreditCard = function () {
160            $scope.customerPaymentProfiles.splice(0, 1);
161            $scope.isAddingNewCreditCard = false;
162        };
163
164        $scope.addECheck = function () {
165            $scope.customerPaymentProfiles.unshift(
166                {
167                    isEditing: true,
168                    isViewingPayments: false,
169                    paymentProfileType: 'eCheck',
170                    bankName: '',
171                    bankAccountNumber: "",
172                    bankRoutingNumber: "",
173                    bankAccountType: "checking",
174                    firstNameOnAccount: "",
175                    lastNameOnAccount: "",
176                    payments: [],
177                    paymentsPageNumber: 1,
178                    paymentsPageSize: 25
179                }
180            );
181
182            $scope.isAddingNewECheck = true;
183        };
184
185        $scope.cancelAddECheck = function () {
186            $scope.customerPaymentProfiles.splice(0, 1);
187            $scope.isAddingNewECheck = false;
188        };
189
190        $scope.toggleViewingPayments = function (customerPaymentProfile) {
191            customerPaymentProfile.isViewingPayments = !customerPaymentProfile.isViewingPayments;
192
193            if (customerPaymentProfile.isViewingPayments) {
194                $scope.getPayments(customerPaymentProfile);
195            }
196        };
197
198        $scope.saveNewCreditCard = function (customerPaymentProfile) {
199
200            // Set the deffered promise for the button to disable
201            var deferred = $q.defer();
202
203            // Validate the form
204            if (!$scope.paymentForm.$valid) {
205                // Make sure that the form field highlight if nothing is filled out.
206                $scope.$broadcast('show-errors-check-validity');
207
208                popMessage("error", "Error", 'All required fields must be filled.');
209
210                // Resolve the promise
211                deferred.resolve();
212
213                // Return the promise so the button will activate again
214                return deferred.promise;
215            }
216
217
218            authorizeDotNetService.createCustomerProfileCreditCard($scope.authorizeDotNetCustomerProfileId, customerPaymentProfile.cardNumber,
219                customerPaymentProfile.cardCode, customerPaymentProfile.cardExpirationMonth, customerPaymentProfile.cardExpirationYear, customerPaymentProfile.billToFirstName,
220                customerPaymentProfile.billToLastName, customerPaymentProfile.billToAddress, customerPaymentProfile.billToCity,
221                customerPaymentProfile.billToState, customerPaymentProfile.billToZip).then(function (results) {
222
223                    if (results && results.data && results.data.results && results.data.results.length > 0 && results.data.results[0].success) {
224                        popMessage("success", "Credit Card Added", "Your credit card has been securely saved.");
225                    } else {
226                        var errorMessage = "";
227                        try {
228                            errorMessage = results.data.results[0].message;
229                        } catch (e) {
230                            errorMessage = "There was an error while attempting to save your credit card. Please check to make sure that you haven't already entered this credit card in the system.";
231                        }
232                        popMessage("error", "Credit Card Error", errorMessage);
233                    }
234
235                    $scope.isAddingNewCreditCard = false;
236                    deferred.resolve();
237
238                    $scope.getBillingInfo();
239
240                    authenticationService.refreshBearerToken().then(function (results) {
241                        $scope.user = localStorageService.get('AuthData');
242                    }, function (error) {
243                        popApiErrorMessage(error);
244                    });
245
246                    $scope.loadPaymentDirectiveDate = new Date(); //This causes the payment directive to re-load
247
248                }, function (error) {
249                    // Pop up an error
250                    popApiErrorMessage(error);
251                    // Resolve the promise
252                    deferred.resolve();
253                });
254
255            // Return the promise so the button will activate again
256            return deferred.promise;
257        };
258
259        $scope.saveNewECheck = function (customerPaymentProfile) {
260
261            // Set the deffered promise for the button to disable
262            var deferred = $q.defer();
263
264            // Validate the form
265            if (!$scope.paymentForm.$valid) {
266                // Make sure that the form field highlight if nothing is filled out.
267                $scope.$broadcast('show-errors-check-validity');
268
269                popMessage("error", "Error", 'All required fields must be filled.');
270
271                // Resolve the promise
272                deferred.resolve();
273
274                // Return the promise so the button will activate again
275                return deferred.promise;
276            }
277
278
279            authorizeDotNetService.createCustomerProfileECheck($scope.authorizeDotNetCustomerProfileId, customerPaymentProfile.bankName,
280                customerPaymentProfile.bankAccountFirstName, customerPaymentProfile.bankAccountLastName, customerPaymentProfile.bankAccountType,
281                customerPaymentProfile.bankAccountRoutingNumber, customerPaymentProfile.bankAccountNumber).then(function (results) {
282
283                    if (results && results.data && results.data.results && results.data.results.length > 0 && results.data.results[0].success) {
284                        popMessage("success", "E-Check Account Added", "Your e-check account has been securely saved.");
285                    } else {
286                        var errorMessage = "";
287                        try {
288                            errorMessage = results.data.results[0].message;
289                        } catch (e) {
290                            errorMessage = "There was an error while attempting to save your e-check account. Please check to make sure that you haven't already entered this account information in the system.";
291                        }
292                        popMessage("error", "E-Check Account Error", errorMessage);
293                    }
294
295                    $scope.isAddingNewECheck = false;
296                    deferred.resolve();
297
298                    $scope.getBillingInfo();
299
300                    authenticationService.refreshBearerToken().then(function (results) {
301                        $scope.user = localStorageService.get('AuthData');
302                    }, function (error) {
303                        popApiErrorMessage(error);
304                    });
305
306                    $scope.loadPaymentDirectiveDate = new Date(); //This causes the payment directive to re-load
307
308                }, function (error) {
309                    // Pop up an error
310                    popApiErrorMessage(error);
311                    // Resolve the promise
312                    deferred.resolve();
313                });
314
315            // Return the promise so the button will activate again
316            return deferred.promise;
317        };
318
319        $scope.deactivateCustomerPaymentProfile = function (customerPaymentProfile) {
320            var deferred = $q.defer();
321
322            authorizeDotNetService.deactivateCustomerPaymentProfile(customerPaymentProfile.authorizeDotNetCustomerProfileId, customerPaymentProfile.authorizeDotNetPaymentProfileId).then(function (results) {
323
324                if (results && results.data && results.data.results && results.data.results.length > 0 && results.data.results[0].success) {
325                    popMessage("success", "Payment Method Deactivated", "Your payment method has been successfully deactivated.");
326                } else {
327                    var errorMessage = "";
328                    try {
329                        errorMessage = results.data.results[0].message;
330                    } catch (e) {
331                        errorMessage = "There was an error while attempting to deactivate your payment method.";
332                    }
333                    popMessage("error", "Payment Method Deactivation Error", errorMessage);
334                }
335
336                deferred.resolve();
337
338                $scope.getBillingInfo();
339
340                authenticationService.refreshBearerToken().then(function (results) {
341                    $scope.user = localStorageService.get('AuthData');
342                }, function (error) {
343                    popApiErrorMessage(error);
344                });
345
346                $scope.loadPaymentDirectiveDate = new Date(); //This causes the payment directive to re-load
347
348            }, function (error) {
349                // Pop up an error
350                popApiErrorMessage(error);
351                // Resolve the promise
352                deferred.resolve();
353            });
354
355            // Return the promise so the button will activate again
356            return deferred.promise;
357        };
358
359        $scope.getPayments = function (customerPaymentProfile) {
360
361            customerPaymentProfile.isSearchInProgress = true;
362
363            if (customerPaymentProfile.pageNumber == null) {
364                customerPaymentProfile.pageNumber = 1;
365            }
366            if (customerPaymentProfile.pageSize == null) {
367                customerPaymentProfile.pageSize = 25;
368            }
369
370            authorizeDotNetService.getPaymentsByPaymentProfileId(
371                customerPaymentProfile.authorizeDotNetCustomerProfileId,
372                customerPaymentProfile.authorizeDotNetPaymentProfileId,
373                customerPaymentProfile.pageNumber,
374                customerPaymentProfile.pageSize).then(function (results) {
375
376                    customerPaymentProfile.payments = results.data.payments;
377                    customerPaymentProfile.totalItems = results.data.totalRows[0].totalRows;
378                    customerPaymentProfile.isSearchInProgress = false;
379
380                }, function (error) {
381                    // Pop up an error
382                    popApiErrorMessage(error);
383                });
384
385        };
386        
387        //if a payment is made somewhere while we're on this screen, check to see if we need to refresh so that payment displays
388        $scope.userPaymentMade = $rootScope.$on('payment-made', function (event, authorizeDotNetPaymentProfileId) {
389            $.each($scope.customerPaymentProfiles, function (index, authorizeDotNetPaymentProfile) {
390                if (authorizeDotNetPaymentProfile.authorizeDotNetPaymentProfileId == authorizeDotNetPaymentProfileId) {
391                    $scope.getPayments(authorizeDotNetPaymentProfile);
392                }
393            });
394        });
395
396        $scope.$on('$destroy', function () {
397            $scope.userPaymentMade();
398        });
399
400        $scope.pageSizeChange = function (customerPaymentProfile, newpageSize) {
401            customerPaymentProfile.pageSize = newpageSize;
402
403            if (customerPaymentProfile.pageNumber * customerPaymentProfile.pageSize > customerPaymentProfile.totalItems && customerPaymentProfile.totalItems > 0) {
404                customerPaymentProfile.pageNumber = Math.ceil(customerPaymentProfile.totalItems / customerPaymentProfile.pageSize);
405            }
406
407            // Re-get the data
408            $scope.getPayments(customerPaymentProfile);
409        };
410
411        $scope.pageResults = function (customerPaymentProfile, pagination) {
412            customerPaymentProfile.pageNumber = pagination.page;
413
414            // Re-get the data
415            $scope.getPayments(customerPaymentProfile);
416        };
417
418        $scope.toggleIncludeDeactivatedPaymentProfiles = function () {
419            $scope.includeDeactivatedPaymentProfiles = !$scope.includeDeactivatedPaymentProfiles;
420            $scope.pageIsLoaded = false;
421            $scope.getBillingInfo();
422        };
423
424
425        $scope.isCreditCard = function (item) {
426            return item.paymentProfileType == 'creditCard';
427        };
428        $scope.isECheck = function (item) {
429            return item.paymentProfileType == 'eCheck';
430        };
431        $scope.isSavedPaymentMethod = function (item) {
432            return item.authorizeDotNetPaymentProfileId != null && item.paymentProfileType == "creditCard" && item.authorizeDotNetPaymentProfileId.length > 0;
433        };
434
435        //initialize variables
436        $scope.user = localStorageService.get('AuthData');
437
438        $scope.authorizeDotNetCustomerProfileId = "";
439        $scope.customerPaymentProfiles = [];
440
441        $scope.months = [];
442        $scope.years = [];
443        $scope.states = [];
444        $scope.bankAccountTypes = [];
445
446        $scope.availablePageSizes = lists.availablePageSizes;
447
448        $scope.isAddingNewCreditCard = false;
449        $scope.isAddingNewECheck = false;
450
451        $scope.validPaymentProfileFound = false;
452
453        $scope.includeDeactivatedPaymentProfiles = false;
454
455        $scope.loadPaymentDirectiveDate = new Date(); //By setting this variable, it'll cause the payment directive to load (or re-load)
456
457        $scope.invoiceIdForPaymentDirective = -1;
458        $scope.includeDirectPaymentTypes = false;
459
460        $scope.showMakePayment = false;
461
462        $scope.pageIsLoaded = false;
463
464        //If the page hasn't loaded after 1 second, signal that the ui can show the loading animation
465        $scope.canShowPageLoading = false;
466        $timeout(function () { $scope.canShowPageLoading = true; }, 1000);
467
468        $scope.showAchECheck = true;
469
470        //initialize Page
471        $scope.initializePage();
472    }
473]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.