private void PopulateCreditCardOptions(IUnitOfWork unitOfWork, PaymentOptionsDto paymentOptions) { DateTimeOffset now = DateTimeProvider.Current.Now; unitOfWork.GetRepository <PaymentMethod>().GetTable().Where <PaymentMethod>((Expression <Func <PaymentMethod, bool> >)(o => o.ActivateOn <now && (o.DeactivateOn ?? DateTimeOffset.MaxValue)> now && o.IsCreditCard)).Each <PaymentMethod>((Action <PaymentMethod>)(o => { ICollection <PaymentMethodDto> paymentMethods = paymentOptions.PaymentMethods; PaymentMethodDto paymentMethodDto = new PaymentMethodDto() { Name = o.Name, IsCreditCard = o.IsCreditCard, Description = this.entityTranslationService.Value.TranslateProperty <PaymentMethod>(o, (Expression <Func <PaymentMethod, string> >)(x => x.Description)) }; paymentMethods.Add(paymentMethodDto); })); GetPaymentSettingsResult paymentSettings = this.paymentService.Value.GetPaymentSettings(new GetPaymentSettingsParameter()); paymentOptions.CanStorePaymentProfile = paymentSettings.ResultCode == ResultCode.Success && paymentSettings.SupportsStoredPaymentProfiles; if (paymentOptions.CanStorePaymentProfile) { this.PopulateStoredPaymentProfile(paymentOptions); } this.PopulateCardTypes(paymentOptions); this.PopulateExpirationDates(paymentOptions); }
private void PopulatePoOptions(IUnitOfWork unitOfWork, PaymentOptionsDto paymentOptions) { Customer billTo = SiteContext.Current.BillTo; if (billTo.CreditHold) { return; } PaymentMethod customerPaymentMethod = unitOfWork.GetRepository <PaymentMethod>().GetTable().FirstOrDefault <PaymentMethod>((Expression <Func <PaymentMethod, bool> >)(o => o.Name == billTo.TermsCode)); if (customerPaymentMethod == null || customerPaymentMethod.IsCreditCard) { return; } DateTimeOffset now = DateTimeProvider.Current.Now; unitOfWork.GetRepository <PaymentMethod>().GetTable().Where <PaymentMethod>((Expression <Func <PaymentMethod, bool> >)(o => o.ActivateOn <now && (o.DeactivateOn ?? DateTimeOffset.MaxValue)> now && o.Name.Equals(customerPaymentMethod.Name))).Each <PaymentMethod>((Action <PaymentMethod>)(o => { ICollection <PaymentMethodDto> paymentMethods = paymentOptions.PaymentMethods; PaymentMethodDto paymentMethodDto = new PaymentMethodDto() { Name = o.Name, IsCreditCard = o.IsCreditCard, Description = this.entityTranslationService.Value.TranslateProperty <PaymentMethod>(o, (Expression <Func <PaymentMethod, string> >)(x => x.Description)) }; paymentMethods.Add(paymentMethodDto); })); }
private void PopulateCardTypes(PaymentOptionsDto paymentOptions) { paymentOptions.CardTypes = (ICollection <KeyValuePair <string, string> >)((IEnumerable <string>) this.checkoutSettings.AcceptedCreditCards.Split('|')).Select <string, KeyValuePair <string, string> >((Func <string, KeyValuePair <string, string> >)(o => { string key = o; return(new KeyValuePair <string, string>(key, key.ToUpper())); })).ToList <KeyValuePair <string, string> >(); }
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); }
private void PopulateExpirationDates(PaymentOptionsDto paymentOptions) { DateTimeFormatInfo dateTimeFormat = Thread.CurrentThread.CurrentCulture.DateTimeFormat; paymentOptions.ExpirationMonths = (ICollection <KeyValuePair <string, int> >)Enumerable.Range(1, 12).Select <int, KeyValuePair <string, int> >((Func <int, KeyValuePair <string, int> >)(o => new KeyValuePair <string, int>(dateTimeFormat.GetMonthName(o), o))).ToList <KeyValuePair <string, int> >(); paymentOptions.ExpirationYears = (ICollection <KeyValuePair <int, int> >)Enumerable.Range(DateTimeProvider.Current.Now.Year, 10).Select <int, KeyValuePair <int, int> >((Func <int, KeyValuePair <int, int> >)(o => { int key = o; return(new KeyValuePair <int, int>(key, key)); })).ToList <KeyValuePair <int, int> >(); }
private void PopulateStoredPaymentProfile(PaymentOptionsDto paymentOptions) { UserProfileDto userProfile = SiteContext.Current.UserProfileDto; GetPaymentProfileCollectionResult profileCollection = this.paymentService.Value.GetPaymentProfileCollection(new GetPaymentProfileCollectionParameter() { BillToId = new Guid?(SiteContext.Current.BillTo.Id) }); if (profileCollection.ResultCode != ResultCode.Success) { return; } profileCollection.PaymentProfiles.Each <PaymentProfileDto>((Action <PaymentProfileDto>)(o => paymentOptions.PaymentMethods.Add(new PaymentMethodDto() { Name = o.PaymentProfileId, Description = o.MaskedCardNumber + " " + GetCardType(o.CardType) + " " + userProfile.UserPaymentProfiles.FirstOrDefault(x => x.CardIdentifier == o.PaymentProfileId).Description, IsPaymentProfile = true }))); }
List <PaymentOptionsSourceOfFundsSelectionsVm> BuildSourceOfFundsSelections(PaymentOptionsDto paymentOptionsDto) { List <PaymentOptionsSourceOfFundsSelectionsVm> sourceOfFunds = new List <PaymentOptionsSourceOfFundsSelectionsVm>(); if (paymentOptionsDto.SourceOfFundsPaymentOptions == null) { paymentOptionsDto.SourceOfFundsPaymentOptions = new List <string>(); } foreach (string optionString in paymentOptionsDto.SourceOfFundsPaymentOptions) { sourceOfFunds.Add(new PaymentOptionsSourceOfFundsSelectionsVm() { Value = optionString, DisplayedText = optionString, // TODO: should be refactored into a flag from Payment Service // TODO: ideally, flag or special value should come from CaseFlow DataFormValue = (optionString == "Other") ? "other-field" : null }); } return(sourceOfFunds); }
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); }