public object Post(ServicePaymentFormModel model)
        {
            try
            {
                tbPayment payment    = model.ConvertModelToPayment();
                var       createdObj = PaymentFormMock.Instancia().Create(payment);

                var result = model.ConvertPaymentToModel(createdObj);

                if (result.id != 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, result));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                log.Error("Mensaje de Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    log.Error("Inner exception: " + ex.InnerException.Message);
                }
                throw ex;
            }
        }
Exemple #2
0
        public ServicePaymentModel ConvertPaymentToModel(tbPayment payment)
        {
            try
            {
                ServicePaymentFormModel modelForm = base.ConvertPaymentToModel(payment);

                this.id                    = modelForm.id;
                this.usuario               = modelForm.usuario;
                this.concepto              = modelForm.concepto;
                this.monto                 = modelForm.monto;
                this.producto              = modelForm.producto;
                this.cuotas                = modelForm.cuotas;
                this.url_formulario        = modelForm.url_formulario;
                this.emails                = modelForm.emails;
                this.emails_enviados       = modelForm.emails_enviados;
                this.estado_pago           = modelForm.estado_pago;
                this.informacion_adicional = modelForm.informacion_adicional;
                this.fecha                 = modelForm.fecha;

                return(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public tbPayment ActualizarPayment()
        {
            //Inserto en payment detail el post del proveedor
            tbPaymentDetail paymentDetailPost = this.InsertPaymentDetail("POST_VENDOR");

            //Inserto en payment detail el request que voy a realizar a SimpleQueryTx
            tbPaymentDetail paymentDetailSimpleQuery = this.InsertPaymentDetail("SIMPLE_QUERY_TX");

            //Consulto el estado del pago
            NpsBusiness npsBusiness      = new NpsBusiness();
            tbPayment   paymentNpsResult = npsBusiness.ConsultarEstadoDelPago(_transactionId, _idPayment, paymentDetailSimpleQuery);

            //Actualizo tbPaymentDetails
            paymentDetailSimpleQuery = this.UpdatePaymentDetail(paymentDetailSimpleQuery);

            //Obtengo el registro del pago
            tbPayment payment = this.ObtengoPaymentPorId();

            //Actualizo registro del pago, con estado del pago y la informacion adicional
            payment.pst_id = paymentNpsResult.pst_id;
            payment.pay_informacion_adicional = paymentNpsResult.pay_informacion_adicional;
            payment = this.UpdatePayment(payment);

            return(payment);
        }
Exemple #4
0
        public object Post(ServicePaymentFormModel model)
        {
            try
            {
                tbPayment payment = model.ConvertModelToPayment();
                ServicePaymentFormModel response;

                if (payment.pay_id != 0)
                {
                    response = model.ConvertPaymentToModel(this.RecoverPayment(payment));
                }
                else
                {
                    response = model.ConvertPaymentToModel(this.CreatePayment(payment));
                }

                if (response.id != 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, response));
                }

                return(Request.CreateResponse(HttpStatusCode.Conflict));
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    log.Error("Inner exception: " + ex.InnerException.Message);
                }
                throw new Exception("Error Post, ver log para mas detalle: " + ex.Message);
            }
        }
        public ServicePaymentFormModel ConvertPaymentToModel(tbPayment payment)
        {
            try
            {
                ServicePaymentFormModel model = new ServicePaymentFormModel()
                {
                    id                    = payment.pay_id,
                    usuario               = this.getUsuerNameByIdUser(payment.usu_id),
                    estado_pago           = payment.pst_id,
                    concepto              = payment.pay_concepto,
                    monto                 = this.ConvertIntToString(payment.pay_monto),
                    producto              = this.ConvertProductoCode(payment.pay_producto),
                    cuotas                = payment.pay_cuotas,
                    url_formulario        = payment.pay_url_formulario,
                    url_formulario_custom = payment.pay_url_formulario_custom,
                    emails                = payment.pay_email_to,
                    emails_enviados       = payment.pay_cantidad_mails_enviados,
                    informacion_adicional = payment.pay_informacion_adicional,
                    fecha                 = payment.pay_fecha.ToString("dd/MM/yyyy HH:mm:ss")
                };

                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #6
0
 public ServicePaymentFormBusiness(tbPayment payment)
 {
     _idUser   = payment.usu_id;
     _concepto = payment.pay_concepto;
     _monto    = payment.pay_monto;
     _producto = payment.pay_producto;
     _cuotas   = payment.pay_cuotas;
     _email    = payment.pay_email_to;
 }
Exemple #7
0
        public tbPayment GenerarFormularioDePago()
        {
            try
            {
                //Creo el registro en la tabla payment
                tbPayment payment = this.CreatePayment();

                //Creo el detalle del pago
                tbPaymentDetail paymentDetail = this.CreatePaymentDetail(payment);

                //Creo el formulario de pago
                NpsBusiness npsBusiness    = new NpsBusiness();
                string      urlPaymentForm = npsBusiness.CreateForm(payment.pay_id, _monto, _producto, _cuotas, paymentDetail);

                //Actualizo payment detail
                paymentDetail = this.UpdatePaymentDetail(paymentDetail);

                //Actualizo el payment con el formulario de pagos si no retorno nulo
                if (!string.IsNullOrEmpty(urlPaymentForm))
                {
                    //Valido que NPS retorne una url, sino es porque arrojo error y lo dejo registrado en tbPayment
                    //y no envío el mail
                    if (urlPaymentForm.Contains("http"))
                    {
                        //Asigno la url del formulario de pago de la app cliente
                        string vueAppUrl = ConfigurationManager.AppSettings["VUE_APP_URL_FORM"] + "/" + payment.pay_id.ToString();

                        //Actualizo payment con el formulario de pago
                        payment.pay_url_formulario        = urlPaymentForm;
                        payment.pay_url_formulario_custom = vueAppUrl;
                        payment.pst_id = (int)EnumPaymentStatus.PENDIENTE;
                        payment        = this.UpdatePayment(payment);

                        //envio e-mail
                        this.SendEmamil(vueAppUrl);

                        //Actualizo payment con el contador de envio de mails
                        payment.pay_cantidad_mails_enviados++;
                        payment = this.UpdatePayment(payment);
                    }
                    else
                    {
                        //Actualizo payment con el error que arrojo NPS
                        payment.pay_informacion_adicional = urlPaymentForm;
                        payment.pst_id = (int)EnumPaymentStatus.ERROR;
                        payment        = this.UpdatePayment(payment);
                    }
                }

                return(payment);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #8
0
        public tbPayment Delete(tbPayment obj)
        {
            var result = _lista.Where(x => x.pay_id == obj.pay_id).FirstOrDefault();

            if (result != null)
            {
                _lista.Remove(result);
            }
            return(result);
        }
Exemple #9
0
        public tbPayment Create(tbPayment obj)
        {
            obj.pay_id                      = _lista.OrderByDescending(x => x.pay_id).FirstOrDefault().pay_id + 1;
            obj.pst_id                      = (int)EnumPaymentStatus.PROCESANDO;
            obj.pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4572320&t=68fdf1db8ab9b704290b392bf638236a";
            obj.pay_cantidad_mails_enviados = 1;
            obj.pay_fecha                   = DateTime.Now;

            _lista.Add(obj);
            return(obj);
        }
Exemple #10
0
 private tbPayment CreatePayment(tbPayment payment)
 {
     try
     {
         ServicePaymentFormBusiness paymentFormBusiness = new ServicePaymentFormBusiness(payment);
         return(paymentFormBusiness.GenerarFormularioDePago());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private tbPayment UpdatePayment(tbPayment payment)
 {
     try
     {
         payment = paymentBusiness.Update(payment) as tbPayment;
         return(payment);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #12
0
 private tbPayment RecoverPayment(tbPayment payment)
 {
     try
     {
         ServicePaymentFormBusiness paymentFormBusiness = new ServicePaymentFormBusiness();
         return(paymentFormBusiness.RecuperarFormularioDePago(payment.pay_id));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #13
0
        public tbPayment Update(tbPayment obj)
        {
            tbPayment result  = null;
            var       tempObj = _lista.Where(x => x.pay_id == obj.pay_id).FirstOrDefault();

            if (tempObj != null)
            {
                _lista.Remove(tempObj);
                _lista.Add(obj);
                result = obj;
            }
            return(result);
        }
 public object Put(tbPayment obj)
 {
     try
     {
         throw new NotImplementedException();
     }
     catch (Exception ex)
     {
         log.Error("Mensaje de Error: " + ex.Message);
         if (ex.InnerException != null)
         {
             log.Error("Inner exception: " + ex.InnerException.Message);
         }
         throw ex;
     }
 }
Exemple #15
0
 private tbPaymentDetail CreatePaymentDetail(tbPayment payment)
 {
     try
     {
         //Creo el registro del request en payment details
         tbPaymentDetail paymentDetail = new tbPaymentDetail()
         {
             pay_id        = payment.pay_id,
             pde_operacion = "SOLICITUD_FORMULARIO",
             pde_fecha     = DateTime.Now
         };
         paymentDetail = paymentDetailBusiness.Create(paymentDetail) as tbPaymentDetail;
         return(paymentDetail);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #16
0
        public tbPayment RecuperarFormularioDePago(int idPayment)
        {
            try
            {
                tbPayment payment = null;
                bool func(tbPayment x) => x.pay_id == idPayment;

                List <tbPayment> resultList = paymentBusiness.Read(func) as List <tbPayment>;

                if (resultList.Count() > 0)
                {
                    payment = resultList.FirstOrDefault();
                }

                return(payment);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public tbPayment ConvertModelToPayment()
        {
            try
            {
                tbPayment payment = new tbPayment()
                {
                    pay_id       = id,
                    usu_id       = getIdUsuerByName(this.usuario),
                    pay_concepto = this.concepto,
                    pay_monto    = ConvertStringToInt(this.monto),
                    pay_producto = GetProductoCode(this.producto),
                    pay_cuotas   = cuotas,
                    pay_email_to = emails
                };

                return(payment);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #18
0
 private tbPayment CreatePayment()
 {
     try
     {
         //Creo el registro de pago
         tbPayment payment = new tbPayment()
         {
             usu_id       = _idUser,
             pst_id       = (int)EnumPaymentStatus.PROCESANDO,
             pay_concepto = _concepto,
             pay_monto    = _monto,
             pay_producto = _producto,
             pay_cuotas   = _cuotas,
             pay_email_to = _email,
             pay_fecha    = DateTime.Now
         };
         payment = paymentBusiness.Create(payment) as tbPayment;
         return(payment);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #19
0
        protected PaymentFormMock()
        {
            _lista = new List <tbPayment>();

            payment = new tbPayment()
            {
                pay_id                      = 1,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.PAGADO,
                pay_concepto                = "asd",
                pay_monto                   = 1000,
                pay_producto                = 14,
                pay_cuotas                  = 1,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4554203&t=cb128f66f0fd088eb18e63557edfee4c",
                pay_email_to                = "*****@*****.**",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-05T17:32:44.453")
            };
            _lista.Add(payment);

            payment = new tbPayment()
            {
                pay_id                      = 2,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.PENDIENTE,
                pay_concepto                = "asd",
                pay_monto                   = 2000,
                pay_producto                = 14,
                pay_cuotas                  = 1,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4558369&t=313d1fd99e27f71afe2be2dbef511a5a",
                pay_email_to                = "[email protected];[email protected]",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-08T15:55:51.563")
            };
            _lista.Add(payment);

            payment = new tbPayment()
            {
                pay_id                      = 3,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.ERROR,
                pay_concepto                = "asd",
                pay_monto                   = 2115,
                pay_producto                = 14,
                pay_cuotas                  = 1,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4558431&t=605ce7ec2365dd5c99bf20705b004cd0",
                pay_email_to                = "[email protected];[email protected]",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-08T16:25:56.013")
            };
            _lista.Add(payment);

            payment = new tbPayment()
            {
                pay_id                      = 4,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.PAGADO,
                pay_concepto                = "asd",
                pay_monto                   = 2335,
                pay_producto                = 14,
                pay_cuotas                  = 1,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4558462&t=bbc25065487ab2a16f54990746b42720",
                pay_email_to                = "[email protected];[email protected]",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-08T16:36:59.36")
            };
            _lista.Add(payment);

            payment = new tbPayment()
            {
                pay_id                      = 5,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.PENDIENTE,
                pay_concepto                = "2 pintas",
                pay_monto                   = 1545,
                pay_producto                = 14,
                pay_cuotas                  = 2,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4558685&t=42f1e14a16fef8fd006dd2ba89f957ad",
                pay_email_to                = "*****@*****.**",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-08T18:32:39.57")
            };
            _lista.Add(payment);

            payment = new tbPayment()
            {
                pay_id                      = 6,
                usu_id                      = 1,
                pst_id                      = (int)EnumPaymentStatus.ERROR,
                pay_concepto                = "5 pintas",
                pay_monto                   = 1195,
                pay_producto                = 14,
                pay_cuotas                  = 2,
                pay_url_formulario          = "https://implementacion.nps.com.ar/psp3p_gen_form.php?id=4560468&t=d149726e910712efdc92464e0a5f372a",
                pay_email_to                = "*****@*****.**",
                pay_cantidad_mails_enviados = 1,
                pay_fecha                   = Convert.ToDateTime("2020-08-09T18:38:17.04")
            };
            _lista.Add(payment);
        }
        public object Post(HttpRequestMessage request)
        {
            try
            {
                string[] parametros = request.Content.ReadAsStringAsync().Result.Split('&');
                ServicePaymentFormListenerModel model = new ServicePaymentFormListenerModel();
                tbPayment paymentResult;

                foreach (var p in parametros)
                {
                    string[] value = p.Split('=');
                    if (p.Contains("psp_TransactionId"))
                    {
                        model.psp_TransactionId = value[1];
                    }

                    if (p.Contains("psp_MerchTxRef"))
                    {
                        model.psp_MerchTxRef = value[1];
                    }
                }

                //Este parseo se hace unicamente porque tengo como merchTxRef CARG0-00001-idPayment
                string[] arregloTemp   = model.psp_MerchTxRef.Split('-');
                string   idPaymentTemp = arregloTemp[2];
                int      idPayment     = Int32.Parse(idPaymentTemp);

                //Esta parseo deberia ir, se deja el de arriba solo par avanzar el desarrollo
                //int idPayment = Int32.Parse(model.psp_MerchTxRef);

                //Antes de hacer un hit en NPS consulto el estado del pago, si es true es pq ya se actualizo
                tbPayment paymentStatus = this.GetPayment(idPayment);

                //consulto si no se proceso, si ya fue procesado no hiteo nps y retorno el valor (ya procesado)
                if (paymentStatus.pst_id == (int)EnumPaymentStatus.PENDIENTE)
                {
                    //Si es falso, deberia analizar si hubo algun error de tarjeta y demas
                    //Ese desarrollo esta pendiente, lo de abajo se deberia ejecutar igual para acualizar o no
                    //Si se tuvo un error en el proceso de pago, consultar seria al pedo

                    ServicePaymentFormListenerBusiness paymentFormListenerBusiness =
                        new ServicePaymentFormListenerBusiness(model.psp_TransactionId, idPayment);

                    paymentResult = paymentFormListenerBusiness.ActualizarPayment();
                }
                else
                {
                    paymentResult = paymentStatus;
                }

                //now redirect
                var response = Request.CreateResponse(HttpStatusCode.Moved);
                response.Headers.Location =
                    new Uri(ConfigurationManager.AppSettings["RESPONSE_SERVER"] + paymentResult.pst_id.ToString());
                return(response);
            }
            catch (Exception ex)
            {
                log.Error("Error: " + ex.Message);
                if (ex.InnerException != null)
                {
                    log.Error("Inner exception: " + ex.InnerException.Message);
                }
                throw ex;
            }
        }
Exemple #21
0
        private tbPayment RequestSimpleQueryTx(NpsModel model)
        {
            try
            {
                tbPayment paymentResult = new tbPayment();
                //var proxy = new NpsService.PaymentServicePlatformPortTypeClient("PaymentServicePlatformPort");

                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

                PaymentServicePlatformPortTypeClient client =
                    new PaymentServicePlatformPortTypeClient("PaymentServicePlatformPort");

                RespuestaStruct_SimpleQueryTx     result = new RespuestaStruct_SimpleQueryTx();
                RequerimientoStruct_SimpleQueryTx query  = new RequerimientoStruct_SimpleQueryTx();
                query = GetRequestSimpleQueryTx(model);

                this.AuditRequestResponse(JsonConvert.SerializeObject(query));
                result = client.SimpleQueryTx(query);
                this.AuditRequestResponse(JsonConvert.SerializeObject(result));

                //Estoy actualizando por referencia los valores de los campos dentro del registro tbPaymentDetails
                _paymentDetail.pde_vendor_response_status = result.psp_ResponseCod;

                //Valido si el codigo de respuesta del simple query es OK = 2
                if (Int32.Parse(result.psp_ResponseCod).Equals(2))
                {
                    if (result.psp_Transaction != null)
                    {
                        int responseCode = Int32.Parse(result.psp_Transaction.psp_ResponseCod);
                        //y el codigo de la transaccion=0 "Compra online aprobada"
                        //result.psp_Transaction.psp_ResponseCod = 0 (Pago aceptado)
                        //result.psp_Transaction.psp_ResponseCod = 9 (Pago rechazado)
                        //result.psp_Transaction.psp_ResponseCod = 25 (Formulario en curso)
                        //result.psp_Transaction.psp_ResponseCod = 3 (fondos insuficientes)
                        //result.psp_Transaction.psp_ResponseCod = 9 (form vencido)
                        switch (responseCode)
                        {
                        case 0:
                        {
                            paymentResult.pst_id = (int)EnumPaymentStatus.PAGADO;
                            paymentResult.pay_informacion_adicional = result.psp_Transaction.psp_ResponseMsg;
                            break;
                        }

                        default:
                        {
                            paymentResult.pst_id = (int)EnumPaymentStatus.ERROR;
                            paymentResult.pay_informacion_adicional =
                                result.psp_Transaction.psp_ResponseMsg + " | " +
                                result.psp_Transaction.psp_ResponseExtended;
                            break;
                        }
                        }

                        //Estoy actualizando por referencia los valores de los campos dentro del registro tbPaymentDetails
                        _paymentDetail.pde_vendor_response_id = result.psp_Transaction.psp_TransactionId;
                    }
                }

                return(paymentResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }