public void ProcessPayment(PaymentEditModel paymentEditModel, long eventCustomerId, long customerId, bool isAmexFullPayment) { if (paymentEditModel != null && paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.ChargeCard != null || p.ECheck != null || p.GiftCertificate != null || p.Check != null)) { var aexPayment = paymentEditModel.Payments.SingleOrDefault(p => p.ChargeCard != null && p.ChargeCard.ChargeCard != null && p.ChargeCard.ChargeCard.TypeId == ChargeCardType.AmericanExpress); if (aexPayment != null && !isAmexFullPayment) { aexPayment.Amount = Math.Round(aexPayment.Amount / 2, 2); aexPayment.ChargeCard.ChargeCardPayment.Amount = aexPayment.Amount; } _paymentController.ManagePayment(paymentEditModel, customerId, (System.Web.HttpContext.Current != null ? System.Web.HttpContext.Current.Request.UserHostAddress : ""), string.Concat(customerId, "_", eventCustomerId)); } if (paymentEditModel != null && paymentEditModel.Payments != null && paymentEditModel.Payments.Any(p => p.Insurance != null)) { var insurancePayment = paymentEditModel.Payments.Where(p => p.Insurance != null).Select(p => p.Insurance).SingleOrDefault(); if (insurancePayment != null && insurancePayment.EligibilityId > 0 && insurancePayment.InsurancePayment.AmountToBePaid > 0) { var chargeCard = _chargeCardRepository.GetById(insurancePayment.ChargeCardId); chargeCard.DataRecorderMetaData.DataRecorderCreator.Id = customerId; _chargeCardRepository.Save(chargeCard); _eligibilityRepository.SaveEventCustomerEligibility(eventCustomerId, insurancePayment.EligibilityId, insurancePayment.ChargeCardId); } } }
public long SavePayment(PaymentEditModel paymentEditModel, long dataRecorderOrgRoleUserId) { if (paymentEditModel.Payments == null || paymentEditModel.Payments.Count() < 1) { return(0); } var payments = paymentEditModel.Payments.Where(p => p.Amount != 0); var paymentInstruments = new List <PaymentInstrument>(); var dataRecordermetaData = new DataRecorderMetaData() { DateCreated = DateTime.Now, DataRecorderCreator = new OrganizationRoleUser(dataRecorderOrgRoleUserId) }; foreach (var payment in payments) { if ((payment.PaymentType == PaymentType.CreditCard.PersistenceLayerId || payment.PaymentType == PaymentType.CreditCardOnFile_Value) && payment.ChargeCard != null) { payment.ChargeCard.ChargeCardPayment.DataRecorderMetaData = dataRecordermetaData; payment.ChargeCard.ChargeCardPayment.Id = 0; if (payment.ChargeCard.ChargeCard.Id < 1) { payment.ChargeCard.ChargeCard.DataRecorderMetaData = dataRecordermetaData; } if (payment.PaymentType != PaymentType.CreditCardOnFile_Value) { payment.ChargeCard.ChargeCard = _chargeCardRepository.Save(payment.ChargeCard.ChargeCard); } payment.ChargeCard.ChargeCardPayment.ChargeCardId = payment.ChargeCard.ChargeCard.Id; payment.ChargeCard.ChargeCardPayment.ChargeCardPaymentStatus = ChargeCardPaymentStatus.Approve; if (paymentEditModel.PaymentFlow == PaymentFlow.Out) { payment.ChargeCard.ChargeCardPayment.Amount = -1 * payment.ChargeCard.ChargeCardPayment.Amount; } paymentInstruments.Add(payment.ChargeCard.ChargeCardPayment); } else if (payment.PaymentType == PaymentType.Cash.PersistenceLayerId) { var cashPayment = new CashPayment { Amount = paymentEditModel.PaymentFlow == PaymentFlow.Out ? -1 * payment.Amount : payment.Amount, DataRecorderMetaData = dataRecordermetaData }; paymentInstruments.Add(cashPayment); } else if (payment.PaymentType == PaymentType.Check.PersistenceLayerId && payment.Check != null) { var check = payment.Check.Check; var checkPayment = payment.Check.CheckPayment; if (check.Id < 1) { check.DataRecorderMetaData = dataRecordermetaData; } if (checkPayment.Id < 1) { checkPayment.DataRecorderMetaData = dataRecordermetaData; } checkPayment.Check = check; if (paymentEditModel.PaymentFlow == PaymentFlow.Out) { checkPayment.Amount = -1 * checkPayment.Amount; check.Amount = -1 * check.Amount; } paymentInstruments.Add(checkPayment); } else if (payment.PaymentType == PaymentType.ElectronicCheck.PersistenceLayerId && payment.ECheck != null) { var check = payment.ECheck.ECheck; var checkPayment = payment.ECheck.ECheckPayment; if (check.Id < 1) { check.DataRecorderMetaData = dataRecordermetaData; } if (checkPayment.Id < 1) { checkPayment.DataRecorderMetaData = dataRecordermetaData; } checkPayment.ECheck = check; paymentInstruments.Add(checkPayment); } else if (payment.PaymentType == PaymentType.GiftCertificate.PersistenceLayerId && payment.GiftCertificate != null) { var giftCertificate = payment.GiftCertificate.GiftCertificate; var giftCertificatePayment = payment.GiftCertificate.GiftCertificatePayment; if (giftCertificate.Id < 1) { giftCertificate.DataRecorderMetaData = dataRecordermetaData; } if (giftCertificatePayment.Id < 1) { giftCertificatePayment.DataRecorderMetaData = dataRecordermetaData; } paymentInstruments.Add(giftCertificatePayment); } else if (payment.PaymentType == PaymentType.Insurance.PersistenceLayerId && payment.Insurance != null && payment.Insurance.EligibilityId > 0 && payment.Insurance.InsurancePayment.AmountToBePaid > 0) { var insurancePayment = payment.Insurance.InsurancePayment; insurancePayment.Amount = 0; insurancePayment.DataRecorderMetaData = dataRecordermetaData; paymentInstruments.Add(insurancePayment); } } long paymentId = SavePayment(paymentInstruments, "Payment", dataRecorderOrgRoleUserId); return(paymentId); }
public EligibilityEditModel CheckEligibility(EligibilityEditModel model, long?orgRoleUserId) { var insuranceCompany = _insuranceCompanyRepository.GetById(model.Request.InsuranceCompanyId); var insuranceServiceType = _insuranceServiceTypeRepository.GetById((long)EligibilityServiceType.HBPC); var eligibilityRespose = _eligibilityApi.GetCoverage(model.Request, insuranceCompany, insuranceServiceType); var creditCardResponse = CheckCreditCard(model.CardDetail); if (eligibilityRespose.Plan != null && (eligibilityRespose.Plan.CoverageStatus == EligibleCoverageStatus.ActiveCoverage || eligibilityRespose.Plan.CoverageStatus == EligibleCoverageStatus.ActiveFullRiskCapitation || eligibilityRespose.Plan.CoverageStatus == EligibleCoverageStatus.ActiveServicesCapitated || eligibilityRespose.Plan.CoverageStatus == EligibleCoverageStatus.ActiveServicesCapitatedToPrimaryCarePhysician) && creditCardResponse.ProcessorResult == ProcessorResponseResult.Accepted) { decimal coPay = 0; decimal coInsurance = 0; if (eligibilityRespose.Plan.FinancialData != null) { if (eligibilityRespose.Plan.FinancialData.CoPayment != null && eligibilityRespose.Plan.FinancialData.CoPayment.Amounts != null) { if (insuranceCompany.InNetwork) { if (eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.InNetWork != null && eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.InNetWork.Any()) { coPay = eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.InNetWork.First().Amount; } } else { if (eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.OutNetWork != null && eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.OutNetWork.Any()) { coPay = eligibilityRespose.Plan.FinancialData.CoPayment.Amounts.OutNetWork.First().Amount; } } } if (eligibilityRespose.Plan.FinancialData.CoInsurance != null && eligibilityRespose.Plan.FinancialData.CoInsurance.Percents != null) { if (insuranceCompany.InNetwork) { if (eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.InNetWork != null && eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.InNetWork.Any()) { coInsurance = eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.InNetWork.First().Amount; } } else { if (eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.OutNetWork != null && eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.OutNetWork.Any()) { coPay = eligibilityRespose.Plan.FinancialData.CoInsurance.Percents.OutNetWork.First().Amount; } } } } var eligibility = new Eligibility { Id = model.EligibilityId, Guid = eligibilityRespose.Guid, InsuranceCompanyId = model.Request.InsuranceCompanyId, PlanName = eligibilityRespose.Plan.PlanName, GroupName = eligibilityRespose.Demographics.Subscriber.GroupName, CoPayment = coPay, CoInsurance = coInsurance, Request = JsonConvert.SerializeObject(model.Request), Response = eligibilityRespose.RawResponse, DateCreated = DateTime.Now, CreatedByOrgRoleUserId = orgRoleUserId }; eligibility = _eligibilityRepository.Save(eligibility); model.EligibilityId = eligibility.Id; var chargeCard = model.CardDetail; chargeCard.DataRecorderMetaData = new DataRecorderMetaData { DataRecorderCreator = new OrganizationRoleUser(orgRoleUserId.HasValue && orgRoleUserId.Value > 0 ? orgRoleUserId.Value : 1), DateCreated = DateTime.Now }; chargeCard = _chargeCardRepository.Save(chargeCard); model.CardDetail = chargeCard; } model.Response = eligibilityRespose; if (creditCardResponse.ProcessorResult != ProcessorResponseResult.Accepted) { model.ChargeCardResponse = creditCardResponse.Message; model.HideCardDetails = false; } return(model); }