Beispiel #1
0
        //billing manage services

        public static PriceLineDTO Entity2PriceLineDto(this BILL_ItemsPriceList entity, CurrencyDTO currency)
        {
            var token = new PriceLineDTO
            {
                PriceLineID        = entity.PriceLineId
                , ItemId           = entity.ItemId
                , ItemType         = Utils.ParseEnum <BillingEnums.ePurchaseItemTypes>(entity.ItemTypeId)
                , PriceType        = Utils.ParseEnum <BillingEnums.ePricingTypes>(entity.PriceTypeId)
                , Price            = entity.Price.FormatPrice(currency.KeepDecimal ? 2 : 0)
                , Name             = entity.Name
                , NumOfPeriodUnits = entity.NumOfPeriodUnits
                , Currency         = currency.ToBaseCurrencyDto()
            };

            token.Title = token.PriceLineToken2Title();

            if (entity.PeriodTypeId != null)
            {
                token.PeriodType = Utils.ParseEnum <BillingEnums.eBillingPeriodType>(entity.PeriodTypeId.ToString());
            }

            token.Name = token.PriceLineToken2Name();

            return(token);
        }
Beispiel #2
0
        public static string PriceLineToken2Name(this PriceLineDTO token)
        {
            switch (token.PriceType)
            {
            case BillingEnums.ePricingTypes.ONE_TIME:
                return("One-time");

            case BillingEnums.ePricingTypes.SUBSCRIPTION:
                return(token.PeriodType != null?token.PeriodType.PeriodTypeTranslate() : "Monthly");

            case BillingEnums.ePricingTypes.RENTAL:
                return(token.Name);
            }

            return(string.Empty);
        }
Beispiel #3
0
        //public void UpdateRestTrxFee()
        //{

        //    try
        //    {
        //        var list =TransactionsViewRepository.GetMany(
        //                    x => x.Fee == 0 && x.Amount > 0
        //                        && x.TransactionDate.Year >= 2014
        //                    //x.TransactionTypeId == (byte) BillingEnums.eTransactionTypes.InitialSubscriptionPayment &&
        //                       && (x.PaymentMethodId == (byte)BillingEnums.ePaymentMethods.Credit_Card) || x.PaymentMethodId == (byte)BillingEnums.ePaymentMethods.Saved_Instrument).ToList();
        //        var cnt = 0;

        //        foreach (var row in list)
        //        {
        //            var trx = _paypalManageServies.GetRestPaymentDetails(row.ExternalTransactionID);

        //            //if(trx ==null || trx.Ack != AckCodeType.SUCCESS) continue;

        //            //var fee = trx.PaymentTransactionDetails.PaymentInfo.FeeAmount.value;

        //            //if(fee==null) continue;

        //            //var entity = TransactionRepository.GetById(row.TransactionId);

        //            //if(entity==null) continue;

        //            //entity.Fee = Convert.ToDecimal(fee);

        //            //entity.UpdateDate = DateTime.Now;

        //            //if(!TransactionRepository.UnitOfWork.CommitAndRefreshChanges()) continue;
        //            cnt++;
        //        }
        //    }
        //    catch (Exception)
        //    {

        //    }
        //}

        //public void ImportPrices()
        //{
        //    using (var context = new lfeAuthorEntities())
        //    {
        //        #region courses
        //        var courses = context.Courses.Where(x => !x.IsFreeCourse).ToList();

        //        foreach (var course in courses)
        //        {
        //            var courseId = course.Id;

        //            BILL_ItemsPriceList entity;

        //            if (course.PriceUSD != null)
        //            {
        //                if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId
        //                                                        && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE
        //                                                        && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.ONE_TIME
        //                                                        && x.CurrencyId == DEFAULT_CURRENCY_ID)
        //                                                    ) continue;


        //                entity = new BILL_ItemsPriceList
        //                {
        //                    ItemId       = courseId
        //                    ,ItemTypeId  = (byte)BillingEnums.ePurchaseItemTypes.COURSE
        //                    ,PriceTypeId = (byte)BillingEnums.ePricingTypes.ONE_TIME
        //                    ,Price       = (decimal) course.PriceUSD
        //                    ,CurrencyId  = DEFAULT_CURRENCY_ID
        //                    ,IsDeleted   = false
        //                    ,AddOn       = DateTime.Now
        //                };

        //                context.BILL_ItemsPriceList.Add(entity);

        //                context.SaveChanges();
        //            }

        //            if (course.MonthlySubscriptionPriceUSD == null) continue;


        //            if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId
        //                                                     && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE
        //                                                     && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.SUBSCRIPTION
        //                                                     && x.PeriodTypeId == (byte)BillingEnums.eBillingPeriodType.MONTH
        //                                                     && x.CurrencyId == DEFAULT_CURRENCY_ID)
        //                ) continue;


        //                entity = new BILL_ItemsPriceList
        //                {
        //                    ItemId        = courseId
        //                    ,ItemTypeId   = (byte)BillingEnums.ePurchaseItemTypes.COURSE
        //                    ,PriceTypeId  = (byte)BillingEnums.ePricingTypes.SUBSCRIPTION
        //                    ,PeriodTypeId = (byte)BillingEnums.eBillingPeriodType.MONTH
        //                    ,Price        = (decimal) course.MonthlySubscriptionPriceUSD
        //                    ,CurrencyId   = DEFAULT_CURRENCY_ID
        //                    ,IsDeleted    = false
        //                    ,AddOn        = DateTime.Now
        //                };

        //                context.BILL_ItemsPriceList.Add(entity);

        //                context.SaveChanges();
        //        }
        //        #endregion

        //        #region bundle
        //        var bundles = context.CRS_Bundles.ToList();

        //        foreach (var bundle in bundles)
        //        {
        //            var courseId = bundle.BundleId;

        //            BILL_ItemsPriceList entity;

        //            if (bundle.Price != null)
        //            {
        //                if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId
        //                                                        && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.BUNDLE
        //                                                        && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.ONE_TIME
        //                                                        && x.CurrencyId == DEFAULT_CURRENCY_ID)
        //                                                    ) continue;


        //                entity = new BILL_ItemsPriceList
        //                {
        //                    ItemId       = courseId
        //                    ,ItemTypeId  = (byte)BillingEnums.ePurchaseItemTypes.BUNDLE
        //                    ,PriceTypeId = (byte)BillingEnums.ePricingTypes.ONE_TIME
        //                    ,Price       = (decimal) bundle.Price
        //                    ,CurrencyId  = DEFAULT_CURRENCY_ID
        //                    ,IsDeleted   = false
        //                    ,AddOn       = DateTime.Now
        //                };

        //                context.BILL_ItemsPriceList.Add(entity);

        //                context.SaveChanges();
        //            }

        //            if (bundle.MonthlySubscriptionPrice == null) continue;


        //            if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId
        //                                                     && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.BUNDLE
        //                                                     && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.SUBSCRIPTION
        //                                                     && x.PeriodTypeId == (byte)BillingEnums.eBillingPeriodType.MONTH
        //                                                     && x.CurrencyId == DEFAULT_CURRENCY_ID)
        //                ) continue;


        //                entity = new BILL_ItemsPriceList
        //                {
        //                    ItemId        = courseId
        //                    ,ItemTypeId   = (byte)BillingEnums.ePurchaseItemTypes.BUNDLE
        //                    ,PriceTypeId  = (byte)BillingEnums.ePricingTypes.SUBSCRIPTION
        //                    ,PeriodTypeId = (byte)BillingEnums.eBillingPeriodType.MONTH
        //                    ,Price        = (decimal) bundle.MonthlySubscriptionPrice
        //                    ,CurrencyId   = DEFAULT_CURRENCY_ID
        //                    ,IsDeleted    = false
        //                    ,AddOn        = DateTime.Now
        //                };

        //                context.BILL_ItemsPriceList.Add(entity);

        //                context.SaveChanges();
        //        }
        //        #endregion
        //    }
        //}

        public void UpdateFreeCourses()
        {
            try
            {
                var lines = CourseRepository.GetMany(x => x.IsFreeCourse).ToList();

                foreach (var course in lines)
                {
                    var current  = course;
                    var isExists = PriceListRepository.IsAny(x => x.ItemId == current.Id &&
                                                             x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE &&
                                                             x.PriceTypeId == (byte)BillingEnums.ePricingTypes.FREE &&
                                                             !x.IsDeleted);

                    if (isExists)
                    {
                        continue;
                    }

                    var dto = new PriceLineDTO
                    {
                        ItemId = course.Id
                        ,
                        ItemType = BillingEnums.ePurchaseItemTypes.COURSE
                        ,
                        PriceType = BillingEnums.ePricingTypes.FREE
                        ,
                        Price = 0
                        ,
                        Currency = new BaseCurrencyDTO {
                            CurrencyId = DEFAULT_CURRENCY_ID
                        }
                    };

                    var entity = dto.Token2PriceLineEntity();

                    PriceListRepository.Add(entity);

                    PriceListRepository.UnitOfWork.CommitAndRefreshChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public static BILL_ItemsPriceList Token2PriceLineEntity(this PriceLineDTO token)
 {
     return(new BILL_ItemsPriceList
     {
         ItemId = token.ItemId
         , ItemTypeId = (byte)token.ItemType
         , PriceTypeId = (byte)token.PriceType
         , PeriodTypeId = token.PeriodType != null ? (byte)token.PeriodType : (byte?)null
         , Price = token.Price
         , CurrencyId = token.Currency.CurrencyId
         , NumOfPeriodUnits = token.NumOfPeriodUnits
         , Name = token.ToPriceLineName()
         , IsDeleted = false
         , AddOn = DateTime.Now
         , CreatedBy = DtoExtensions.CurrentUserId
     });
 }
Beispiel #5
0
        public static string PriceLineToken2PurchaseEmailPaymentMethod(this PriceLineDTO token)
        {
            switch (token.PriceType)
            {
            case BillingEnums.ePricingTypes.ONE_TIME:
                return("One-time payment");

            case BillingEnums.ePricingTypes.SUBSCRIPTION:
                return
                    ($"{(token.PeriodType != null ? token.PeriodType.PeriodTypeTranslate() : "Monthly")} subscription");

            case BillingEnums.ePricingTypes.RENTAL:
                return($"{token.Name} Rental");
            }

            return(string.Empty);
        }
Beispiel #6
0
        public static string PriceLineToken2PurchaseNameSuffix(this PriceLineDTO token)
        {
            switch (token.PriceType)
            {
            case BillingEnums.ePricingTypes.ONE_TIME:
                return("Unlimited Access");

            case BillingEnums.ePricingTypes.SUBSCRIPTION:
                return
                    ($"{(token.PeriodType != null ? token.PeriodType.PeriodTypeTranslate() : "Monthly")} subscription");

            case BillingEnums.ePricingTypes.RENTAL:
                return($"{token.Name} Rental");
            }

            return(string.Empty);
        }
Beispiel #7
0
        public static string PriceLineToken2Title(this PriceLineDTO token)
        {
            switch (token.PriceType)
            {
            case BillingEnums.ePricingTypes.ONE_TIME:
                return("One time payment");

            case BillingEnums.ePricingTypes.SUBSCRIPTION:
                return($"{token.PeriodType.PeriodTypeTranslate()} Subscription");

            case BillingEnums.ePricingTypes.RENTAL:
                return("Rental");

            case BillingEnums.ePricingTypes.FREE:
                return("Free");
            }

            return(string.Empty);
        }
Beispiel #8
0
 public static ItemPurchaseCompleteToken BundleInfoDto2ItemPurchaseCompleteToken(this BundleInfoDTO token, PriceLineDTO priceToken, BaseUserInfoDTO buyer, decimal totalPrice)
 {
     return(new ItemPurchaseCompleteToken
     {
         ItemId = token.BundleId
         , ItemName = token.BundleName
         , ItemType = BillingEnums.ePurchaseItemTypes.BUNDLE
         , ThumbUrl = token.ThumbUrl
         , FinalPrice = totalPrice
         , PriceToken = priceToken
         , BuyerInfo = buyer
         , Author = new BaseUserInfoDTO
         {
             UserId = token.Author.UserId
             , FullName = token.Author.FullName
         }
     });
 }
Beispiel #9
0
 public static ItemPurchaseDataToken BundleInfoDTO2ItemPurchaseDataToken(this BundleInfoDTO token, PriceLineDTO priceToken)
 {
     return(new ItemPurchaseDataToken
     {
         ItemId = token.BundleId
         , ItemName = token.BundleName
         , Type = BillingEnums.ePurchaseItemTypes.BUNDLE
         , PriceToken = priceToken
         , Author = new UserBaseDTO
         {
             userId = token.Author.UserId
             , fullName = token.Author.FullName
         }
     });
 }
Beispiel #10
0
 public static string ToPriceLineName(this PriceLineDTO token)
 {
     return(token.PriceType == BillingEnums.ePricingTypes.FREE ? "Free" : (token.PriceType == BillingEnums.ePricingTypes.RENTAL ? String.Format("{0} {1}", token.NumOfPeriodUnits, Utils.GetEnumDescription(token.PeriodType)) : null));
 }
Beispiel #11
0
 public static PayPalAgreementDTO CoursePurchaseDataToken2PayPalAgreementDto(this ItemPurchaseDataToken token, string buyerName, string buyerEmail, string SUCCESS_PAYMENT_URL, string CANCEL_PAYMENT_URL, int?addressId, Guid?instrumentId, BillingEnums.ePaymentMethods paymentMethod, PriceLineDTO priceToken)
 {
     return(new PayPalAgreementDTO
     {
         cancel_url = CANCEL_PAYMENT_URL
         , success_url = SUCCESS_PAYMENT_URL
         , currency = token.PriceToken.Currency.ISO                       //"USD"
         , priceLineId = token.PriceToken.PriceLineID
         , amount = token.Price
         , Type = token.Type
         , courseId = token.Type == BillingEnums.ePurchaseItemTypes.COURSE ? token.ItemId : (int?)null
         , bundleId = token.Type == BillingEnums.ePurchaseItemTypes.BUNDLE ? token.ItemId : (int?)null
         , couponCode = token.CouponCode
         , trackingId = token.TrackingID
         , addressId = addressId
         , paymentInstrumentId = instrumentId
         , description = token.ItemName.ItemName2SubscriptionDescription()
         , method = paymentMethod
         , buyerEmail = buyerEmail
         , buyerName = buyerName
         , Currency = priceToken.Currency
     });
 }