public static GetPricesRequest PopulateUsageWithRequestData(this GetPricesRequest request, ApiResponse usageTemplate) { var compareGas = request.CompareType != CompareWhat.Electricity; var compareElec = request.CompareType != CompareWhat.Gas; UpdateItemData(usageTemplate, "includedFuels", "compareGas", compareGas.ToString()); UpdateItemData(usageTemplate, "includedFuels", "compareElec", compareElec.ToString()); switch (request.EnergyJourneyType) { case EnergyJourneyType.HaveMyBill: case EnergyJourneyType.Qr: if (request.CalculateElecBasedOnBillSpend) { PopulateSpendUsageForElectricity(request, usageTemplate); } else { PopulateKWhUsage(request, usageTemplate); } if (request.CalculateGasBasedOnBillSpend) { PopulateSpendUsageForGas(request, usageTemplate); } else { PopulateKWhUsage(request, usageTemplate); } break; case EnergyJourneyType.DontHaveMyBill: if (request.UseDetailedEstimatorForElectricity) { PopulateDetailedUsageForElectricity(request, usageTemplate); } else { PopulateSpendUsageForElectricity(request, usageTemplate); } if (request.UseDetailedEstimatorForGas) { PopulateDetailedUsageForGas(request, usageTemplate); } else { PopulateSpendUsageForGas(request, usageTemplate); } break; } if (compareElec && request.ElectricityEco7) { UpdateItemData(usageTemplate, "economy7", "nightUsagePercentage", request.PercentageNightUsage.ToString(CultureInfo.InvariantCulture)); } return(request); }
public static GetPricesRequest ToEhlPriceRequest(this MakeProviderEnquiry <EnergyEnquiry> energyEnquiry) { var enquiry = energyEnquiry.Enquiry; var risk = enquiry.Risk; var priceRequest = new GetPricesRequest { EnergyJourneyType = risk.EnergyJourneyType, JourneyId = Guid.Parse(risk.JourneyId), Postcode = risk.Postcode, SwitchId = risk.SwitchId, CurrentSupplyUrl = risk.CurrentSupplyUrl, SwitchUrl = risk.SwitchUrl, PrePayment = risk.PrePayment, CompareType = risk.CompareType, GasSupplierId = risk.GasSupplierId, GasTariffId = risk.GasTariffId, GasPaymentMethodId = risk.GasPaymentMethodId, ElectricitySupplierId = risk.ElectricitySupplierId, ElectricityTariffId = risk.ElectricityTariffId, ElectricityPaymentMethodId = risk.ElectricityPaymentMethodId, ElectricityEco7 = risk.Economy7, PercentageNightUsage = risk.Economy7NightUsage, IgnoreProRataComparison = risk.IgnoreProRataComparison, UseDetailedEstimatorForElectricity = risk.CompareType == CompareWhat.Electricity && risk.NoBill != null && risk.NoBill.ElectricitySpendUnknown, UseDetailedEstimatorForGas = risk.CompareType == CompareWhat.Gas && risk.NoBill != null && risk.NoBill.GasSpendUnknown }; SetPriceRequestBillDetails(risk, priceRequest); return(priceRequest); }
protected void When_an_invalid_Response_returned_from_Ehl() { var stubPriceRequest = new GetPricesRequest { CompareType = CompareWhat.Both, CurrentSupplyUrl = "http://rest-predeploy.energyhelpline.com/domestic/energy/switches/e1b208db-54ab-4cb6-b592-a17f008f6dc9/schemaerror-response?b=1+SxdN9QwjA1nP8RoesecNN8ctw", SwitchUrl = "http://rest-predeploy.energyhelpline.com/domestic/energy/switches/e1b208db-54ab-4cb6-b592-a17f008f6dc9?b=1+SxdN9QwjA1nP8RoesecNN8ctw", Postcode = "", ElectricitySupplierId = 1, EnergyJourneyType = EnergyJourneyType.DontHaveMyBill, ElectricityTariffId = 1, GasSupplierId = 1, GasTariffId = 1, PercentageNightUsage = 100M, SwitchId = Guid.NewGuid().ToString(), ElectricityEco7 = true, PrePayment = "false", }; // todo: sort out this work-around (doing this to just get some example data for now) // todo: do we need EnergyRisk AND GetPricesRequest as they seem to be very similar? var energyRisk = JsonConvert.DeserializeObject <EnergyRisk>(JsonConvert.SerializeObject(stubPriceRequest)); _energyEnquiry = new EnergyEnquiry { Risk = energyRisk }; }
public async Task <EhlApiResponse> GetPreferenceEhlApiResponse(GetPricesRequest request, string url, string environment) { var preferencesSwitchesApiResponse = await _ehlHttpClient.GetApiResponse <ApiResponse>(url, environment).ConfigureAwait(false); CheckSuccessReponse("PreferencesStage", preferencesSwitchesApiResponse); request.PopulatePreferencesWithRequestData(preferencesSwitchesApiResponse); var preferencesSwitchesApiPostResponse = await _ehlHttpClient.PostApiGetResponse(url, preferencesSwitchesApiResponse, environment).ConfigureAwait(false); return(ApiCallResponse("PreferencesStage", preferencesSwitchesApiPostResponse, EhlApiConstants.FutureSupplyRel)); }
public async Task <EhlApiResponse> GetSupplierEhlApiResponse(GetPricesRequest request, string environment) { var currentSwitchesApiResponse = await _ehlHttpClient.GetApiResponse <ApiResponse>(request.CurrentSupplyUrl, environment).ConfigureAwait(false); CheckSuccessReponse("CustomerSupplyStage", currentSwitchesApiResponse); request.PopulateCurrentSupplyWithRequestData(currentSwitchesApiResponse); var currentSwitchesApiPostResponse = await _ehlHttpClient.PostApiGetResponse(request.CurrentSupplyUrl, currentSwitchesApiResponse, environment).ConfigureAwait(false); return(ApiCallResponse("CustomerSupplyStage", currentSwitchesApiPostResponse, EhlApiConstants.UsageRel)); }
private static void PopulateSpendUsageForGas(GetPricesRequest request, ApiResponse usageTemplate) { if (request.CompareType != CompareWhat.Gas && request.CompareType != CompareWhat.Both) { return; } UpdateItemData(usageTemplate, "gasUsageType", "usageType", EhlApiConstants.UsageTypeBySpend); UpdateItemData(usageTemplate, "gasSpend", "usageAsSpend", request.SpendData.GasSpendAmount.ToString(CultureInfo.InvariantCulture)); UpdateItemData(usageTemplate, "gasSpend", "spendPeriod", ((int)request.SpendData.GasSpendPeriod).ToString()); }
private static void PopulateDetailedUsageForGas(GetPricesRequest request, ApiResponse usageTemplate) { UpdateItemData(usageTemplate, "gasUsageType", "usageType", EhlApiConstants.UsageTypeByEstimator); UpdateItemData(usageTemplate, "gasDetailedEstimate", "houseType", request.EstimatorData.HouseType); UpdateItemData(usageTemplate, "gasDetailedEstimate", "numberOfBedrooms", request.EstimatorData.NumberOfBedrooms); UpdateItemData(usageTemplate, "gasDetailedEstimate", "mainCookingSource", request.EstimatorData.MainCookingSource); UpdateItemData(usageTemplate, "gasDetailedEstimate", "cookingFrequency", ((int)CookingFrequency.Daily).ToString()); UpdateItemData(usageTemplate, "gasDetailedEstimate", "centralHeating", request.EstimatorData.MainHeatingSource); UpdateItemData(usageTemplate, "gasDetailedEstimate", "numberOfOccupants", request.EstimatorData.NumberOfOccupants); UpdateItemData(usageTemplate, "gasDetailedEstimate", "insulation", request.EstimatorData.HouseInsulation); UpdateItemData(usageTemplate, "gasDetailedEstimate", "energyUsage", request.EstimatorData.HouseOccupied); }
private static void SetPriceRequestWithHaveBill(GetPricesRequest request, EnergyRisk risk) { request.UsageData.GasKwh = risk.Bill.GasUsage; request.UsageData.GasUsagePeriod = risk.Bill.GasUsagePeriod; request.UsageData.ElectricityKwh = risk.Bill.ElectricityUsage; request.UsageData.ElectricityUsagePeriod = risk.Bill.ElectricityUsagePeriod; request.SpendData.GasSpendAmount = risk.Bill.GasSpend; request.SpendData.GasSpendPeriod = risk.Bill.GasSpendPeriod; request.SpendData.ElectricitySpendAmount = risk.Bill.ElectricitySpend; request.SpendData.ElectricitySpendPeriod = risk.Bill.ElectricitySpendPeriod; }
public void Setup() { var attachments = Mock.Of <IPersistAttachments>(); var ehlHttpClient = new EhlHttpClient(messageHandler: new WebRequestHandler(), attachmentPersister: attachments); _ehlCommsAggregator = new EhlCommsAggregator(new EhlApiCalls(ehlHttpClient)); _startSwitchHelper = new StartSwitchHelper(ehlHttpClient); var startSwitchResponse = _startSwitchHelper.StartSwitch().Result; _pricesRequest = EntityHelper.GenerateValidPricesRequest(startSwitchResponse); }
private static void SetPriceRequestBillDetails(EnergyRisk risk, GetPricesRequest priceRequest) { switch (risk.EnergyJourneyType) { case EnergyJourneyType.HaveMyBill when risk.Bill != null: SetPriceRequestWithHaveBill(priceRequest, risk); break; case EnergyJourneyType.DontHaveMyBill when risk.NoBill != null: SetPriceRequestWithDontHaveMyBill(priceRequest, risk); break; } }
public static GetPricesRequest PopulatePreferencesWithRequestData(this GetPricesRequest request, ApiResponse preferencesTemplate) { const string filterOptionAll = "105"; const string paymentMethodAny = "-1"; UpdateItemData(preferencesTemplate, "tariffFilterOptions", "tariffFilterOption", filterOptionAll); if (request.PrePayment == "false") { UpdateItemData(preferencesTemplate, "limitToPaymentType", "paymentMethod", paymentMethodAny); } return(request); }
private static void SetPriceRequestWithDontHaveMyBill(GetPricesRequest request, EnergyRisk risk) { request.SpendData.GasSpendAmount = risk.NoBill.GasSpend; request.SpendData.GasSpendPeriod = risk.NoBill.GasSpendPeriod; request.SpendData.ElectricitySpendAmount = risk.NoBill.ElectricitySpend; request.SpendData.ElectricitySpendPeriod = risk.NoBill.ElectricitySpendPeriod; request.EstimatorData.NumberOfBedrooms = risk.NoBill.NumberOfBedrooms.ToString(); request.EstimatorData.NumberOfOccupants = risk.NoBill.NumberOfOccupants.ToString(); request.EstimatorData.MainHeatingSource = risk.NoBill.MainHeatingSource; request.EstimatorData.HeatingUsage = risk.NoBill.HeatingUsage; request.EstimatorData.HouseInsulation = risk.NoBill.HouseInsulation; request.EstimatorData.MainCookingSource = risk.NoBill.MainCookingSource; request.EstimatorData.HouseOccupied = risk.NoBill.HouseOccupied.ToString(); request.EstimatorData.HouseType = risk.NoBill.HouseType; }
public static GetPricesRequest PopulateCurrentSupplyWithRequestData(this GetPricesRequest request, ApiResponse currentSupplyTemplate) { var compareGas = request.CompareType != CompareWhat.Electricity; var compareElec = request.CompareType != CompareWhat.Gas; UpdateItemData(currentSupplyTemplate, "includedFuels", "compareGas", compareGas.ToString()); UpdateItemData(currentSupplyTemplate, "includedFuels", "compareElec", compareElec.ToString()); UpdateItemData(currentSupplyTemplate, "gasTariff", "supplier", request.GasSupplierId.ToString()); UpdateItemData(currentSupplyTemplate, "gasTariff", "supplierTariff", request.GasTariffId.ToString()); UpdateItemData(currentSupplyTemplate, "gasTariff", "paymentMethod", request.GasPaymentMethodId.ToString()); UpdateItemData(currentSupplyTemplate, "elecTariff", "supplier", request.ElectricitySupplierId.ToString()); UpdateItemData(currentSupplyTemplate, "elecTariff", "supplierTariff", request.ElectricityTariffId.ToString()); UpdateItemData(currentSupplyTemplate, "elecTariff", "paymentMethod", request.ElectricityPaymentMethodId.ToString()); UpdateItemData(currentSupplyTemplate, "elecTariff", "economy7", request.ElectricityEco7.ToString()); return(request); }
private static void PopulateKWhUsage(GetPricesRequest request, ApiResponse usageTemplate) { if (!request.CalculateGasBasedOnBillSpend) { UpdateItemData(usageTemplate, "gasUsageType", "usageType", EhlApiConstants.UsageTypeByKWhUsage); UpdateItemData(usageTemplate, "gasKWhUsage", "usageAsKWh", request.UsageData.GasKwh.ToString()); UpdateItemData(usageTemplate, "gasKWhUsage", "usagePeriod", ((int)request.UsageData.GasUsagePeriod).ToString()); } if (request.CalculateElecBasedOnBillSpend) { return; } UpdateItemData(usageTemplate, "elecUsageType", "usageType", EhlApiConstants.UsageTypeByKWhUsage); UpdateItemData(usageTemplate, "elecKWhUsage", "usageAsKWh", request.UsageData.ElectricityKwh.ToString()); UpdateItemData(usageTemplate, "elecKWhUsage", "usagePeriod", ((int)request.UsageData.ElectricityUsagePeriod).ToString()); }
public Market GetPrices(long marketId) { GetPricesRequest request = new GetPricesRequest(); request.MarketIds = new long[] { marketId }; request.NumberAgainstPricesRequired = 3; request.NumberForPricesRequired = 3; GetPricesResponse response = _proxy.GetPrices(request); if (response.ReturnStatus.Code != 0) { throw new Exception(response.ReturnStatus.Description); } // Since only receive one marketId as param then can assume will always be just one market returned. Market[] marketToReturn = MarketConverter.ConvertMarketTypeWithPricesCollection(response.MarketPrices); return(marketToReturn[0]); }
public static GetPricesRequest GenerateValidPricesRequest(StartSwitchResponse response) { var request = new GetPricesRequest { CurrentSupplyUrl = response.CurrentSupplyUrl, SwitchUrl = response.SwitchStatusUrl, CompareType = CompareWhat.Both, GasSupplierId = 59, GasTariffId = 301, GasPaymentMethodId = 2, ElectricitySupplierId = 59, ElectricityTariffId = 301, ElectricityPaymentMethodId = 2, ElectricityEco7 = false, PercentageNightUsage = 0, UseDetailedEstimatorForElectricity = false, UseDetailedEstimatorForGas = false }; request.UsageData.GasKwh = 8000; request.UsageData.GasUsagePeriod = UsagePeriod.Quarterly; request.UsageData.ElectricityKwh = 8000; request.UsageData.ElectricityUsagePeriod = UsagePeriod.Quarterly; request.SpendData.GasSpendAmount = 500; request.SpendData.GasSpendPeriod = UsagePeriod.Annually; request.SpendData.ElectricitySpendAmount = 400; request.SpendData.ElectricitySpendPeriod = UsagePeriod.Annually; request.EstimatorData.HeatingUsage = "1"; request.EstimatorData.HouseInsulation = "1"; request.EstimatorData.HouseOccupied = "1"; request.EstimatorData.HouseType = "4"; request.EstimatorData.MainCookingSource = "1"; request.EstimatorData.MainHeatingSource = "0"; request.EstimatorData.NumberOfBedrooms = "4"; request.EstimatorData.NumberOfOccupants = "4"; return(request); }
public async Task UpdateCurrentSwitchStatus(GetPricesRequest request, string environment) { var switchesUrl = request.SwitchUrl; var ignoreProRataComparison = request.IgnoreProRataComparison; var switchStatus = await _ehlHttpClient.GetApiResponse <SwitchApiResponse>(switchesUrl, environment).ConfigureAwait(false); if (switchStatus?.Links == null) { return; } var proRataUrl = switchStatus.Links.SingleOrDefault(l => l.Rel.Equals(EhlApiConstants.ProRataRel)); if (string.IsNullOrWhiteSpace(proRataUrl?.Uri)) { return; } var proRataTemplate = await _ehlHttpClient.GetApiResponse <ApiResponse>(proRataUrl.Uri, environment).ConfigureAwait(false); var proRataValue = ignoreProRataComparison ? "false" : "true"; proRataTemplate.UpdateItemData("proRataPreference", "preferProRataCalculations", proRataValue); await _ehlHttpClient.PostApiGetResponse(proRataUrl.Uri, proRataTemplate, environment).ConfigureAwait(false); }
public static List <PriceResult> MapToPriceResults(this FutureSupplies ehlResults, GetPricesRequest request) { var mappedResults = new List <PriceResult>(); var ehlResultsSet = ehlResults.Results.First(r => r.SupplyType.Id.Equals(request.CompareType.EhlSupplyType())); foreach (var supply in ehlResultsSet.EnergySupplies) { var paymentMethod = int.Parse(supply.SupplyDetails.PaymentMethod.Id); var priceResult = new PriceResult { AnnualSavings = decimal.Round(supply.ExpectedAnnualSavings, 0), AnnualSpend = decimal.Round(supply.ExpectedAnnualSpend, 0), ElectricityAnnualSavings = supply.ExpectedElecAnnualSavings, ElectricityAnnualSpend = supply.ExpectedElecAnnualSpend, ElectricityEstimatedMonthlyCost = supply.EstimatedElecMonthlyCost, GasAnnualSavings = supply.ExpectedGasAnnualSavings, GasAnnualSpend = supply.ExpectedGasAnnualSpend, GasEstimatedMonthlyCost = supply.EstimatedGasMonthlyCost, ResultId = supply.Id, SupplierId = int.Parse(supply.Supplier.Id), SupplierName = supply.Supplier.Name, SupplierRating = supply.Supplier.ServiceStarRating, TariffId = int.Parse(supply.SupplyDetails.Id), TariffName = supply.SupplyDetails.Name, TariffDetailsUrl = supply.SupplyDetails.FurtherDetails.Uri, PaymentMethod = (PaymentMethodType)paymentMethod, PaymentMethodId = paymentMethod, CanApply = supply.CanApply, CappedOrFixed = supply.SupplyDetails.Attributes.Any(a => a.Equals("CappedOrFixed", StringComparison.InvariantCultureIgnoreCase)), Green = supply.SupplyDetails.Attributes.Any(a => a.Equals("Green", StringComparison.InvariantCultureIgnoreCase)), AccurateMonthlyBilling = supply.SupplyDetails.Attributes.Any(a => a.Equals("AccurateMonthlyBilling", StringComparison.InvariantCultureIgnoreCase)), StayWarm = supply.SupplyDetails.Attributes.Any(a => a.Equals("StayWarm", StringComparison.InvariantCultureIgnoreCase)), Economy10 = supply.SupplyDetails.Attributes.Any(a => a.Equals("Economy10", StringComparison.InvariantCultureIgnoreCase)), PaperLessBilling = supply.SupplyDetails.Attributes.Any(a => a.Equals("PaperlessBilling", StringComparison.InvariantCultureIgnoreCase)), PaperBilling = supply.SupplyDetails.Attributes.Any(a => a.Equals("PaperBilling", StringComparison.InvariantCultureIgnoreCase)), NoStandingCharges = supply.SupplyDetails.Attributes.Any(a => a.Equals("NoStandingCharges", StringComparison.InvariantCultureIgnoreCase)), RenewableFuelPercentage = supply.SupplyDetails.RenewableFuelPercentage, TotalExitFees = CalculateTotalExitFees(request.CompareType, supply.SupplyDetails.ExitFeesGas, supply.SupplyDetails.ExitFeesElectricity), CheapestBigSupplier = PromotionsValidator(supply.Promotions, "CheapestBigSupplier"), CheapestLongFixed = PromotionsValidator(supply.Promotions, "CheapestLongFixed"), CheapestShortFixed = PromotionsValidator(supply.Promotions, "CheapestShortFixed"), Cheapest = PromotionsValidator(supply.Promotions, "Cheapest"), CheapestMediumFixed = PromotionsValidator(supply.Promotions, "CheapestMediumFixed"), CheapestCanApply = PromotionsValidator(supply.Promotions, "CheapestCanApply"), CheapestGreen = PromotionsValidator(supply.Promotions, "CheapestGreen"), CheapestHighestRated = PromotionsValidator(supply.Promotions, "CheapestHighestRated") }; priceResult.SupplierRating = priceResult.SupplierRating > 5 ? 5 : priceResult.SupplierRating; // Key features priceResult.KeyFeatures = supply.SupplyDetails.KeyFeatures.ToPriceFeatures(); // Set CTM custom feature text if (request.TariffCustomFeatureEnabled) { priceResult.CustomFeatureText = SetCustomFeatureText(string.Concat(priceResult.SupplierName, priceResult.TariffName).ToLowerInvariant(), request.CustomFeatures); priceResult.HasTariffCustomFeature = !string.IsNullOrWhiteSpace(priceResult.CustomFeatureText); } mappedResults.Add(priceResult); } return(mappedResults); }
public async Task <List <PriceResult> > PopulatePricesResponseWithFutureSuppliesFromEhl(GetPricesRequest request, string futureSupplyUrl, string environment) { var futureSupplySwitchesApiResponse = await _ehlHttpClient.GetApiResponse <ApiResponse>(futureSupplyUrl, environment).ConfigureAwait(false); CheckSuccessReponse("FutureSupplySwitches", futureSupplySwitchesApiResponse); var futureSuppliesUrl = futureSupplySwitchesApiResponse.GetLinkedDataUrl(EhlApiConstants.FutureSuppliesRel); var futureSuppliesGetResponse = await _ehlHttpClient.GetApiResponse <FutureSupplies>(futureSuppliesUrl, environment).ConfigureAwait(false); CheckSuccessReponse("FutureSuppliesSwitches", futureSuppliesGetResponse); return(futureSuppliesGetResponse.MapToPriceResults(request)); }