public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { if (sessionID.Equals("0")) { return new GetLastDistributionsResponseBody() { ResponseCode = 90, ResponseMessage = "error session", TransactionID = 0, Distributions = new DistributionList() } } ; GetLastDistributionsRequestBody request = requestObject as GetLastDistributionsRequestBody; GetLastDistributionsResponseBody response = null; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[GetLastDistributionsProvider] [SEND-DATA] getLastDistributionsParameters {agentReference=" + request.Agent + ",count=" + request.Count + "}"); var agentId = new IBank.Utils().GetAgentId(request.AuthenticationData.Username); var result = new IBank.Utils().ListaSolicitudes(agentId, request.Count); response = new GetLastDistributionsResponseBody() { ResponseCode = 0, ResponseMessage = "OK", Distributions = result, //generateRandomDist(request.Count), TransactionID = 0 }; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[GetLastDistributionsProvider] [RECV-DATA] getLastDistributionsResult {response={" + (response.Distributions == null || response.Distributions.Count == 0 ? "" : response.Distributions.ToString()) + "}}"); return(response); }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { if (sessionID.Equals("0")) { return new TransferResponseBody() { ResponseCode = 90, ResponseMessage = "error session", TransactionID = 0, StockBalance = 0m } } ; TransferRequestBody request = requestObject as TransferRequestBody; TransferResponseBody response = null; if (request.AuthenticationData.Username != ConfigurationManager.AppSettings["ProincoUser"]) { return new TransferResponseBody() { Fee = 0, ResponseCode = 99, ResponseMessage = "fallo", TransactionID = 0 } } ; string myAgent = new IBank.Utils().GetAgentPdv(request.Recipient); var distributionResponse = new IBank.Utils().ExecuteDistribution(ConfigurationManager.AppSettings["id_net"], request.ExternalTransactionReference, DateTime.Now, myAgent, request.Amount, ConfigurationManager.AppSettings["AccountProinco"]); if (int.Parse(distributionResponse.responseCode) == 0) { response = new TransferResponseBody() { Fee = 0, ResponseCode = 0, ResponseMessage = distributionResponse.Message, TransactionID = 0 }; } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = 99, ResponseMessage = "fallo", TransactionID = 0 }; } return(response); } } }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { if (sessionID.Equals("0")) { return new InformPaymentResponseBody() { ResponseCode = 90, ResponseMessage = "error session", TransactionID = 0 } } ; InformPaymentRequestBody request = requestObject as InformPaymentRequestBody; InformPaymentResponseBody response = null; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[InformPaymentProvider] [SEND-DATA] informPaymentParameters {amount=" + request.Amount + ",targentAgentId=" + request.TargetAgentId + ",hasDeposit=" + request.HasDeposit + ",accountId=" + request.AccountId + ",transactionReference=" + request.TransactionReference + ",transactionDate=" + request.TransactionDate + ",sucursalNumber=" + request.SucursalNumber + ",sucursalName=" + request.SucursalName + ",comment=" + request.Comment + ",immediatelyDistribute=" + request.ImmediatelyDistribute + "}"); string responseCode = "99", message = "error"; bool result = false; int usrId = new IBank.Utils().GetUserId(request.AuthenticationData.Username); if (request.TargetAgentId > 0) { if (!IsValid(request)) { return(new InformPaymentResponseBody() { ResponseCode = 80, ResponseMessage = "Datos incompletos", TransactionID = 0 }); } string bankAccount = new IBank.Utils().GetBankNumber(request.AccountId); if (request.ImmediatelyDistribute) { //result = new Movilway.API.Service.ExtendedApi.Provider.IBank.Utils().RegistroPago(decimal.Parse(request.TargetAgentId.ToString()), request.Amount, request.TransactionReference, request.TransactionDate, bankAccount, (request.HasDeposit ? "S" : "N"), ref responseCode, ref message, request.Comment, decimal.Parse(request.TransactionReference), DateTime.UtcNow.AddHours(new Movilway.API.Service.ExtendedApi.Provider.IBank.Utils().GetTimeZone())); result = new IBank.Utils().RegistroDepositoAcreditaSaldo(decimal.Parse(request.TargetAgentId.ToString()), usrId, request.Amount, request.TransactionReference, request.TransactionDate, bankAccount, ref responseCode, ref message, request.Comment, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()), request.SucursalNumber.ToString(), request.SucursalName); } else { result = new IBank.Utils().RegistrarDeposito(request.TargetAgentId, usrId, request.Amount, request.TransactionReference, request.TransactionDate, bankAccount, request.Comment, ref responseCode, ref message, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()), request.SucursalNumber.ToString(), request.SucursalName); } } else { //int ageId = new IBank.Utils().GetAgentId(request.AuthenticationData.Username); int prodcut = -1; String res = ""; KinacuLogisticsWebService.LogisticsInterface logisticsInterface = new KinacuLogisticsWebService.LogisticsInterface(); result = logisticsInterface.CreateProductRequest(Convert.ToInt32(sessionID), 0, (int)request.Amount * 100, out prodcut, out res); if (result) { responseCode = "00"; message = "TRANSACCION OK"; } else { responseCode = Movilway.API.Core.UtilResut.StrErrorCode(1); message = res; } //result = new IBank.Utils().RegistrarSolicitudProducto(ageId, request.Amount, request.TransactionDate, ref responseCode, ref message); } response = new InformPaymentResponseBody() { ResponseCode = int.Parse(responseCode), ResponseMessage = message, TransactionID = 0 }; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[InformPaymentProvider] [RECV-DATA] informPaymentResult {ResponseCode=" + responseCode + ",ResponseMessage=" + message + ",TransactionID=" + 0 + "}"); return(response); }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { if (sessionID.Equals("0")) { return new ProcessDistributionResponseBody() { ResponseCode = 90, ResponseMessage = "error session", TransactionID = 0 } } ; ProcessDistributionRequestBody request = requestObject as ProcessDistributionRequestBody; ProcessDistributionResponseBody response = null; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] [SEND-DATA] processDistributionParameters {comment=" + request.Comment + ",immediatelyDistribute=" + request.ImmediatelyDistribute + ",isApproved=" + request.IsApproved + ",distributionId=" + request.DistributionId + "}"); string responseCode = "99", message = "error"; DistributionSummary deposit; var isProductRequest = request.AccountId == 0; var result = false; int usrId = new IBank.Utils().GetUserId(request.AuthenticationData.Username); if (isProductRequest) { deposit = new IBank.Utils().GetSolicitudProducto(request.DistributionId); if (request.IsApproved) { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] isProductRequest y isApproved"); //deposit.HasDeposit = false; result = new IBank.Utils().ProcesaSolicitudProducto(deposit.OriginalDistributionID, usrId, deposit.TargetAgentID, deposit.Amount, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()), request.Comment, ref responseCode, ref message); } else { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] isProductRequest y not isApproved"); result = new IBank.Utils().RechazaSolicitudProducto(deposit.OriginalDistributionID, deposit.TargetAgentID, usrId, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()), request.Comment, ref responseCode, ref message); } } else { deposit = new IBank.Utils().GetSolicitud(request.DistributionId); deposit.HasDeposit = true; //TODO escenario prueba dos registro pago // deposit.HasDeposit = false; // if (request.IsApproved) { if (request.ImmediatelyDistribute) { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] not isProductRequest y isApproved y immediatelyDist"); result = new IBank.Utils().RegistroPago(deposit.TargetAgentID, usrId, deposit.Amount, deposit.ReferenceNumber, deposit.DepositDate, deposit.AccountNumber, deposit.HasDeposit ? "S" : "N", ref responseCode, ref message, request.Comment, request.DistributionId, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone())); } else { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] not isProductRequest y isApproved y not immediatelyDist"); result = new IBank.Utils().ProcesaAvisoDeposito(deposit.OriginalDistributionID, deposit.TargetAgentID, usrId, deposit.Amount, deposit.ReferenceNumber, deposit.DepositDate, deposit.AccountNumber, request.Comment, ref responseCode, ref message); } //result = new Movilway.API.Service.ExtendedApi.Provider.IBank.Utils().RegistrarDeposito(deposit.TargetAgentID, deposit.Amount, deposit.ReferenceNumber, deposit.DepositDate, deposit.AccountNumber, request.Comment, ref responseCode, ref message, DateTime.UtcNow.AddHours(new Movilway.API.Service.ExtendedApi.Provider.IBank.Utils().GetTimeZone()), "", ""); } else { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] not isProductRequest y not isApproved"); result = new IBank.Utils().RechazaAvisoDeposito(deposit.OriginalDistributionID, deposit.TargetAgentID, usrId, DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()), request.Comment, ref responseCode, ref message); } } response = new ProcessDistributionResponseBody() { ResponseCode = int.Parse(responseCode), ResponseMessage = message, TransactionID = 0 }; logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[ProcessDistributionProvider] [RECV-DATA] processDistributionResult {response={" + responseCode + "," + message + "}}"); return(response); } }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { TransferCommissionRequestBody request = requestObject as TransferCommissionRequestBody; TransferCommissionResponseBody response = null; string rootagency = ConfigurationManager.AppSettings["rootagency"] ?? "4"; int sourceUserId = 0, recipientAgentId = 0; string accessReceiver = ""; bool requestHasPDV = !String.IsNullOrEmpty(request.RecipientPdv); //LA AGENCIA RAIZ PUEDE TRANSFERIR UNA COMISION AL PDV //LA AGENCIA RAIZ BUSCA EL PADRE Y HACE QUE EL PADRE TRANSFIERA LA COMISION if (sessionID.Equals("0")) { response = new TransferCommissionResponseBody() { ResponseCode = requestHasPDV ? 3 : 90, ResponseMessage = requestHasPDV ? "ID Inactivo" : "error session", TransactionID = 0, StockBalance = 0m }; response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); return(response); } try { sourceUserId = new IBank.Utils().GetUserId(request.AuthenticationData.Username); } catch (Exception) { response = new TransferCommissionResponseBody() { ResponseCode = 99, ResponseMessage = "ERROR OBTENIENDO USUARIO ID", TransactionID = 0, StockBalance = 0m }; return(response); } int recipientId = 0; bool recipientIsNumeric = int.TryParse(request.Recipient, out recipientId); if (!recipientIsNumeric && String.IsNullOrEmpty(request.RecipientPdv)) { response = new TransferCommissionResponseBody() { ResponseCode = 99, ResponseMessage = "RecipientPdv NO PUEDE SER VACIO", TransactionID = 0, StockBalance = 0m }; return(response); } if (recipientIsNumeric) { recipientAgentId = recipientId; } if (!recipientIsNumeric) { try { recipientAgentId = new IBank.Utils().GetAgentIdByPdv(request.RecipientPdv); accessReceiver = request.Recipient; } catch (Exception ex) { //if (requestHasPDV) // throw e; //else return(new TransferCommissionResponseBody() { ResponseCode = 3, ResponseMessage = "PDV Inactivo", TransactionID = 0, StockBalance = 0m, ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") }); } } if (recipientAgentId != 0) { request.Recipient = recipientAgentId.ToString(); } int sourceAgentId = new IBank.Utils().GetAgentId(request.AuthenticationData.Username); bool isChild = false; IBank.Utils.TransferInfo info = new IBank.Utils.TransferInfo(); info.OverrideRequestCode = request.Code > 0? request.Code: 501; info.OverrideReverseCode = 205; logger.InfoHigh(LOG_PREFIX + " get agent data "); //Ariel 2021-Ma-09 Comentado // var agentinfo = Utils.GetAgentData(base.LOG_PREFIX, recipientAgentId); logger.InfoHigh(LOG_PREFIX + " agent data ok"); switch (request.TransferRequestType) { case TransferRequestType.FromParentToBranch: if (sourceAgentId.ToString() == rootagency) { isChild = true; // seleccionar agencia padre y usuario //Ariel 2021-Ma-09 Comentado asignamos 0 info.AgentParent = 0; // Convert.ToInt32(agentinfo["age_id_sup"]); info.UserTransacctionId = sourceUserId; // info.AgentParent = (int) agentinfo.AgentID; } else { // validar si la agencia es padre //Ariel 2021-Ma-09 Comentado asignamos 0 info.AgentParent = 0;// Convert.ToInt32(agentinfo["age_id_sup"]); info.UserTransacctionId = sourceUserId; if (info.AgentParent != sourceAgentId) { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = 99, ResponseMessage = "No puede hacer asginacion de comision a una agencia que no es hija directa.", //ResponseCode = 90, //ResponseMessage = "Distribución de Saldo Fallida, agencia destino igual a agencia origen", TransactionID = 0 }; return(response); } } break; } if (sourceAgentId == recipientAgentId) { response = new TransferCommissionResponseBody() { Fee = 0, // ResponseCode = requestHasPDV ? 3 : 90, // ResponseMessage = requestHasPDV ? "ID Inactivo" : "Distribución de Saldo Fallida, agencia destino igual a agencia origen", ResponseCode = 90, ResponseMessage = "Comision Fallida, agencia destino igual a agencia origen", //ResponseCode = 90, //ResponseMessage = "Distribución de Saldo Fallida, agencia destino igual a agencia origen", TransactionID = 0 }; // if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); return(response); } bool isNegativeAmount = false; bool acceptReverse = false; if (request.Amount < 0) { isNegativeAmount = true; acceptReverse = new IBank.Utils().CheckReverse(request.Recipient); } if ((isChild && !isNegativeAmount && request.DBTransferIfChild) || (!isChild && !isNegativeAmount) || (isChild && isNegativeAmount && acceptReverse)) { // Acá resultó NO ser hijo(o hijo pero no se quiere afectar cta corriente), así que procedo con la distribución vía SP string autorization = "", messageOut = "", responseCode = "99"; DateTime myNow = Utils.GetLocalTimeZone(); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bCommissionParameters {info=" + info.ToString() + "} {agent_reciver=" + request.Recipient + ",cuenta=" + ConfigurationManager.AppSettings["TransferAccount"] + ",usr_id=" + sourceUserId + ",amount=" + double.Parse(request.Amount.ToString()) + ",reference_number=" + request.ExternalTransactionReference); // + ",date=" + myNow + "}"); //Se valida que el maximo a transferir si es hijo no exceda el límite de crédito (Condición Proesa) if (isChild && !isNegativeAmount && request.DBTransferIfChild) { //Ariel 2021-Ma-09 Comentado devolvemos 0 decimal maxCredit = 0;//Utils.GetAgentMaxCreditAvailable(request.Recipient); if (request.Amount > maxCredit) { logger.ErrorHigh(base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bCommission El monto Excede el máximo de crédito disponible Amount:" + request.Amount + " Limite Credito: " + maxCredit); return(new TransferCommissionResponseBody() { ResponseCode = 99, ResponseMessage = "EL MONTO EXCEDE EL LIMITE DE CREDITO CONFIGURADO", TransactionID = 0, StockBalance = 0m }); } } //decimal newAmount = 0m; var distributionResponse = new IBank.Utils().transferb2bCommission(request.Recipient, accessReceiver, ConfigurationManager.AppSettings["TransferAccount"], sourceUserId, double.Parse(request.Amount.ToString()), request.ExternalTransactionReference, myNow, (isChild && isNegativeAmount && acceptReverse), ref autorization, ref messageOut, ref responseCode, info); //, ref newAmount); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[transferb2bCommission] [RECV-DATA] createCommissionResult {response=" + distributionResponse + ",autorization=" + autorization + ",message=" + messageOut + ",response_code=" + responseCode + "}"); if (int.Parse(responseCode ?? "99") == 0) { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = 0, //ResponseMessage = requestHasPDV ? "activado" : messageOut, ResponseMessage = messageOut, TransactionID = int.Parse(autorization) }; // if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } else { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : int.Parse(responseCode ?? "99"), ResponseMessage = requestHasPDV ? "ID Inactivo" : messageOut, TransactionID = String.IsNullOrEmpty(autorization) ? 99 : int.Parse(autorization) }; // if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } else if (!isChild && isNegativeAmount) { // TODO NEW CONDITION TO MO - Done int[] branchsAllowed = Array.ConvertAll <string, int>(ConfigurationManager.AppSettings["ReversesBranchesAllowed"].Split(','), int.Parse); if (branchsAllowed.Contains(sourceAgentId)) { // TODO Check the debt_amount var debtAmount = Utils.GetTotalDebt(request.Recipient); logger.InfoLow("[MO] " + base.LOG_PREFIX + "[MOApiProvider] [RECV-DATA] totalDebtAmount {response=" + debtAmount + "}"); if (Math.Abs(request.Amount) <= debtAmount) { // Mismo código que arriba string autorization = "", messageOut = "", responseCode = "99"; DateTime myNow = Utils.GetLocalTimeZone(); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bParameters {agent_reciver=" + request.Recipient + ",cuenta=" + ConfigurationManager.AppSettings["TransferAccount"] + ",usr_id=" + sourceUserId + ",amount=" + double.Parse(request.Amount.ToString()) + ",reference_number=" + request.ExternalTransactionReference + ",date=" + myNow + "}"); //decimal newAmount = 0m; var distributionResponse = new IBank.Utils().transferb2b(request.Recipient, accessReceiver, ConfigurationManager.AppSettings["TransferAccount"], sourceUserId, double.Parse(request.Amount.ToString()), request.ExternalTransactionReference, myNow, (isChild && isNegativeAmount && acceptReverse), ref autorization, ref messageOut, ref responseCode); //, ref newAmount, partialCharge: true); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [RECV-DATA] createProductDistributionResult {response=" + distributionResponse + ",autorization=" + autorization + ",message=" + messageOut + ",response_code=" + responseCode + "}"); if (int.Parse(responseCode ?? "99") == 0) { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = 0, ResponseMessage = requestHasPDV ? "activado" : messageOut, TransactionID = int.Parse(autorization) }; //if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } else { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : int.Parse(responseCode ?? "99"), ResponseMessage = requestHasPDV ? "ID Inactivo" : messageOut, TransactionID = String.IsNullOrEmpty(autorization) ? 99 : int.Parse(autorization) }; //if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); //if (!newAmount.Equals(request.Amount)) // response.ChargedAmount = newAmount; } // End } else { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : "El monto a debitar es superior a la deuda actual", TransactionID = 99 }; // if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } else { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : "Debito de stock no permitido", TransactionID = 99 }; //if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } // Validate if the branch is MO (allowed from .config) // if true // query debt amount // if amount <= debt amount // transfer code (up) // else // return error amount too high // else // return error } else { response = new TransferCommissionResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : (isChild && isNegativeAmount && !acceptReverse ? "La agencia no acepta quitas automáticas" : "Error no identificado"), TransactionID = 99 }; //if (requestHasPDV) response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } // Envío de SMS VE si lo tiene habilitado try { if (response.ResponseCode.Equals(0)) { var sendTransferSMS = ConfigurationManager.AppSettings["SendTransferSMS"]; if (!String.IsNullOrEmpty(sendTransferSMS) ? bool.Parse(sendTransferSMS) : false) { var mobilePhone = new IBank.Utils().GetAgentMobilePhone(int.Parse(request.Recipient)); var stockFinal = new IBank.Utils().GetAgentFinalStock(int.Parse(request.Recipient)); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] phone " + mobilePhone); if (mobilePhone.Length.Equals(int.Parse(ConfigurationManager.AppSettings["TelemoPhoneLength"]))) { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] smsToCustomer begin"); Util.SMSTelemoDispatcher.SmsToCustomer(ConfigurationManager.AppSettings["TelemoClientId"], ConfigurationManager.AppSettings["TelemoCustomerId"], mobilePhone, String.Format(ConfigurationManager.AppSettings["TelemoMessageTemplate"], request.Amount.ToString("C"), stockFinal, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()).ToString("HH:mm:ss"))); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] smsToCustomer end"); } } } } catch (Exception ex) { logger.ErrorHigh("[SMS] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] " + ex.Message + ", " + ex.StackTrace); } return(response); }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { TransferRequestBody request = requestObject as TransferRequestBody; TransferResponseBody response = null; int sourceUserId = 0, recipientAgentId = 0; string accessReceiver = ""; bool requestHasPDV = !String.IsNullOrEmpty(request.RecipientPdv); if (sessionID.Equals("0")) { response = new TransferResponseBody() { ResponseCode = requestHasPDV ? 3 : 90, ResponseMessage = requestHasPDV ? "ID Inactivo" : "error session", TransactionID = 0, StockBalance = 0m }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } return(response); } try { sourceUserId = new IBank.Utils().GetUserId(request.AuthenticationData.Username); } catch (Exception) { } int recipientId = 0; bool recipientIsNumeric = int.TryParse(request.Recipient, out recipientId); if (!String.IsNullOrEmpty(request.RecipientPdv)) { try { recipientAgentId = new IBank.Utils().GetAgentIdByPdv(request.RecipientPdv); accessReceiver = request.Recipient; } catch (Exception e) { if (requestHasPDV) { throw e; } else { return new TransferResponseBody() { ResponseCode = 3, ResponseMessage = "ID Inactivo", TransactionID = 0, StockBalance = 0m, ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") } }; } } else if (String.IsNullOrEmpty(request.RecipientAccessId)) { try { recipientAgentId = new IBank.Utils().GetAgentId(request.Recipient); accessReceiver = request.Recipient; } catch (Exception) { } } else { try { //TODO PROBLEMA NAMESAPCE Movilway.API.Service.ExtendedApi.Provider.IBank.Utils().GetAgentId(request.RecipientAccessId); recipientAgentId = new IBank.Utils().GetAgentId(request.RecipientAccessId); accessReceiver = request.RecipientAccessId; } catch (Exception) { if (requestHasPDV) { return new TransferResponseBody() { ResponseCode = 3, ResponseMessage = "ID Inactivo", TransactionID = 0, StockBalance = 0m, ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") } } ; /*request.Recipient = request.RecipientAccessId;*/ } } if (recipientAgentId != 0) { request.Recipient = recipientAgentId.ToString(); } bool isChild = false; bool isNegativeAmount = false; bool acceptReverse = false; int sourceAgentId = new IBank.Utils().GetAgentId(request.AuthenticationData.Username); if (sourceAgentId == recipientAgentId) { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 90, ResponseMessage = requestHasPDV ? "ID Inactivo" : "Distribución de Saldo Fallida, agencia destino igual a agencia origen", //ResponseCode = 90, //ResponseMessage = "Distribución de Saldo Fallida, agencia destino igual a agencia origen", TransactionID = 0 }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } return(response); } if (request.Amount < 0) { isNegativeAmount = true; acceptReverse = new IBank.Utils().CheckReverse(request.Recipient); } var getChildListResponse = new ServiceExecutionDelegator <GetChildListResponseBody, GetChildListRequestBody>().ResolveRequest( new GetChildListRequestBody() { AuthenticationData = new AuthenticationData() { Username = request.AuthenticationData.Username, Password = request.AuthenticationData.Password }, DeviceType = request.DeviceType, Agent = request.AuthenticationData.Username, Platform = "1" }, ApiTargetPlatform.Kinacu, ApiServiceName.GetChildList); if (getChildListResponse.ChildList != null && getChildListResponse.ChildList.Count(ch => ch.Agent == request.Recipient) > 0) { isChild = true; } if (isChild && !isNegativeAmount && !request.DBTransferIfChild) { // Acá resultó ser hijo y debe afectarse la cuenta corriente, así que procedo con la distribución a hijo vía WS LogisticsInterface logisticsWS = new LogisticsInterface(); string message = ""; logger.InfoLow("[KIN] " + base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] createProductDistributionParameters {UserId=" + sessionID + ",RetailerIdTo=" + decimal.Parse(request.Recipient) + ",IdProduct=0,Amount=" + int.Parse((request.Amount * 100).ToString("#")) + "}"); var result = logisticsWS.CreateProductDistribution(int.Parse(sessionID), decimal.Parse(request.Recipient), 0, int.Parse((request.Amount * 100).ToString("#")), out message); var transactionId = new IBank.Utils().GetDistributionId(DateTime.Now, Convert.ToDecimal(sourceAgentId), decimal.Parse(request.Recipient), request.Amount); logger.InfoLow("[KIN] " + base.LOG_PREFIX + "[TransferProvider] [RECV-DATA] createProductDistributionResult {response=" + result + ",message=" + message + "}"); if (result) { response = new TransferResponseBody() { Fee = 0, ResponseCode = 0, ResponseMessage = requestHasPDV ? "activado" : String.Format("Distribución de Saldo Exitosa\nFECHA: {0}\nVENDEDOR: {1}\nID PDV: {2}\nMONTO: {3}", DateTime.Now.ToString("dd/MM/yyyy"), request.AuthenticationData.Username, getChildListResponse.ChildList.Single(ch => ch.Agent == request.Recipient).Name, request.Amount.ToString("N2")), //message, TransactionID = transactionId }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : Utils.BuildResponseCode(result, message), ResponseMessage = requestHasPDV ? "ID Inactivo" : (String.IsNullOrEmpty(message) ? "La distribución es fallida, por favor valide que ingreso el ID correcto del PDV Hijo o que tiene suficiente saldo." : message), //ResponseCode = Utils.BuildResponseCode(result,message), //ResponseMessage = String.IsNullOrEmpty(message) ? "La distribución es fallida, por favor valide que ingreso el ID correcto del PDV Hijo o que tiene suficiente saldo." : message, //message, TransactionID = transactionId }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } } else if ((isChild && !isNegativeAmount && request.DBTransferIfChild) || (!isChild && !isNegativeAmount) || (isChild && isNegativeAmount && acceptReverse)) { // Acá resultó NO ser hijo(o hijo pero no se quiere afectar cta corriente), así que procedo con la distribución vía SP string autorization = "", messageOut = "", responseCode = "99"; DateTime myNow = Utils.GetLocalTimeZone(); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bParameters {agent_reciver=" + request.Recipient + ",cuenta=" + ConfigurationManager.AppSettings["TransferAccount"] + ",usr_id=" + sourceUserId + ",amount=" + double.Parse(request.Amount.ToString()) + ",reference_number=" + request.ExternalTransactionReference); // + ",date=" + myNow + "}"); //Se valida que el maximo a transferir si es hijo no exceda el límite de crédito (Condición Proesa) if (isChild && !isNegativeAmount && request.DBTransferIfChild) { //Ariel 2021-Ma-09 Comentado ponemos cero decimal maxCredit = 0; //Utils.GetAgentMaxCreditAvailable(request.Recipient); if (request.Amount > maxCredit) { logger.ErrorHigh(base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bParameters El monto Excede el máximo de crédito disponible Amount:" + request.Amount + " Limite Credito: " + maxCredit); return(new TransferResponseBody() { ResponseCode = 99, ResponseMessage = "EL MONTO EXCEDE EL LIMITE DE CREDITO CONFIGURADO", TransactionID = 0, StockBalance = 0m }); } } //decimal newAmount = 0m; var distributionResponse = new IBank.Utils().transferb2b(request.Recipient, accessReceiver, ConfigurationManager.AppSettings["TransferAccount"], sourceUserId, double.Parse(request.Amount.ToString()), request.ExternalTransactionReference, myNow, (isChild && isNegativeAmount && acceptReverse), ref autorization, ref messageOut, ref responseCode); //, ref newAmount); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [RECV-DATA] createProductDistributionResult {response=" + distributionResponse + ",autorization=" + autorization + ",message=" + messageOut + ",response_code=" + responseCode + "}"); if (int.Parse(responseCode ?? "99") == 0) { response = new TransferResponseBody() { Fee = 0, ResponseCode = 0, ResponseMessage = requestHasPDV ? "activado" : messageOut, TransactionID = int.Parse(autorization) }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : int.Parse(responseCode ?? "99"), ResponseMessage = requestHasPDV ? "ID Inactivo" : messageOut, TransactionID = String.IsNullOrEmpty(autorization) ? 99 : int.Parse(autorization) }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } } else if (!isChild && isNegativeAmount) { // TODO NEW CONDITION TO MO - Done int[] branchsAllowed = Array.ConvertAll <string, int>(ConfigurationManager.AppSettings["ReversesBranchesAllowed"].Split(','), int.Parse); if (branchsAllowed.Contains(sourceAgentId)) { // TODO Check the debt_amount var debtAmount = Utils.GetTotalDebt(request.Recipient); logger.InfoLow("[MO] " + base.LOG_PREFIX + "[MOApiProvider] [RECV-DATA] totalDebtAmount {response=" + debtAmount + "}"); if (Math.Abs(request.Amount) <= debtAmount) { // Mismo código que arriba string autorization = "", messageOut = "", responseCode = "99"; DateTime myNow = Utils.GetLocalTimeZone(); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-DATA] transferb2bParameters {agent_reciver=" + request.Recipient + ",cuenta=" + ConfigurationManager.AppSettings["TransferAccount"] + ",usr_id=" + sourceUserId + ",amount=" + double.Parse(request.Amount.ToString()) + ",reference_number=" + request.ExternalTransactionReference + ",date=" + myNow + "}"); //decimal newAmount = 0m; var distributionResponse = new IBank.Utils().transferb2b(request.Recipient, accessReceiver, ConfigurationManager.AppSettings["TransferAccount"], sourceUserId, double.Parse(request.Amount.ToString()), request.ExternalTransactionReference, myNow, (isChild && isNegativeAmount && acceptReverse), ref autorization, ref messageOut, ref responseCode); //, ref newAmount, partialCharge: true); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [RECV-DATA] createProductDistributionResult {response=" + distributionResponse + ",autorization=" + autorization + ",message=" + messageOut + ",response_code=" + responseCode + "}"); if (int.Parse(responseCode ?? "99") == 0) { response = new TransferResponseBody() { Fee = 0, ResponseCode = 0, ResponseMessage = requestHasPDV ? "activado" : messageOut, TransactionID = int.Parse(autorization) }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : int.Parse(responseCode ?? "99"), ResponseMessage = requestHasPDV ? "ID Inactivo" : messageOut, TransactionID = String.IsNullOrEmpty(autorization) ? 99 : int.Parse(autorization) }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } //if (!newAmount.Equals(request.Amount)) // response.ChargedAmount = newAmount; } // End } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : "El monto a debitar es superior a la deuda actual", TransactionID = 99 }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : "Debito de stock no permitido", TransactionID = 99 }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } // Validate if the branch is MO (allowed from .config) // if true // query debt amount // if amount <= debt amount // transfer code (up) // else // return error amount too high // else // return error } else { response = new TransferResponseBody() { Fee = 0, ResponseCode = requestHasPDV ? 3 : 99, ResponseMessage = requestHasPDV ? "ID Inactivo" : (isChild && isNegativeAmount && !acceptReverse ? "La agencia no acepta quitas automáticas" : "Error no identificado"), TransactionID = 99 }; if (requestHasPDV) { response.ResponseDate = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"); } } try { GetBalanceResponseBody balanceResponse = new ServiceExecutionDelegator <GetBalanceResponseBody, GetBalanceRequestBody>().ResolveRequest(new GetBalanceRequestBody() { AuthenticationData = new AuthenticationData() { Username = request.AuthenticationData.Username, Password = request.AuthenticationData.Password }, DeviceType = request.DeviceType }, ApiTargetPlatform.Kinacu, ApiServiceName.GetBalance); if (response != null) { response.StockBalance = balanceResponse.StockBalance.Value; } } catch (Exception) { } // Envío de SMS VE si lo tiene habilitado try { if (response.ResponseCode.Equals(0)) { var sendTransferSMS = ConfigurationManager.AppSettings["SendTransferSMS"]; if (!String.IsNullOrEmpty(sendTransferSMS) ? bool.Parse(sendTransferSMS) : false) { var mobilePhone = new IBank.Utils().GetAgentMobilePhone(int.Parse(request.Recipient)); var stockFinal = new IBank.Utils().GetAgentFinalStock(int.Parse(request.Recipient)); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] phone " + mobilePhone); if (mobilePhone.Length.Equals(int.Parse(ConfigurationManager.AppSettings["TelemoPhoneLength"]))) { logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] smsToCustomer begin"); Util.SMSTelemoDispatcher.SmsToCustomer(ConfigurationManager.AppSettings["TelemoClientId"], ConfigurationManager.AppSettings["TelemoCustomerId"], mobilePhone, String.Format(ConfigurationManager.AppSettings["TelemoMessageTemplate"], request.Amount.ToString("C"), stockFinal, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.UtcNow.AddHours(new IBank.Utils().GetTimeZone()).ToString("HH:mm:ss"))); logger.InfoLow("[QRY] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] smsToCustomer end"); } } } } catch (Exception ex) { logger.ErrorHigh("[SMS] " + base.LOG_PREFIX + "[TransferProvider] [SEND-SMS] " + ex.Message + ", " + ex.StackTrace); } return(response); } }