// Método de Pago: SC private void GenerarPedido_Safetypay_Cash(DatosPedido pedido, Models.PedidoRS resultPedido, UsuarioLogin DtsUsuarioLogin) { Pedido_AW_Repository _pedidoRepository = new Pedido_AW_Repository(); var errorPedido = string.Empty; /*Generamos el codigo en SafetyPay*/ ws_compra.ws_compra Ws_Compra = new ws_compra.ws_compra(); CustomCashPaymentRequestType requestCash = new CustomCashPaymentRequestType(); ws_compra.AmountType objAmountType = new ws_compra.AmountType(); objAmountType.CurrencyID = "150"; /*Valor del dolar para SafetyPay*/ objAmountType.Value = Convert.ToDecimal(pedido.Monto); requestCash.BankID = String.Empty; requestCash.IncludeAllBanks = true; requestCash.TransactionIdentifier = String.Empty; requestCash.MerchantAccount = String.Empty; requestCash.MerchantSalesID = resultPedido.IdPedido.ToString(); requestCash.TrackingCode = ""; requestCash.ExpirationTime = (Convert.ToInt16(pedido.TiempoExpiracionCIP) * 60); requestCash.ExpirationTimeSpecified = true; requestCash.Language = (pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "PE" : "ES"); requestCash.CountryID = "PER"; requestCash.Amount = objAmountType; requestCash.SendEmailToShopper = true; if (requestCash.SendEmailToShopper) { requestCash.CustomerInformation_Value = DtsUsuarioLogin.EmailUsuario; } requestCash.CustomMerchantName = (pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "Destinos Mundiales Perú" : "NMVIAJES"); requestCash.ApplicationID = Convert.ToInt16(pedido.IdWeb); ws_compra.RptaPagoSafetyPay response = new ws_compra.RptaPagoSafetyPay(); if (pedido.IdWeb == Webs_Cid.DM_WEB_ID) { requestCash.WebId = Convert.ToString(pedido.IdWeb); response = Ws_Compra.GenerarPago_SafetyPay_Cash_DM(requestCash); } else { requestCash.IdDepartamento = DtsUsuarioLogin.IdDep; requestCash.IdOficina = DtsUsuarioLogin.IdOfi; response = Ws_Compra.GenerarPago_SafetyPay_Cash(requestCash); } if (response.OperationId != null && response.TransaccionIdentifier != null) { resultPedido.CodigoOperacion = response.OperationId; resultPedido.CodigoTransaction = response.TransaccionIdentifier; resultPedido.CodigoError = "OK"; resultPedido.MensajeError = "Se generó el código de pedido."; } else { resultPedido.CodigoError = "ER"; resultPedido.MensajeError = "GP - Error al intentar generar el CIP"; //return Ok(resultPedido); } Models.RptaPagoSafetyPay RptaPagoSafetyPayBD = _pedidoRepository.Get_Rpta_SagetyPay(resultPedido.IdPedido); List <Models.PaymentLocationType> lstPaymentType = new List <Models.PaymentLocationType>(); if (response.lst_PaymentLocationType != null) { List <Models.PaymentStepType> lstPaymentStep = new List <Models.PaymentStepType>(); List <Models.PaymentInstructionType> lstPaymentInstructions = new List <Models.PaymentInstructionType>(); foreach (ws_compra.PaymentLocationType objPaymentLocationTypeRSTmp in response.lst_PaymentLocationType) { Models.PaymentLocationType objPaymentLocationTypeRS = new Models.PaymentLocationType(); objPaymentLocationTypeRS.Id = objPaymentLocationTypeRSTmp.ID; foreach (ws_compra.PaymentStepType objPaymentStepRSTmp in objPaymentLocationTypeRSTmp.lst_PaymentStepType) { Models.PaymentStepType objPaymentStepRS = new Models.PaymentStepType(); objPaymentStepRS.Step = objPaymentStepRSTmp.Step; objPaymentStepRS.StepSpecified = objPaymentStepRSTmp.StepSpecified; objPaymentStepRS.Value = objPaymentStepRSTmp.Value; lstPaymentStep.Add(objPaymentStepRS); } if (objPaymentLocationTypeRSTmp.PaymentInstructions != null) { foreach (ws_compra.PaymentInstructionType objPaymentInstructionTypeRSTmp in objPaymentLocationTypeRSTmp.PaymentInstructions) { Models.PaymentInstructionType objPaymentInstructionsRS = new Models.PaymentInstructionType(); objPaymentInstructionsRS.Name = objPaymentInstructionTypeRSTmp.Name; objPaymentInstructionsRS.Value = objPaymentInstructionTypeRSTmp.Value; lstPaymentInstructions.Add(objPaymentInstructionsRS); } } objPaymentLocationTypeRS.lstPaymentStepType = lstPaymentStep; objPaymentLocationTypeRS.Name = objPaymentLocationTypeRSTmp.Name; objPaymentLocationTypeRS.PaymentInstructions = lstPaymentInstructions.ToArray(); objPaymentLocationTypeRS.PaymentSteps = lstPaymentStep.ToArray(); lstPaymentType.Add(objPaymentLocationTypeRS); } } /*Realizamos el envio del correo*/ try { IEnviarCorreo objEnviarCorreo = new EnviarCorreo(pedido.UnidadNegocio.ID); DateTime datFechaActual = DateTime.Now; DateTime datFechaExpiraPago; string strExpirationDateTime = response.ExpirationDateTime; string[] arrExp = strExpirationDateTime.Split('('); datFechaExpiraPago = datFechaActual.AddHours(Convert.ToInt16(pedido.TiempoExpiracionCIP)); resultPedido.CorreoEnviado = objEnviarCorreo.Enviar_SolicitudPagoServicioSafetyPay( pedido.IdUsuario.ToString(), Convert.ToInt32(pedido.IdWeb), Convert.ToInt32(pedido.IdLang), pedido.IdCotVta, pedido.Email, null, pedido.NombreClienteCot, pedido.ApellidoClienteCot, null, DtsUsuarioLogin.NomCompletoUsuario, DtsUsuarioLogin.EmailUsuario, (pedido.CodePasarelaPago == Constantes_SafetyPay.CodeSafetyPayCash ? Constantes_Pedido.ID_FORMA_PAGO_SAFETYPAY_CASH : Convert.ToInt16(0)), RptaPagoSafetyPayBD.TransaccionIdentifier, resultPedido.IdPedido, Convert.ToDouble(pedido.Monto), RptaPagoSafetyPayBD.ExpirationDateTime, RptaPagoSafetyPayBD.lstAmountType, lstPaymentType); objEnviarCorreo = null; } catch (Exception ex) { errorPedido = "Error al enviar el correo |" + ex.Message; /*return InternalServerError(ex);*/ } }
// Método de Pago: SO private void GenerarPedido_Safetypay_Online(DatosPedido pedido, Models.PedidoRS resultPedido, UsuarioLogin DtsUsuarioLogin) { var strEmailsCli = pedido.Email; var ws_SafetyPay = new ws_compra.ws_compra(); var request = new CustomOnlinePaymentRequestType(); var objAmountType = new ws_compra.AmountType(); objAmountType.CurrencyID = CurrencyEnumType.USD.ToString(); objAmountType.Value = decimal.TryParse(pedido.MontoPagar.ToString(), out decimal dblMontoPagar) ? dblMontoPagar : 0; request.BankID = string.Empty; request.TransactionIdentifier = string.Empty; request.MerchantAccount = string.Empty; request.MerchantSalesID = resultPedido.IdPedido.ToString(); request.TrackingCode = "0"; request.ExpirationTime = pedido.TiempoExpiracionCIP ?? 0 * 60; request.ExpirationTimeSpecified = true; request.Language = pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "PE": "ES"; request.CountryID = "PER"; request.Amount = objAmountType; request.TransactionOkURL = pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "http://www.destinosmundialesperu.com/" : "http://www.nmviajes.com/"; request.TransactionErrorURL = pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "http://www.destinosmundialesperu.com/" : "http://www.nmviajes.com/seguros#"; request.SendEmailToShopper = true; if (request.SendEmailToShopper) { request.CustomerInformation_Value = DtsUsuarioLogin.EmailUsuario; } request.IdDepartamento = DtsUsuarioLogin.IdDep; request.IdOficina = DtsUsuarioLogin.IdOfi; request.ApplicationID = (short)(pedido.IdWeb ?? 0); //var respond As ws_srv_gnm.ws_compra.RptaPagoSafetyPay ws_compra.RptaPagoSafetyPay respond; if (pedido.IdWeb == Webs_Cid.DM_WEB_ID) { request.WebId = pedido.IdWeb ?? 0; respond = ws_SafetyPay.GenerarPago_SafetyPay_OnlineDM(request); } else { request.IdDepartamento = DtsUsuarioLogin.IdDep; request.IdOficina = DtsUsuarioLogin.IdOfi; respond = ws_SafetyPay.GenerarPago_SafetyPay_Online(request); } var objRptaPagoSafetyPay = (new Pedido_AW_Repository()).Get_Rpta_SagetyPay(resultPedido.IdPedido); var lstPaymentType = new List <Models.PaymentLocationType>(); if (respond.lst_PaymentLocationType != null) { var lstPaymentStep = new List <Models.PaymentStepType>(); var lstPaymentInstructions = new List <Models.PaymentInstructionType>(); foreach (var objPaymentLocationTypeRSTmp in respond.lst_PaymentLocationType) { var objPaymentLocationTypeRS = new Models.PaymentLocationType(); objPaymentLocationTypeRS.Id = objPaymentLocationTypeRSTmp.ID; foreach (var objPaymentStepRSTmp in objPaymentLocationTypeRSTmp.lst_PaymentStepType) { var objPaymentStepRS = new Models.PaymentStepType(); objPaymentStepRS.Step = objPaymentStepRSTmp.Step; objPaymentStepRS.StepSpecified = objPaymentStepRSTmp.StepSpecified; objPaymentStepRS.Value = objPaymentStepRSTmp.Value; lstPaymentStep.Add(objPaymentStepRS); } if (objPaymentLocationTypeRSTmp.PaymentInstructions != null) { foreach (var objPaymentInstructionTypeRSTmp in objPaymentLocationTypeRSTmp.PaymentInstructions) { var objPaymentInstructionsRS = new Models.PaymentInstructionType(); objPaymentInstructionsRS.Name = objPaymentInstructionTypeRSTmp.Name; objPaymentInstructionsRS.Value = objPaymentInstructionTypeRSTmp.Value; lstPaymentInstructions.Add(objPaymentInstructionsRS); } } objPaymentLocationTypeRS.lstPaymentStepType = lstPaymentStep; objPaymentLocationTypeRS.Name = objPaymentLocationTypeRSTmp.Name; objPaymentLocationTypeRS.PaymentInstructions = lstPaymentInstructions.ToArray(); objPaymentLocationTypeRS.PaymentSteps = lstPaymentStep.ToArray(); lstPaymentType.Add(objPaymentLocationTypeRS); } } var intIdFormaPago = Constantes_Pedido.ID_FORMA_PAGO_SAFETYPAY_ONLINE; try { var objEnviarCorreo = new EnviarCorreo(); var datFechaActual = DateTime.Now; //var datFechaExpiraPago As Date var strExpirationDateTime = respond.ExpirationDateTime; var arrExp = strExpirationDateTime.Split('('); var datFechaExpiraPago = resultPedido.FechaExpiracion = datFechaActual.AddHours(pedido.TiempoExpiracionCIP ?? 0); resultPedido.CorreoEnviado = objEnviarCorreo.Enviar_SolicitudPagoServicioSafetyPay( pedido.IdUsuario.ToString(), Convert.ToInt32(pedido.IdWeb), Convert.ToInt32(pedido.IdLang), pedido.IdCotVta, pedido.Email, null, pedido.NombreClienteCot, pedido.ApellidoClienteCot, null, DtsUsuarioLogin.NomCompletoUsuario, DtsUsuarioLogin.EmailUsuario, (pedido.CodePasarelaPago == Constantes_SafetyPay.CodeSafetyPayOnline ? Constantes_Pedido.ID_FORMA_PAGO_SAFETYPAY_ONLINE : Convert.ToInt16(0)), objRptaPagoSafetyPay.TransaccionIdentifier, resultPedido.IdPedido, Convert.ToDouble(pedido.Monto), objRptaPagoSafetyPay.ExpirationDateTime, objRptaPagoSafetyPay.lstAmountType, lstPaymentType); } catch (Exception ex) { throw ex; } }
public IHttpActionResult Create(Pedido pedido) { Models.PedidoRS _resultpedido = new Models.PedidoRS(); UsuarioLogin DtsUsuarioLogin = null; var errorPedido = string.Empty; bool _return = false; try { /*Validaciones*/ validacionPedido(ref pedido, ref _resultpedido, ref _return, ref DtsUsuarioLogin); if (_return == true) { return(Ok(_resultpedido)); } RepositoryByBusiness(pedido.UnidadNegocio.ID); /*Generamos el Pedido*/ var operation = _pedidoRepository.Create(pedido); if (operation[Operation.Result].ToString() == ResultType.Success.ToString() && Convert.ToInt32(operation[OutParameter.IdPedido].ToString()) > 0) { _resultpedido.IdPedido = Convert.ToInt32(operation[OutParameter.IdPedido].ToString()); //Actualizamos el campo solicitado por CRM SalesForce asociado al numero de pedido _pedidoRepository.Update_Pedido_SolicitudPago_SF(_resultpedido.IdPedido, pedido.IdCotVta, pedido.IdOportunidad_SF, pedido.IdSolicitudpago_SF); } else { //_resultpedido.CodigoError = "GP"; _resultpedido.MensajeError = "Error al intentar generar el pedido"; _resultpedido.CodigoError = "ER"; _resultpedido.MensajeError = "GP - Error al intentar generar el pedido"; return(Ok(_resultpedido)); } /*Generamos el codigo en SafetyPay*/ ws_compra.ws_compra Ws_Compra = new ws_compra.ws_compra(); CustomOnlinePaymentRequestType request = new CustomOnlinePaymentRequestType(); ws_compra.AmountType objAmountType = new ws_compra.AmountType(); objAmountType.CurrencyID = "150"; /*Valor del dolar para SafetyPay*/ objAmountType.Value = Convert.ToDecimal(pedido.Monto); request.BankID = String.Empty; request.TransactionIdentifier = String.Empty; request.MerchantAccount = String.Empty; request.MerchantSalesID = _resultpedido.IdPedido.ToString(); request.TrackingCode = "0"; request.ExpirationTime = (Convert.ToInt16(pedido.TiempoExpiracionCIP) * 60); request.ExpirationTimeSpecified = true; request.Language = (pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "PE" : "ES"); request.CountryID = "PER"; request.Amount = objAmountType; request.TransactionOkURL = (pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "http://www.destinosmundialesperu.com/" : "http://www.nmviajes.com/"); request.TransactionErrorURL = (pedido.IdWeb == Webs_Cid.DM_WEB_ID ? "http://www.destinosmundialesperu.com/" : "http://www.nmviajes.com/seguros#"); request.SendEmailToShopper = true; if (request.SendEmailToShopper) { request.CustomerInformation_Value = DtsUsuarioLogin.EmailUsuario; } request.IdDepartamento = DtsUsuarioLogin.IdDep; request.IdOficina = DtsUsuarioLogin.IdOfi; request.ApplicationID = Convert.ToInt16(pedido.IdWeb); ws_compra.RptaPagoSafetyPay response = new ws_compra.RptaPagoSafetyPay(); if (pedido.IdWeb == Webs_Cid.DM_WEB_ID || (pedido.IdCanalVta != null && pedido.IdCanalVta == Constantes_Pedido.ID_CANAL_VENTA_CONTACT_CENTER)) { request.WebId = Convert.ToInt32(pedido.IdWeb); response = Ws_Compra.GenerarPago_SafetyPay_OnlineDM(request); } else { response = Ws_Compra.GenerarPago_SafetyPay_Online(request); } if (response.OperationId != null && response.TransaccionIdentifier != null) { _resultpedido.CodigoOperacion = response.OperationId; _resultpedido.CodigoTransaction = response.TransaccionIdentifier; _resultpedido.CodigoError = "OK"; _resultpedido.MensajeError = "Se generó el código de pedido."; } else { //_resultpedido.CodigoError = "GP"; _resultpedido.MensajeError = "Error al intentar generar el CIP"; _resultpedido.CodigoError = "ER"; _resultpedido.MensajeError = "GP - Error al intentar generar el CIP"; return(Ok(_resultpedido)); } Models.RptaPagoSafetyPay RptaPagoSafetyPayBD = _pedidoRepository.Get_Rpta_SagetyPay(_resultpedido.IdPedido); List <Models.PaymentLocationType> lstPaymentType = new List <Models.PaymentLocationType>(); if (response.lst_PaymentLocationType != null) { List <Models.PaymentStepType> lstPaymentStep = new List <Models.PaymentStepType>(); List <Models.PaymentInstructionType> lstPaymentInstructions = new List <Models.PaymentInstructionType>(); foreach (ws_compra.PaymentLocationType objPaymentLocationTypeRSTmp in response.lst_PaymentLocationType) { Models.PaymentLocationType objPaymentLocationTypeRS = new Models.PaymentLocationType(); objPaymentLocationTypeRS.Id = objPaymentLocationTypeRSTmp.ID; foreach (ws_compra.PaymentStepType objPaymentStepRSTmp in objPaymentLocationTypeRSTmp.lst_PaymentStepType) { Models.PaymentStepType objPaymentStepRS = new Models.PaymentStepType(); objPaymentStepRS.Step = objPaymentStepRSTmp.Step; objPaymentStepRS.StepSpecified = objPaymentStepRSTmp.StepSpecified; objPaymentStepRS.Value = objPaymentStepRSTmp.Value; lstPaymentStep.Add(objPaymentStepRS); } if (objPaymentLocationTypeRSTmp.PaymentInstructions != null) { foreach (ws_compra.PaymentInstructionType objPaymentInstructionTypeRSTmp in objPaymentLocationTypeRSTmp.PaymentInstructions) { Models.PaymentInstructionType objPaymentInstructionsRS = new Models.PaymentInstructionType(); objPaymentInstructionsRS.Name = objPaymentInstructionTypeRSTmp.Name; objPaymentInstructionsRS.Value = objPaymentInstructionTypeRSTmp.Value; lstPaymentInstructions.Add(objPaymentInstructionsRS); } } objPaymentLocationTypeRS.lstPaymentStepType = lstPaymentStep; objPaymentLocationTypeRS.Name = objPaymentLocationTypeRSTmp.Name; objPaymentLocationTypeRS.PaymentInstructions = lstPaymentInstructions.ToArray(); objPaymentLocationTypeRS.PaymentSteps = lstPaymentStep.ToArray(); lstPaymentType.Add(objPaymentLocationTypeRS); } } /*Realizamos el envio del correo*/ try { IEnviarCorreo objEnviarCorreo = new EnviarCorreo(pedido.UnidadNegocio.ID); DateTime datFechaActual = DateTime.Now; DateTime datFechaExpiraPago; string strExpirationDateTime = response.ExpirationDateTime; string[] arrExp = strExpirationDateTime.Split('('); datFechaExpiraPago = datFechaActual.AddHours(Convert.ToInt16(pedido.TiempoExpiracionCIP)); _resultpedido.CorreoEnviado = objEnviarCorreo.Enviar_SolicitudPagoServicioSafetyPay(pedido.IdUsuario.ToString(), Convert.ToInt32(pedido.IdWeb), Convert.ToInt32(pedido.IdLang), pedido.IdCotVta, pedido.Email, null, pedido.NombreClienteCot, pedido.ApellidoClienteCot, null, DtsUsuarioLogin.NomCompletoUsuario, DtsUsuarioLogin.EmailUsuario, (pedido.CodePasarelaPago == Constantes_SafetyPay.CodeSafetyPayOnline ? Constantes_Pedido.ID_FORMA_PAGO_SAFETYPAY_ONLINE : Convert.ToInt16(0)), RptaPagoSafetyPayBD.TransaccionIdentifier, _resultpedido.IdPedido, Convert.ToDouble(pedido.Monto), RptaPagoSafetyPayBD.ExpirationDateTime, RptaPagoSafetyPayBD.lstAmountType, lstPaymentType); objEnviarCorreo = null; } catch (Exception ex) { errorPedido = "Error al enviar el correo |" + ex.Message; /*return InternalServerError(ex);*/ } /*Inserta Forma de Pedido*/ _pedidoRepository.InsertFormaPagoPedido(pedido, _resultpedido); _pedidoRepository.Update_FechaExpira_Pedido(pedido, _resultpedido); /*Insertamos el POST en el SRV*/ string strTextoPost = "<span class='texto_cambio_estado'>Cambio de estado a <strong>Pendiente de Pago</strong></span><br><br>" + "La pasarela de pago ha actualizado el estado de su cotización."; ICotizacionSRV_Repository _CotizacionSRV = new CotizacionSRV_AW_Repository(pedido.UnidadNegocio.ID); Post_SRV _PostSRV_RQ = new Post_SRV() { IdCot = pedido.IdCotVta, TipoPost = Convert.ToInt16(Constantes_SRV.ID_TIPO_POST_SRV_USUARIO), TextoPost = strTextoPost, IPUsuCrea = (string.IsNullOrEmpty(pedido.IPUsuario) ? "127.0.0.0" : pedido.IPUsuario), LoginUsuCrea = DtsUsuarioLogin.LoginUsuario, IdUsuWeb = DtsUsuarioLogin.IdUsuario, IdDep = DtsUsuarioLogin.IdDep, IdOfi = DtsUsuarioLogin.IdOfi, Archivos = null, LstFilesPTA = null, IdEstado = Constantes_SRV.ID_ESTADO_COT_PENDIENTE_PAGO, CambioEstado = true, LstFechasCotVta = null, EsAutomatico = true, ArchivoMail = null, EsCounterAdmin = false, IdUsuWebCounterCrea = null, IdOfiCounterCrea = null, IdDepCounterCrea = null, EsUrgenteEmision = null, FecPlazoEmision = null, IdMotivoNoCompro = null, OtroMotivoNoCompro = null, MontoEstimadoFile = null }; _CotizacionSRV.ProcesosPostCotizacion(_PostSRV_RQ); return(Ok(_resultpedido)); } catch (Exception ex) { errorPedido = ex.Message; return(InternalServerError(ex)); } finally { (new { Request = pedido, Response = _resultpedido, Exception = errorPedido }).TryWriteLogObject(_logFileManager, _clientFeatures); } }