예제 #1
0
 public string create(Suscriptor entity)
 {
     if (entity != null)
     {
         try {
             entities.Suscriptor.Add(entity);
             entities.SaveChanges();
             return(string.Format("API/Suscriptores/{0}", entity.suscriptorId));
         }
         catch (Exception)
         {
             return(string.Empty);
         }
     }
     return(string.Empty);
 }
예제 #2
0
        public void createSuscription(int userId, TipoSuscripcion suscripcion, string token, string stripePrivateKey)
        {
            StripeConfiguration.SetApiKey(stripePrivateKey);
            var suscriptor = entities.Suscriptor.Find(userId);

            if (string.IsNullOrEmpty(suscriptor.stripeCustomerId))
            {
                var customer = new StripeCustomerCreateOptions()
                {
                    Email       = suscriptor.correoElectronico,
                    SourceToken = token,
                    PlanId      = suscripcion.externalId
                };

                var stripeCustomer = _customerServices.Create(customer);


                suscriptor.stripeCustomerId = stripeCustomer.Id;
                suscriptor.TipoSuscripcionSuscriptor.Add(new TipoSuscripcionSuscriptor()
                {
                    suscriptorId      = suscriptor.suscriptorId,
                    tipoSuscripcionId = suscripcion.tipoSuscripcionId,
                    fechaExperacion   = (DateTime.Now.AddDays(30)),
                    fechaCompra       = DateTime.Now
                });

                entities.SaveChanges();
            }
            else
            {
                var subscriptionService = subscriptionServices.Create(suscriptor.stripeCustomerId, suscripcion.externalId);
                ///// update suscription
            }
        }