public void TestLCR() { var _customerAcct = CustomerAcct.Get(1180); var _customerRoute = CustomerRoute.Get(7248, 40, 258); var _legOutList = RoutingService.Instance.GetTerminationByDestination(_customerAcct, _customerRoute, "5535520312389", 10800); Assert.IsTrue(_legOutList.Count == 2); }
static bool rerateCDR(CDRViewRow_Base pCdrViewRow, IBackgroundWorker pBackgroundWorker) { try { var _customerAcct = CustomerAcct.Get(pCdrViewRow.Customer_acct_id); if (_customerAcct == null) { pBackgroundWorker.ReportStatus(string.Format("ERROR! CustomerAcct NOT FOUND, {0}", pCdrViewRow.Customer_acct_id)); return(false); } var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.RoutingPlanId, pCdrViewRow.Customer_route_id); if (_customerRoute == null) { pBackgroundWorker.ReportStatus(string.Format("ERROR! CustomerRoute NOT FOUND, {0}", pCdrViewRow.Customer_route_id)); return(false); } var _carrierAcct = CarrierAcct.Get(pCdrViewRow.Carrier_acct_id); if (_carrierAcct == null) { pBackgroundWorker.ReportStatus(string.Format("ERROR! CarrierAcct NOT FOUND, {0}", pCdrViewRow.Carrier_acct_id)); return(false); } var _carrierRoute = CarrierRoute.Get(_carrierAcct.Id, pCdrViewRow.Carrier_route_id); if (_carrierRoute == null) { pBackgroundWorker.ReportStatus(string.Format("ERROR! CarrierRoute NOT FOUND, {0}", pCdrViewRow.Carrier_route_id)); return(false); } var _cdr = new Cdr(pCdrViewRow); _customerAcct.RateCall(_customerRoute, ref _cdr); pCdrViewRow.Customer_duration = _cdr.CustomerDuration; pCdrViewRow.Price = _cdr.CustomerPrice; _carrierAcct.RateCall(_carrierRoute, ref _cdr); pCdrViewRow.Carrier_duration = _cdr.CarrierDuration; pCdrViewRow.Cost = _cdr.CarrierCost; } catch (Exception _ex) { pBackgroundWorker.ReportStatus(string.Format("Exception! {0}", _ex.Message)); TimokLogger.Instance.LogRbr(LogSeverity.Critical, "CdrExportController.rerate", string.Format("Exception:\r\n{0}", _ex)); return(false); } return(true); }
int parseCustomer(Cdr pCdr, out CustomerAcct pCustomerAcct, out CustomerRoute pCustomerRoute) { var _result = 0; pCustomerAcct = null; pCustomerRoute = null; try { pCustomerAcct = pCdr.CustomerAcctId > 0 ? CustomerAcct.Get(pCdr.CustomerAcctId) : CustomerAcct.Get(pCdr.DNIS); if (CustomerAcct.NumberOfCallsCounter.ContainsKey(pCustomerAcct.Id)) { if (CustomerAcct.NumberOfCallsCounter[pCustomerAcct.Id] > 0) { T.LogRbr(LogSeverity.Debug, "BillingService.parseCustomer:", string.Format("Calls LIMIT stat, CustomerAcct={0}, NumberOfCalls={1}", pCustomerAcct.Id, CustomerAcct.NumberOfCallsCounter[pCustomerAcct.Id])); CustomerAcct.NumberOfCallsCounter[pCustomerAcct.Id] -= 1; } } //-- get customer route pCustomerRoute = CustomerRoute.Get(pCustomerAcct.ServiceId, pCustomerAcct.RoutingPlanId, pCdr.CustomerBaseRouteId); if (pCustomerRoute == null) { T.LogRbr(LogSeverity.Debug, "BillingService.parseCustomer:", string.Format("Didn't find CustomerRoute by CustomerRouteId={0}", pCdr.CustomerBaseRouteId)); try { pCustomerRoute = CustomerRoute.Get(pCustomerAcct.ServiceId, pCustomerAcct.CallingPlanId, pCustomerAcct.RoutingPlanId, pCdr.DestNumber); } catch { } if (pCustomerRoute == null) { T.LogRbr(LogSeverity.Debug, "BillingService.parseCustomer:", string.Format("Didn't find CustomerRoute by ServiceId={0}, CallingPlanId={1}, DestNumber={2}", pCustomerAcct.ServiceId, pCustomerAcct.CallingPlanId, pCdr.DestNumber)); return(++_result); } } } catch (RbrException _ex) { T.LogRbr(LogSeverity.Error, "BillingService.parseCustomer:", string.Format("Exception:\r\n{0}", _ex.Message)); return(1); } catch (Exception _ex) { T.LogRbr(LogSeverity.Error, "BillingService.parseCustomer:", string.Format("Exception:\r\n{0}", _ex)); return(1); } return(_result); }
public override RbrResult AuthorizeRetail(ISession pSession, out LegIn pLegIn, out List <LegOut> pLegOutOptions) { pLegIn = new LegIn { ANI = pSession.ANI, IP = pSession.OrigIPAddress, IPAndPort = string.Empty, CustomerAcctId = 0, CustomerRouteId = 0, PromptTimeLimit = 0 }; pLegOutOptions = null; try { logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Request: IP={0}, ANI={1}, AccessNumber={2}, CardNumber={3}, DestNumber={4}", pSession.OrigIPAddress, pSession.ANI, pSession.AccessNumber, pSession.CardNumber, pSession.DestNumber)); var _retailService = RetailService.Get(pSession.AccessNumber); var _retailAcct = _retailService.GetRetailAccount(pSession); var _customerAcct = CustomerAcct.Get(_retailAcct.CustomerAcctId); if (CustomerAcct.NumberOfCallsCounter.ContainsKey(_customerAcct.Id)) { if (CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] > _customerAcct.MaxNumberOfCalls) { throw new RbrException(RbrResult.Customer_MaxCallsReached, AUTHORIZE_RETAIL_LABEL, string.Format("CustomerAcct ID={0}, MaxCalls={1}", _customerAcct.Id, CustomerAcct.NumberOfCallsCounter[_customerAcct.Id])); } } else { CustomerAcct.NumberOfCallsCounter.Add(_customerAcct.Id, 0); } CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] += 1; var _destNumber = routingService.CleanDestNumber(string.Empty, pSession.DestNumber); var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.CallingPlanId, _customerAcct.RoutingPlanId, _destNumber); pLegIn.CustomerRouteId = _customerRoute.BaseRouteId; //-- Authorize Wholesale Account var _wholesaleTimeLimit = _customerAcct.Authorize(_customerRoute); //-- Authorize Retail Account int _timeLimit; _retailService.Authorize(pSession, _retailAcct, _customerRoute, out _timeLimit, out pLegIn.PromptTimeLimit); if (_timeLimit > _wholesaleTimeLimit) { logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Customer MaxCallTime REACHED, CustomerAcctId={0}, TimeLimit={1}", _customerAcct.Id, _wholesaleTimeLimit)); _timeLimit = _wholesaleTimeLimit; } if (_timeLimit == 0) { throw new RbrException(RbrResult.Retail_NoBalanceForRoute, AUTHORIZE_RETAIL_LABEL, string.Format("NOT Enough Balance for Route, CustomerAcctId={0}, (W) RouteId={1}", _customerAcct.Id, _customerRoute.WholesaleRouteId)); } //-- propmpt multiplier if (_customerRoute.Multiplier > 0) { pLegIn.PromptTimeLimit = (_timeLimit * _customerRoute.Multiplier) / 100; } else { pLegIn.PromptTimeLimit = _timeLimit; } pLegOutOptions = routingService.GetTerminationByDestination(_customerAcct, _customerRoute, _destNumber, _timeLimit); _retailAcct.UpdateUsage(); //TODO: Move up to IVR for additional LCR calls!! cdrAggrExporter.OnCallSetup(pSession.AccessNumber, pLegOutOptions[0].CarrierAcctId, pLegOutOptions[0].CarrierBaseRouteId, _customerAcct.Id, pLegIn.CustomerRouteId, pSession.OrigIPAddress, IPUtil.ExtractIPAddress(pLegOutOptions[0].DestIPAndPort)); logger.LogRbr(LogSeverity.Status, AUTHORIZE_RETAIL_LABEL, string.Format("Response: Dest#={0}, CalledIP={1}, CustId={2}, CarrierId={3}, CustRouteId={4}, CarrierRouteId={5}, TimeLimit={6}, PTimeLimit={7}", /**/ pLegOutOptions[0].DestNumber, /**/ pLegOutOptions[0].DestIPAndPort, /**/ _customerAcct.Id, /**/ pLegOutOptions[0].CarrierAcctId, /**/ _customerRoute.BaseRouteId, /**/ pLegOutOptions[0].CarrierBaseRouteId, /**/ pLegOutOptions[0].TimeLimit, /**/ pLegIn.PromptTimeLimit)); } catch (RbrException _rbrex) { logger.LogRbr(LogSeverity.Error, AUTHORIZE_RETAIL_LABEL, string.Format("RbrException, from: {0}\r\n{1}", _rbrex.Source, _rbrex.Message)); return(_rbrex.RbrResult); } catch (Exception _ex) { logger.LogRbr(LogSeverity.Critical, AUTHORIZE_RETAIL_LABEL, string.Format("Exception:\r\n{0}", _ex)); return(RbrResult.ExceptionThrown); } return(RbrResult.Success); }
public override RbrResult AuthorizeWholesale(string pCallId, string pOrigIP, string pAlias, string pANI, string pDestNumber, out LegIn pLegIn, out List <LegOut> pLegOutOptions) { pLegIn = new LegIn { ANI = pANI, CustomerAcctId = 0, CustomerRouteId = 0, IP = pOrigIP, IPAndPort = String.Empty, PromptTimeLimit = 0 }; pLegOutOptions = null; var _outDestNumber = pDestNumber; //it may be cleared of inbound prefix and overwritten by outbound Prefix, IntlDialCode try { //-- Resolve OrigEndPoint and strip off origPrefix intl -dialcode: var _origEP = Endpoint.Get(pOrigIP); if (_origEP == null) { throw new RbrException(RbrResult.OrigEP_NotFound, AUTHORIZE_WHOLESALE_LABEL, string.Format("OrigEP IP={0}", pOrigIP)); } _origEP.TakeSample(); pLegIn.IPAndPort = string.Format("{0}:{1}", _origEP.IPAddress, _origEP.Port); if (_origEP.Status != Status.Active) { throw new RbrException(RbrResult.OrigEP_NotActive, AUTHORIZE_WHOLESALE_LABEL, string.Format("OrigEP IP={0}", _origEP.IPAddress)); } //-- Get inbound prefix and clean destNumber var _prefixIn = _origEP.GetPrefixIn(_outDestNumber); _outDestNumber = routingService.CleanDestNumber(_prefixIn, _outDestNumber); //-- First try to get CustomerAcct: var _customerAcct = CustomerAcct.Get(_origEP, _prefixIn); if (_customerAcct == null) { throw new RbrException(RbrResult.Customer_NotFound, AUTHORIZE_WHOLESALE_LABEL, string.Format("CustomerAcct NOT FOUND, OrigEPId={0}, Prefix={1}", _origEP.Id, _prefixIn)); } pLegIn.CustomerAcctId = _customerAcct.Id; //-- Limit CustomerAcct number of Calls if (CustomerAcct.NumberOfCallsCounter.ContainsKey(_customerAcct.Id)) { if (CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] > _customerAcct.MaxNumberOfCalls) { throw new RbrException(RbrResult.Customer_MaxCallsReached, AUTHORIZE_WHOLESALE_LABEL, string.Format("CustomerAcct ID={0}, MaxCalls={1}", _customerAcct.Id, CustomerAcct.NumberOfCallsCounter[_customerAcct.Id])); } } else { CustomerAcct.NumberOfCallsCounter.Add(_customerAcct.Id, 0); } CustomerAcct.NumberOfCallsCounter[_customerAcct.Id] += 1; //-- Get and validate customer route: var _customerRoute = CustomerRoute.Get(_customerAcct.ServiceId, _customerAcct.CallingPlanId, _customerAcct.RoutingPlanId, _outDestNumber); pLegIn.CustomerRouteId = _customerRoute.BaseRouteId; if (_customerRoute.Status != Status.Active) { throw new RbrException(RbrResult.Customer_RouteBlocked, AUTHORIZE_WHOLESALE_LABEL, string.Format("Customer Route BLOCKED, RouteId={0}", _customerRoute)); } //-- Authorize CustomerAcct and get TimeLimit (if PrepaidEnabled): var _timeLimit = _customerAcct.Authorize(_customerRoute); //-- Get best termination choice: pLegOutOptions = routingService.GetTerminationByDestination(_customerAcct, _customerRoute, _outDestNumber, _timeLimit); //TODO: Move up to IVR for additional LCR calls!! cdrAggrExporter.OnCallSetup(string.Empty, pLegOutOptions[0].CarrierAcctId, pLegOutOptions[0].CarrierBaseRouteId, _customerAcct.Id, pLegIn.CustomerRouteId, _origEP.IPAddress, IPUtil.ExtractIPAddress(pLegOutOptions[0].DestIPAndPort)); } catch (RbrException _rbrex) { logger.LogRbr(LogSeverity.Error, AUTHORIZE_WHOLESALE_LABEL, string.Format("RbrException, from: {0}\r\n{1}", _rbrex.Source, _rbrex.Message)); return(_rbrex.RbrResult); } catch (Exception _ex) { logger.LogRbr(LogSeverity.Critical, AUTHORIZE_WHOLESALE_LABEL, string.Format("Exception:\r\n{0}", _ex)); return(RbrResult.ExceptionThrown); } return(RbrResult.Success); }