Example #1
0
        static void CreatePayment()
        {
            Configuration.Secret     = File.ReadAllText("../../../../../SECRET").Trim();
            Configuration.ReceiverId = Int32.Parse(File.ReadAllText("../../../../../RECEIVER_ID").Trim());
            PaymentsApi a = new PaymentsApi();

            try
            {
                PaymentsCreateResponse r = a.PaymentsPost("Pago de Demo", "CLP", 100, notifyUrl: "https://micomercio.com/notify", transactionId: "TX-1234");

                System.Console.WriteLine("PAYMENT_ID: " + r.PaymentId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            System.Console.Read();
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] Transaccion t)
        {
            if (!ConexionOracle.Activa)
            {
                ConexionOracle.Open();
                if (!ConexionOracle.Activa)
                {
                    return(StatusCode(504, ConexionOracle.NoConResponse));
                }
            }
            try
            {
                Procedimiento p = new Procedimiento(ConexionOracle.Conexion, "SP_ID_PAGO");
                p.Parametros.Add("id_pago", OracleDbType.Int32, ParameterDirection.Output);
                await p.Ejecutar();

                int    idf  = Convert.ToInt32((decimal)(OracleDecimal)(p.Parametros["id_pago"].Value));
                String trId = "TTR" + idf.ToString();
                t.Id_pago = trId;
                t.Fecha   = DateTime.Now;
                if (t.Id_medio == 1)
                {
                    /* ZONA KHIPU */
                    Khipu.Client.Configuration.ReceiverId = Secret.T_RESEIVER_ID;
                    Khipu.Client.Configuration.Secret     = Secret.T_SECRET_KEY;
                    PaymentsApi            pago     = new PaymentsApi();
                    PaymentsCreateResponse response = pago.PaymentsPost(t.Comentario, "CLP", t.Monto, transactionId: trId,
                                                                        returnUrl: ServerURLs.PagarUrl(Accion.repay, t.Id_reserva, trId),
                                                                        cancelUrl: ServerURLs.PagarUrl(Accion.cancel, t.Id_reserva, trId, t.Monto));
                    /**/
                    t.Listo = '1';
                    var r = await cmd.Get <Reserva>(t.Id_reserva);

                    if (r == null)
                    {
                        return(BadRequest(MensajeError.Nuevo("Reserva no existe.")));
                    }
                    r.Valor_pagado += Convert.ToInt32(t.Monto);
                    r.N_pago        = r.N_pago + 1;
                    if (r.Valor_pagado == r.Valor_total)
                    {
                        r.Id_estado = 3;
                    }
                    else if (r.Valor_pagado == Math.Round((double)(r.Valor_total / 2), 0, MidpointRounding.AwayFromZero))
                    {
                        r.Id_estado = 2;
                    }
                    else
                    {
                        r.Id_estado = 1;
                    }
                    await cmd.Update(r);

                    var list = await cmd.Find <Reserva>("Username", t.Username);

                    List <Reserva> rl = new List <Reserva>();
                    foreach (var res in list)
                    {
                        if (res.Id_estado == 3 || res.Id_estado == 4)
                        {
                            rl.Add(res);
                        }
                    }
                    if (rl.Count > 9)
                    {
                        var u = await cmd.Get <Usuario>(t.Username);

                        u.Frecuente = '1';
                        await cmd.Update(u);
                    }
                    if (await cmd.Insert(t, false))
                    {
                        return(Ok(response));
                    }
                }
                else
                {/*
                  * var trs = new Webpay(Transbank.Webpay.Configuration.ForTestingWebpayPlusNormal()).NormalTransaction;
                  * var initResult = trs.initTransaction(t.Monto,trId,"sesion-"+trId, ServerURLs.PagarUrl(Acccion.pay, t.Id_reserva, trId, t.Monto), ServerURLs.PagarUrl(Acccion.commit, t.Id_reserva, trId, t.Monto));
                  * var token = initResult.token;
                  * t.Token = token;
                  * var url = initResult.url;
                  * if (await cmd.Insert(t, false))
                  * {
                  *     return Ok(new { Token = token, Url = url });
                  * }*/
                }
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(StatusCode(500, MensajeError.Nuevo(e.Message)));
            }
        }