Пример #1
0
        private void GenerarTarjetas(Solicitud currentSolicitud)
        {
            var allEmails      = currentSolicitud.ListEmails.Split(',').ToList();
            var tarjetaManager = new TarjetaManager();

            allEmails.ForEach(mail =>
            {
                if (!string.IsNullOrEmpty(mail))
                {
                    tarjetaManager.InitializeCard(new Tarjeta
                    {
                        Convenio = currentSolicitud.Convenio,
                        Terminal = currentSolicitud.Terminal,
                        Usuario  = new Usuario
                        {
                            Nombre = "Usuario del convenio: " + currentSolicitud.Convenio.NombreInstitucion,
                            Email  = mail
                        },
                        TipoTarjeta = new TipoTarjeta {
                            TipoTarjetaId = 1
                        }
                    });
                }
            });
        }
Пример #2
0
 public void AprobarReposicion(Tarjeta card)
 {
     try
     {
         var cardManager = new TarjetaManager();
         if (card.EstadoTarjeta.NombreEstado.Equals("Perdida", StringComparison.CurrentCultureIgnoreCase))
         {
             var oldCard = card.CodigoUnico;
             card.CodigoUnico   = Guid.NewGuid().ToString();
             card.NombreTarjeta = "Debido a perdida";
             card.Usuario.Email = card.Usuario.Identificacion;
             cardManager.Create(card);
             cardManager.Delete(new Tarjeta {
                 CodigoUnico = oldCard
             });
         }
         else
         {
             var transactionManager = new TransactionManager();
             var oldCard            = card.CodigoUnico;
             card.CodigoUnico   = Guid.NewGuid().ToString();
             card.NombreTarjeta = "Debido a robo";
             card.Usuario.Email = card.Usuario.Identificacion;
             var saldo = card.SaldoDisponible;
             cardManager.Create(card);
             cardManager.Delete(new Tarjeta {
                 CodigoUnico = oldCard
             });
             transactionManager.CreateUserTransaction(new Transaccion
             {
                 CardUniqueCode = card.CodigoUnico,
                 Charge         = Convert.ToInt32(saldo),
                 Description    = "Traspaso de fondos",
                 Terminal       = card.Terminal,
                 Type           = "Recarga",
                 Status         = "Activo",
                 Usuario        = card.Usuario
             });
         }
     }
     catch (Exception e)
     {
         ExceptionManager.GetInstance().Process(e);
         throw;
     }
 }
Пример #3
0
        public string NewPayment(Payment newPayment)
        {
            try
            {
                var transactionManager = new TransactionManager();
                var cardManager        = new TarjetaManager();

                var card = cardManager.GeTarjetaByUniquecode(newPayment.UserCardUnicode);

                if (card == null)
                {
                    throw new BusinessException(301);
                }

                var chargeOptions = new StripeChargeCreateOptions()
                {
                    Amount      = newPayment.AmoutCrc,
                    Currency    = "usd",
                    Description = $"{newPayment.Description} - {DateTime.Now.ToLongTimeString()}",
                    SourceTokenOrExistingSourceId = newPayment.CardToken // obtained with Stripe.js
                };
                var chargeService = new StripeChargeService();
                var charge        = chargeService.Create(chargeOptions);

                transactionManager.CreateUserTransaction(new Transaccion
                {
                    CardUniqueCode = newPayment.UserCardUnicode,
                    Charge         = newPayment.AmoutCrc,
                    Description    = newPayment.Description,
                    Terminal       = card.Terminal,
                    Type           = "Recarga",
                    Status         = "Activo"
                });
                return(charge.StripeResponse.ObjectJson);
            }
            catch (Exception e)
            {
                ExceptionManager.GetInstance().Process(e);
            }

            return(string.Empty);
        }
Пример #4
0
        public void CreateUserTransaction(Transaccion transaction, bool isFromBus = false)
        {
            try
            {
                var cardManager = new TarjetaManager();
                var card        = cardManager.GeTarjetaByUniquecode(transaction.CardUniqueCode);

                if (card == null)
                {
                    throw new BusinessException(301);
                }

                if (transaction.Type == null)
                {
                    throw new BusinessException(302);
                }

                var userManager = new UsuarioManager();

                var user = userManager.Retrieve(new Usuario {
                    Email = card.Usuario.Identificacion
                });

                if (transaction.Type.Equals("Recarga", StringComparison.CurrentCultureIgnoreCase))
                {
                    card.SaldoDisponible = card.SaldoDisponible + transaction.Charge;
                    cardManager.UpdateSaldoTarjeta(card);
                }
                else
                {
                    if (isFromBus)
                    {
                        transaction.Charge = card.Convenio != null && card.Convenio.CedulaJuridica != -1 ?
                                             transaction.Charge - (transaction.Charge * (card.Convenio.DescuentoTarifa / 100)):
                                             transaction.Charge - (transaction.Charge * (card.TipoTarjeta.DiscountPercentage / 100));
                    }

                    card.SaldoDisponible = card.SaldoDisponible - transaction.Charge;

                    if (card.SaldoDisponible < 0)
                    {
                        throw new BusinessException(304);
                    }

                    cardManager.UpdateSaldoTarjeta(card);

                    if (card.SaldoDisponible <= user.SmsNotificationsMin)
                    {
                        var smsNotification = new SendSms();
                        smsNotification.SendSmsMessage(new SmsMessage
                        {
                            DestinationNumber = user.Telefono.ToString(),
                            Message           = "Su cuenta tiene poco saldo disponible, por favor recargue."
                        });
                    }
                }

                var email = new SendEmail();

                email.SendEmailInvoice(new EmailMessage
                {
                    To      = user.Email,
                    Url     = transaction.Charge.ToString(),
                    Message = $"{transaction.Type} - {transaction.Description} "
                });

                _crudFactory.Create(transaction);
            }
            catch (Exception e)
            {
                ExceptionManager.GetInstance().Process(e);
            }
        }