public async Task <int> FinalBuddyProcessing() { try { BSSAPIHelper bsshelper = new BSSAPIHelper(); OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results); DatabaseResponse serviceCAF = await _orderAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString()); try { foreach (BuddyCheckList b in buddyActionList) { int process = await ProcessBuddy(b, config, (((List <ServiceFees>)serviceCAF.Results)).FirstOrDefault().ServiceCode); } List <BuddyCheckList> unProcessedBuddies = buddyActionList.Where(b => b.IsProcessed == false).ToList(); if (unProcessedBuddies != null && unProcessedBuddies.Count > 0) { foreach (BuddyCheckList upBuddy in unProcessedBuddies) { DatabaseResponse upBuddyCreateResponse = await _orderAccess.CreatePendingBuddyList(upBuddy); } return(0); } else { ProcessOrderQueueMessage(buddyActionList[0].OrderID); return(1); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async Task <int> RemoveBuddyHandler(int orderID, int customerID) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse checkBuddyResponse = await _orderAccess.CheckBuddyToRemove(orderID); if (checkBuddyResponse.ResponseCode == (int)DbReturnValue.RecordExists && checkBuddyResponse.Results != null) { BuddyToRemove buddyToRemove = (BuddyToRemove)checkBuddyResponse.Results; if (buddyToRemove.BuddyRemovalID > 0 && buddyToRemove.IsRemoved == 0 && buddyToRemove.IsPorted != 1) { BSSAPIHelper bsshelper = new BSSAPIHelper(); DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results); DatabaseResponse serviceCAF = await _orderAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString()); DatabaseResponse requestIdToUpdateRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), customerID, (int)BSSCalls.ExistingSession, buddyToRemove.MobileNumber); BSSUpdateResponseObject bssUpdateResponse = new BSSUpdateResponseObject(); try { bssUpdateResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUpdateRes.Results, buddyToRemove.MobileNumber, true); DatabaseResponse updateBuddyRemoval = await _orderAccess.UpdateBuddyRemoval(buddyToRemove.BuddyRemovalID); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BuddyRemovalFailed) + " for Order : " + orderID); } } return(1); } else { return(0); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async Task <List <Recordset> > GetInvoiceList(int customerID) { BSSAPIHelper bsshelper = new BSSAPIHelper(); OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); DatabaseResponse systemConfigResponse = await _orderAccess.GetConfiguration(ConfiType.System.ToString()); DatabaseResponse bssConfigResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi bssConfig = bsshelper.GetGridConfig((List <Dictionary <string, string> >)bssConfigResponse.Results); GridSystemConfig systemConfig = bsshelper.GetGridSystemConfig((List <Dictionary <string, string> >)systemConfigResponse.Results); DatabaseResponse accountResponse = await _orderAccess.GetCustomerBSSAccountNumber(customerID); if (accountResponse.ResponseCode == (int)DbReturnValue.RecordExists) { if (!string.IsNullOrEmpty(((BSSAccount)accountResponse.Results).AccountNumber)) { // Get default daterange in month from config by key - BSSInvoiceDefaultDateRangeInMonths DatabaseResponse dateRangeResponse = ConfigHelper.GetValueByKey(ConfigKeys.BSSInvoiceDefaultDateRangeInMonths.ToString(), _iconfiguration); int rangeInMonths = int.Parse(((string)dateRangeResponse.Results)); DatabaseResponse requestIdRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Customer.ToString(), BSSApis.GetInvoiceDetails.ToString(), customerID, 0, ""); BSSInvoiceResponseObject invoiceResponse = await bsshelper.GetBSSCustomerInvoice(bssConfig, ((BSSAssetRequest)requestIdRes.Results).request_id, ((BSSAccount)accountResponse.Results).AccountNumber, rangeInMonths); if (invoiceResponse.Response.result_code == "0") { // Get download link prefix from config DatabaseResponse downloadLinkResponse = ConfigHelper.GetValueByKey(ConfigKeys.BSSInvoiceDownloadLink.ToString(), _iconfiguration); string downloadLinkPrefix = (string)downloadLinkResponse.Results; foreach (Recordset recordset in invoiceResponse.Response.invoice_details.recordset) { recordset.download_url = downloadLinkPrefix + recordset.bill_id; } return(invoiceResponse.Response.invoice_details.recordset); } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.NoInvoiceFound) + " : " + customerID); return(new List <Recordset>()); } } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.MandatoryFieldMissing) + " for Customer - " + customerID); return(new List <Recordset>()); } } else { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.FailedToGetBillingAccount)); return(new List <Recordset>()); } }
public async Task <string> GetNumberFromBSS(int CustomerID) { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); BSSAPIHelper bsshelper = new BSSAPIHelper(); DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results); DatabaseResponse serviceCAF = await _orderAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString()); DatabaseResponse requestIdRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.GetAssets.ToString(), CustomerID, (int)BSSCalls.NewSession, ""); ResponseObject res = new ResponseObject(); try { res = await bsshelper.GetAssetInventory(config, (((List <ServiceFees>)serviceCAF.Results)).FirstOrDefault().ServiceCode, (BSSAssetRequest)requestIdRes.Results); if (res != null && res.Response != null && res.Response.asset_details != null && (int.Parse(res.Response.asset_details.total_record_count) > 0)) { BSSNumbers numbers = new BSSNumbers(); numbers.FreeNumbers = bsshelper.GetFreeNumbers(res); string number = numbers.FreeNumbers[0].MobileNumber; string json = bsshelper.GetJsonString(numbers.FreeNumbers); // json insert DatabaseResponse updateBssCallFreeNumbers = await _orderAccess.UpdateBSSCallNumbers(json, ((BSSAssetRequest)requestIdRes.Results).userid, ((BSSAssetRequest)requestIdRes.Results).BSSCallLogID); DatabaseResponse requestIdToUpdateMainLineRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), CustomerID, (int)BSSCalls.ExistingSession, number); BSSUpdateResponseObject bssUpdateResponse = new BSSUpdateResponseObject(); try { //line blocking bssUpdateResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUpdateMainLineRes.Results, number, false); if (bsshelper.GetResponseCode(bssUpdateResponse) == "0") { return(number); } else { return(""); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed)); return(""); } } else { return(""); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed)); return(""); } }
public async void ProcessPayment(WebhookNotificationModel notification) { try { string json = JsonConvert.SerializeObject(notification); LogInfo.Information($"Webhooks notification model {json}"); WebhookDataAccess _webhookAccess = new WebhookDataAccess(_iconfiguration); DatabaseResponse webhookLogUpdatedatabaseResponse = _webhookAccess.UpdateMPGSWebhookNotification(notification); // epoch System.IO.File.WriteAllText($@"{GatewayApiConfig.WEBHOOKS_NOTIFICATION_FOLDER}/WebHookNotifications_{notification.Timestamp}.json", json); CheckOutResponseUpdate updateRequest = new CheckOutResponseUpdate { MPGSOrderID = notification.Order.Id, Result = notification.Order.Status }; OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); //update checkout details // DatabaseResponse updateCheckoutDetailsResponse = await _orderAccess.UpdateCheckOutResponse(updateRequest); // retrieve transaction details from MPGS DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.MPGS.ToString()); PaymentHelper gatewayHelper = new PaymentHelper(); GridMPGSConfig gatewayConfig = gatewayHelper.GetGridMPGSConfig((List <Dictionary <string, string> >)configResponse.Results); //Direct capture MID config DatabaseResponse configDirectResponse = await _orderAccess.GetConfiguration(ConfiType.MPGSDirect.ToString()); GridMPGSDirectMIDConfig gatewayDirectConfig = gatewayHelper.GetGridMPGSDirectMerchant((List <Dictionary <string, string> >)configDirectResponse.Results); gatewayConfig = gatewayHelper.GetGridMPGSCombinedConfig(gatewayConfig, gatewayDirectConfig); // Direct capture MID config end TransactionRetrieveResponseOperation transactionResponse = new TransactionRetrieveResponseOperation(); string receipt = gatewayHelper.RetrieveCheckOutTransaction(gatewayConfig, updateRequest); transactionResponse = gatewayHelper.GetPaymentTransaction(receipt); if (webhookLogUpdatedatabaseResponse != null && webhookLogUpdatedatabaseResponse.Results != null) { DatabaseResponse paymentMethodResponse = await _orderAccess.GetPaymentMethodToken((int)webhookLogUpdatedatabaseResponse.Results); PaymentMethod paymentMethod = new PaymentMethod(); paymentMethod = (PaymentMethod)paymentMethodResponse.Results; transactionResponse.TrasactionResponse.CardType = paymentMethod.CardType; transactionResponse.TrasactionResponse.CardHolderName = paymentMethod.CardHolderName; transactionResponse.TrasactionResponse.Token = paymentMethod.Token; } DatabaseResponse paymentProcessingRespose = new DatabaseResponse(); paymentProcessingRespose = await _orderAccess.UpdateCheckOutReceipt(transactionResponse.TrasactionResponse); DatabaseResponse updatePaymentResponse = await _orderAccess.UpdatePaymentResponse(updateRequest.MPGSOrderID, receipt); if (paymentProcessingRespose.ResponseCode == (int)DbReturnValue.TransactionSuccess) { LogInfo.Information(EnumExtensions.GetDescription(DbReturnValue.TransactionSuccess)); QMHelper qMHelper = new QMHelper(_iconfiguration, _messageQueueDataAccess); int processResult = await qMHelper.ProcessSuccessTransaction(updateRequest); if (processResult == 1) { LogInfo.Information(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed)); } else if (processResult == 2) { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed)); } else if (processResult == 3) { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". " + EnumExtensions.GetDescription(CommonErrors.MQSent)); } else if (processResult == 4) { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing Buddy/MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.SourceTypeNotFound) + " for MPGSOrderID" + updateRequest.MPGSOrderID); } else if (processResult == 5) { LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing Buddy/MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.InvalidCheckoutType) + " for MPGSOrderID" + updateRequest.MPGSOrderID); } else { // entry for exceptions from QM Helper, but need to send payment success message to UI as payment already processed LogInfo.Warning(EnumExtensions.GetDescription(CommonErrors.PaymentProcessed) + ". But while processing MQ/EML/SMS " + EnumExtensions.GetDescription(CommonErrors.SystemExceptionAfterPayment) + " for MPGSOrderID" + updateRequest.MPGSOrderID); } } else { LogInfo.Warning(EnumExtensions.GetDescription(DbReturnValue.TransactionFailed)); } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); } }
public async Task <int> HandleRollbackOnAdditionalBuddyProcessingFailure(int customerID, int orderID, List <AdditionalBuddy> additionalBuddies) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); BSSAPIHelper bsshelper = new BSSAPIHelper(); DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results); DatabaseResponse serviceCAF = await _orderAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString()); //unblock all subscribers for the order foreach (AdditionalBuddy buddy in additionalBuddies) { // unblock mainline subscriber - not ported if (buddy.IsPorted == 0) { DatabaseResponse requestIdToUnblockSubscribers = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), customerID, (int)BSSCalls.ExistingSession, buddy.MobileNumber); BSSUpdateResponseObject bssUpdateAdditionalBuddyMainlineUnblockResponse = new BSSUpdateResponseObject(); try { bssUpdateAdditionalBuddyMainlineUnblockResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUnblockSubscribers.Results, buddy.MobileNumber, true); if (bsshelper.GetResponseCode(bssUpdateAdditionalBuddyMainlineUnblockResponse) != "0") { //failed to unblock subscriber number add it to buddy removal table DatabaseResponse logUnblockFailedSubscriber = await _orderAccess.LogUnblockFailedMainline(orderID, buddy); if (logUnblockFailedSubscriber.ResponseCode != (int)DbReturnValue.CreateSuccess) { LogInfo.Warning("Unlocking failed subscriber loging to BuddyRemoval table failed for OrderID:" + orderID + ", MobileNumber:" + buddy.MobileNumber); } } } catch { //failed to unblock subscriber number add it to buddy removal table DatabaseResponse logUnblockFailedSubscriber = await _orderAccess.LogUnblockFailedMainline(orderID, buddy); if (logUnblockFailedSubscriber.ResponseCode != (int)DbReturnValue.CreateSuccess) { LogInfo.Warning("Unlocking failed subscriber loging to BuddyRemoval table failed for OrderID:" + orderID + ", MobileNumber:" + buddy.MobileNumber); } } } } //remove additional buddy for the order from additional buddy table DatabaseResponse removeAdditionalBuddyRes = await _orderAccess.RemoveAdditionalBuddyOnRollBackOrder(orderID); //rollback order DatabaseResponse rollbackResponse = await _orderAccess.RollBackOrder(orderID, "Rollback while processing additional buddy line"); return(1); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }
public async Task <int> AddRemoveBuddyHandler(int orderID, int customerID) { try { OrderDataAccess _orderAccess = new OrderDataAccess(_iconfiguration); // call remove buddy handler here int isRemoved = await RemoveBuddyHandler(orderID, customerID); DatabaseResponse checkAdditionalBuddyResponse = await _orderAccess.CheckAdditionalBuddy(orderID); // check additional Buddy if (checkAdditionalBuddyResponse.ResponseCode == (int)DbReturnValue.RecordExists && checkAdditionalBuddyResponse.Results != null) { List <AdditionalBuddy> additionalBuddies = (List <AdditionalBuddy>)checkAdditionalBuddyResponse.Results; foreach (AdditionalBuddy buddy in additionalBuddies) { if (buddy.OrderAdditionalBuddyID > 0 && buddy.IsProcessed == 0) { BSSAPIHelper bsshelper = new BSSAPIHelper(); DatabaseResponse configResponse = await _orderAccess.GetConfiguration(ConfiType.BSS.ToString()); GridBSSConfi config = bsshelper.GetGridConfig((List <Dictionary <string, string> >)configResponse.Results); DatabaseResponse serviceCAF = await _orderAccess.GetBSSServiceCategoryAndFee(ServiceTypes.Free.ToString()); DatabaseResponse requestIdToGetAdditionalBuddy = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.GetAssets.ToString(), customerID, (int)BSSCalls.NewSession, ""); ResponseObject res = new ResponseObject(); BSSNumbers numbers = new BSSNumbers(); //get a free number for additional buddy try { res = await bsshelper.GetAssetInventory(config, (((List <ServiceFees>)serviceCAF.Results)).FirstOrDefault().ServiceCode, (BSSAssetRequest)requestIdToGetAdditionalBuddy.Results); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BSSConnectionFailed)); // need to unblock all subscribers for the order and roll back the order and return int buddyRollback = await HandleRollbackOnAdditionalBuddyProcessingFailure(customerID, orderID, additionalBuddies); // rollback on bss failure return(3); } if (res != null && res.Response != null && res.Response.asset_details != null && (int.Parse(res.Response.asset_details.total_record_count) > 0)) { numbers.FreeNumbers = bsshelper.GetFreeNumbers(res); //insert these number into database string json = bsshelper.GetJsonString(numbers.FreeNumbers); // json insert DatabaseResponse updateBssCallFeeNumbers = await _orderAccess.UpdateBSSCallNumbers(json, ((BSSAssetRequest)requestIdToGetAdditionalBuddy.Results).userid, ((BSSAssetRequest)requestIdToGetAdditionalBuddy.Results).BSSCallLogID); DatabaseResponse requestIdToUpdateAdditionalBuddyRes = await _orderAccess.GetBssApiRequestId(GridMicroservices.Order.ToString(), BSSApis.UpdateAssetStatus.ToString(), customerID, (int)BSSCalls.ExistingSession, numbers.FreeNumbers[0].MobileNumber); BSSUpdateResponseObject bssUpdateAdditionalBuddyResponse = new BSSUpdateResponseObject(); // block the number for additional buddy try { bssUpdateAdditionalBuddyResponse = await bsshelper.UpdateAssetBlockNumber(config, (BSSAssetRequest)requestIdToUpdateAdditionalBuddyRes.Results, numbers.FreeNumbers[0].MobileNumber, false); // create buddy subscriber with blocked number and the existing main line if (bsshelper.GetResponseCode(bssUpdateAdditionalBuddyResponse) == "0") { CreateBuddySubscriber additinalBuddySubscriberToCreate = new CreateBuddySubscriber { OrderID = orderID, MobileNumber = numbers.FreeNumbers[0].MobileNumber, MainLineMobileNumber = buddy.MobileNumber, UserId = ((BSSAssetRequest)requestIdToUpdateAdditionalBuddyRes.Results).userid }; DatabaseResponse createAdditionalBuddySubscriberResponse = await _orderAccess.CreateBuddySubscriber(additinalBuddySubscriberToCreate); // update if (createAdditionalBuddySubscriberResponse.ResponseCode == (int)DbReturnValue.CreateSuccess) { DatabaseResponse updateBuddyProcessedResponse = await _orderAccess.UpdateAdditionalBuddyProcessing(buddy.OrderAdditionalBuddyID); } } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical) + EnumExtensions.GetDescription(CommonErrors.BuddyRemovalFailed) + " for Order : " + orderID); } } else { // rollback on no assets retunred int buddyRollback = await HandleRollbackOnAdditionalBuddyProcessingFailure(customerID, orderID, additionalBuddies); return(2); } } } } return(1); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); return(0); } }