コード例 #1
0
        public int AddTrialServiceSubscription(string ChargifyID, string CustomerId, int idLead)
        {
            var response = new BaseResponse();

            try
            {
                var serviceSubscriptionRepository = new ServiceSubscriptionRepository();
                var serviceSubscription           = new ServiceSubscription()
                {
                    SubscriptionName      = "TrialSuscription",
                    StartDate             = DateTime.Now,
                    EndDate               = DateTime.Now.AddMonths(1),
                    IsActive              = true,
                    idChargifyCustomer    = CustomerId,
                    idChargifySuscription = ChargifyID,
                    idLead = idLead
                };
                serviceSubscriptionRepository.Add(serviceSubscription);
                serviceSubscriptionRepository.SaveChanges();
                return(serviceSubscription.idServiceSubscription);
            }
            catch (Exception ex)
            {
                response.Acknowledgment = false;
                response.Message        = ex.Message;
            }
            return(0);
        }
コード例 #2
0
 public DateTime getTrialEnding(int userId)
 {
     try
     {
         var users                = new UserProfileRepository();
         var subcriptions         = new ServiceSubscriptionRepository();
         var customerId           = users.Query().FirstOrDefault(x => x.UserId == userId).ChargifyCustomerId ?? 0;
         var subscriptionId       = Convert.ToInt32(subcriptions.Query().FirstOrDefault(x => x.idChargifyCustomer == customerId.ToString()).idChargifySuscription);
         var chargifySubscription = GetSubscription(subscriptionId);
         if (chargifySubscription.State.ToString().ToLower() == "trialing" || chargifySubscription.State.ToString().ToLower() == "trial_ended")
         {
             return(chargifySubscription.TrialEndedAt);
         }
         return(DateTime.Now.AddMonths(-1));
     }
     catch (Exception ex)
     {
         return(DateTime.Now.AddMonths(-1));
     }
 }