UNPKG

client-ui

Version:

Testing implementation of nodeJs Backend, angular frontend, and hopefully in a way that this can be deployed to s3/cloudfront

131 lines (117 loc) 4.61 kB
(function () { 'use strict'; angular.module(moduleName).controller('debitController', debitController); debitController.$inject = ['loan', 'currentLoan', '$state']; function debitController(loanService, currentLoan, $state) { var self = this; $('a[rel=popover]').popover({ html: true, trigger: 'hover', placement: 'top', content: function () { return '<img src="' + $(this).data('img') + '" width="200px" />'; } }); self.currentLoan = currentLoan; self.debitAccount = { type: 'debit', cardholderName: '', accountNo: '', expMonth: '', expYear: '', cvv: '' }; self.goToNextStep = goToNextStep; self.submitBankInfo = submitBankInfo; self.resetCardErrors = resetCardErrors; self.editBankInfo = false; self.emailVerError = false; self.emailVerSuccess = false; self.errorMessage = false; self.fundingAccount = loanService.getFundingAccount(); self.editBank = editBank; self.cancelEditBank = cancelEditBank; self.cardResponse = { ACCOUNT_EXISTS: { message: 'That card was already added to your account.', failed: false }, cardNumber: { message: 'Please double-check your card number.', failed: false }, expired: { message: 'Please double-check your card expiration date.', failed: false }, cvv: { message: 'Please double-check your card security code (CVV).', failed: false }, type: { message: 'Unfortunately, that type of card is not eligible for funding your loan. We can only deposit to debit cards.', failed: false }, credit: {// not credit eligible (deposits) message: 'Unfortunately, that card is not eligible for funding through our network.', failed: false }, unknownError: { message: 'Unfortunately, we are experiencing technical difficulties with our debit card verification network.', failed: false } }; function submitBankInfo() { resetCardErrors(); constructCardExpiration(); self.working = true; loanService.addBankAccount(self.debitAccount) .then(function (res) { self.currentLoan = loanService.getCurrentLoan(); self.working = false; goToNextStep(); }, function (err) { self.working = false; var code = err.code || 'unknownError'; if (code === 'ADD_BANK_ACCOUNT_MAX_ATTEMPTS') { self.loanSuspended = true; } else { self.cardResponseError = true; if (code === 'invalid') { code = 'cardNumber'; } if (code === 'ACCOUNT_EXISTS') { self.cardResponse.cardNumber.failed = true; } self.cardResponse[code].failed = true; } }); } function resetCardErrors() { self.cardResponseError = false; self.loanSuspended = false; for (var cat in self.cardResponse) { self.cardResponse[cat].failed = false; } } function goToNextStep() { self.working = false; $state.go(loanService.getNextStep()); } function constructCardExpiration() { var month = self.monthChosen.toString(); var year = self.yearChosen.toString().substring(2, 4); self.debitAccount.expMonth = month; self.debitAccount.expYear = year; } function editBank() { self.editBankInfo = true; setTimeout(function () { config.scrollToTop($('#clientDebitInfo').offset().top); }, 250); } function cancelEditBank() { self.editBankInfo = false; self.cardResponseError = false; setTimeout(function () { config.scrollToTop($('h2').offset().top); }, 250); } } })();