public async Task <AmendDirectDebitVm> Build(IApplicationSessionState session, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = session.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto {
                LowellReference = lowellReference
            };
            var currentDirectDebit = await _getCurrentDirectDebitProcess.GetCurrentDirectDebit(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            var workingAccounts = 0;

            if (caseflowUserId != null)
            {
                List <AccountSummary> accounts = await _accountService.GetAccounts(caseflowUserId);

                workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);
            }

            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            var obj = new AmendDirectDebitVm
            {
                LowellReference    = currentDirectDebit.LowellReference,
                ClientName         = currentDirectDebit.ClientName,
                OutstandingBalance = currentDirectDebit.OutstandingBalance,
                DirectDebitAmount  = null,
                PlanType           = currentDirectDebit.PlanType,
                EarliestStartDate  = currentDirectDebit.EarliestInstalmentDate,
                LatestStartDate    = currentDirectDebit.LatestPlanSetupDate,
                PlanStartDate      = currentDirectDebit.EarliestInstalmentDate,
                DiscountedBalance  = currentDirectDebit.DiscountedBalance,
                DiscountAmount     = currentDirectDebit.DiscountAmount,
                DiscountExpiry     = currentDirectDebit.DiscountExpiry,
                DiscountPercentage = currentDirectDebit.DiscountPercentage,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                Frequency                    = _buildFrequencyListProcess.BuildFrequencyList(currentDirectDebit.DirectDebitFrequencies),
                IandENotAvailable            = incomeAndExpenditureDto == null,
                IandELessThanOrIs12MonthsOld = (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date),
                AverageMonthlyPayment        = _portalSetting.AverageMonthlyPaymentAmount,
                MonthlyDisposableIncome      = (incomeAndExpenditureDto == null ? 0 :
                                                (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)))
            };

            obj.AccountCount = workingAccounts;

            if (workingAccounts > 1)
            {
                obj.MonthlyDisposableIncomePerAccount =
                    obj.MonthlyDisposableIncome / workingAccounts;
            }
            else
            {
                obj.MonthlyDisposableIncomePerAccount = obj.MonthlyDisposableIncome;
            }

            return(obj);
        }
Пример #2
0
        public async Task <PaymentOptionsVm> Build(IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = applicationSessionState.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto()
            {
                LowellReference = lowellReference
            };
            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            List <AccountSummary> accounts;

            if (caseflowUserId != null)
            {
                accounts = await _accountsService.GetAccounts(caseflowUserId);
            }
            else
            {
                accounts = await _accountsService.GetMyAccountsSummary(lowellReference);
            }

            var workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);

            if (workingAccounts == 0)
            {
                workingAccounts = 1;
            }

            var accountDetails = await _accountsService.GetAccount(caseflowUserId, lowellReference);

            string[] planMessages = accountDetails.PlanMessages;

            var paymentOptionsVm = new PaymentOptionsVm()
            {
                OutstandingBalance                  = paymentOptionsDto.OutstandingBalance,
                LowellReference                     = paymentOptionsDto.LowellReference,
                ClientName                          = paymentOptionsDto.ClientName,
                ExcludedAccountMessage              = paymentOptionsDto.ExcludedAccountMessage,
                PlanInPlace                         = paymentOptionsDto.PlanInPlace,
                PlanIsDirectDebit                   = paymentOptionsDto.PaymentPlanIsDirectDebit,
                WithLowellSolicitors                = paymentOptionsDto.WithLowellSolicitors,
                PaymentOptions                      = new List <PaymentOptionsSelectionsVm>(),
                DiscountPercentage                  = paymentOptionsDto.DiscountPercentage,
                DiscountAmount                      = paymentOptionsDto.DiscountAmount,
                DiscountExpiryDate                  = paymentOptionsDto.DiscountExpiryDate,
                DiscountedBalance                   = paymentOptionsDto.DiscountedBalance,
                DiscountBalanceAvailable            = paymentOptionsDto.DiscountBalanceAvailable,
                ProposedDiscountedBalanceIfAccepted = paymentOptionsDto.ProposedDiscountedBalanceIfAccepted,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                ArrearsMessage                      = _arrearsDescriptionProcess.DeriveArrearsDetail(paymentOptionsDto.PaymentPlanArrearsAmount,
                                                                                                     paymentOptionsDto.PaymentPlanIsAutomated),
                StandingOrder           = paymentOptionsDto.StandingOrder,
                StandingOrderMessage    = paymentOptionsDto.StandingOrderMessage,
                VerifoneTransactionGuid = $"{paymentOptionsDto.LowellReference}_{Guid.NewGuid()}",
                DiscountAccepted        = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                PlanMessage             = planMessages != null && planMessages.Length > 0? planMessages[0]:string.Empty
            };

            if (loggedInUser.IsLoggedInUser)
            {
                paymentOptionsVm.DirectDebitEmailAddress = loggedInUser.EmailAddress;
            }
            else
            {
                paymentOptionsVm.DirectDebitIsEmailAddressFieldVisible = true;
            }

            // Logged in user has accept T&C defaulted and will be hidden.
            // Anon user has tick box displayed. Must be ticked.
            if (loggedInUser.IsLoggedInUser)
            {
                paymentOptionsVm.AcceptTermsAndConditions = true;
            }
            else
            {
                paymentOptionsVm.IsAcceptTermsAndConditionsFieldVisible = true;
            }

            // Work out amount that needs to be paid to clear balance
            if (paymentOptionsVm.DiscountedBalancePreviouslyAccepted)
            {
                paymentOptionsVm.FullPaymentBalance = paymentOptionsVm.DiscountedBalance;
            }
            else
            {
                paymentOptionsVm.FullPaymentBalance = paymentOptionsVm.OutstandingBalance;
            }

            // Customer has a plan but it isn't direct debit.
            // Used to display a message informing customer that they can change to a DD online.
            if (paymentOptionsDto.PlanInPlace && !paymentOptionsDto.PaymentPlanIsDirectDebit)
            {
                paymentOptionsVm.HasNonDirectDebitPlanInPlace = true;
            }

            if (paymentOptionsDto.WithLowellSolicitors)
            {
                paymentOptionsVm.LowellSolicitorsRedirectLink = _portalSetting.SolicitorsRedirectDataProtectionUrl;
            }

            // Shared list of options for partial / full
            paymentOptionsVm.SourceOfFunds = BuildSourceOfFundsSelections(paymentOptionsDto);

            // Direct Debit
            paymentOptionsVm.DirectDebitFrequency         = BuildFrequencyList(paymentOptionsDto.DirectDebitFrequencies);
            paymentOptionsVm.DirectDebitStartDateEarliest = paymentOptionsDto.DirectDebitStartDateEarliest;
            paymentOptionsVm.DirectDebitStartDateLatest   = paymentOptionsDto.DirectDebitStartDateLatest;

            // TODO: Wrap the code below in a strategy pattern
            if (paymentOptionsDto.CanMakeFullPayment)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Card payment (Pay in Full)",
                    Value         = PaymentOptionsSelectionsVm.Values.FullPayment,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.FullPayment
                });
            }
            if (paymentOptionsDto.CanMakePartialPayment)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Card payment (Partial amount)",
                    Value         = PaymentOptionsSelectionsVm.Values.PartialPayment,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.PartialPayment,
                    ClassValue    = "js-hide-option"        // script hides this
                });
            }
            if (paymentOptionsDto.CanSetupDirectDebit)
            {
                paymentOptionsVm.PaymentOptions.Add(new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Direct Debit plan",
                    Value         = PaymentOptionsSelectionsVm.Values.DirectDebit,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.DirectDebit
                });
            }

            // Only add 'please select' if there are options
            // Required because view checks for availability of payment options
            if (paymentOptionsVm.PaymentOptions.Count > 0)
            {
                paymentOptionsVm.PaymentOptions.Insert(0, new PaymentOptionsSelectionsVm()
                {
                    DisplayedText = "Please Select",
                    Value         = PaymentOptionsSelectionsVm.Values.PleaseSelect,
                    DataFormValue = PaymentOptionsSelectionsVm.Values.PleaseSelect
                });
            }

            paymentOptionsVm.LowellReferenceSurrogate = lowellReferenceSurrogateKey;

            paymentOptionsVm.IandENotAvailable = incomeAndExpenditureDto == null;

            paymentOptionsVm.IandELessThanOrIs12MonthsOld =
                (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date);
            paymentOptionsVm.AverageMonthlyPayment   = _portalSetting.AverageMonthlyPaymentAmount;
            paymentOptionsVm.MonthlyDisposableIncome =
                (incomeAndExpenditureDto == null ? 0 : (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)));

            paymentOptionsVm.AccountCount = workingAccounts;
            paymentOptionsVm.MonthlyDisposableIncomePerAccount = paymentOptionsVm.MonthlyDisposableIncome / workingAccounts;

            return(paymentOptionsVm);
        }