public static string GetProductName(IPTV2Entities context, Product product) { if (product is SubscriptionProduct) { SubscriptionProduct sproduct = (SubscriptionProduct)product; if (sproduct is ShowSubscriptionProduct) return ((ShowSubscriptionProduct)sproduct).Categories.First().Show.Description; else if (sproduct is EpisodeSubscriptionProduct) return ((EpisodeSubscriptionProduct)sproduct).Episodes.First().Episode.Description; else if (sproduct is PackageSubscriptionProduct) return ((PackageSubscriptionProduct)sproduct).Packages.First().Package.Description; } return String.Empty; }
public static SubscriptionProductType GetProductType(Product product) { SubscriptionProductType type = SubscriptionProductType.Package; if (product is SubscriptionProduct) { SubscriptionProduct sproduct = (SubscriptionProduct)product; if (sproduct is ShowSubscriptionProduct) type = SubscriptionProductType.Show; else if (sproduct is EpisodeSubscriptionProduct) type = SubscriptionProductType.Episode; else if (sproduct is PackageSubscriptionProduct) type = SubscriptionProductType.Package; } return type; }
public static void AddToPaypalRecurringBilling(IPTV2Entities context, Product product, Offering offering, User user, DateTime registDt, string subscr_id, bool IsRecurringSignUp = false, int TrialProductId = 0) { try { //Check if product is subscription product if (product is SubscriptionProduct) { //check if there are any recurring products that have the same productgroup SubscriptionProduct subscriptionProduct = (SubscriptionProduct)product; //Get user's recurring productGroups var recurringProductGroups = user.GetRecurringProductGroups(offering); if (!recurringProductGroups.Contains(subscriptionProduct.ProductGroup)) { var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId); if (productPackage != null) { var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId); if (entitlement != null) { var paypalRecurringBilling = user.RecurringBillings.FirstOrDefault(r => r is PaypalRecurringBilling && r.StatusId == GlobalConfig.Visible && String.Compare(((PaypalRecurringBilling)r).SubscriberId, subscr_id, true) == 0); if (paypalRecurringBilling == null) { var billing = new PaypalRecurringBilling() { CreatedOn = registDt, Product = product, User = user, UpdatedOn = registDt, EndDate = entitlement.EndDate, //NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry NextRun = entitlement.EndDate.Date, StatusId = GlobalConfig.Visible, Offering = offering, Package = (Package)productPackage.Package, SubscriberId = subscr_id, NumberOfAttempts = 0 }; context.RecurringBillings.Add(billing); } else { if (paypalRecurringBilling.Product != null) { var recurringProduct = paypalRecurringBilling.Product; if (recurringProduct is SubscriptionProduct) { var recurringSubscriptionProduct = (SubscriptionProduct)recurringProduct; paypalRecurringBilling.NextRun = MyUtility.getEntitlementEndDate(recurringSubscriptionProduct.Duration, recurringSubscriptionProduct.DurationType, paypalRecurringBilling.NextRun != null ? (DateTime)paypalRecurringBilling.NextRun : registDt.Date); paypalRecurringBilling.UpdatedOn = DateTime.Now; } } } context.SaveChanges(); } else { if (IsRecurringSignUp) { // get trial product var trialProduct = context.Products.FirstOrDefault(p => p.ProductId == TrialProductId); SubscriptionProduct trialSubscriptionProduct = (SubscriptionProduct)trialProduct; var billing = new PaypalRecurringBilling() { CreatedOn = registDt, Product = product, User = user, UpdatedOn = registDt, //NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry EndDate = MyUtility.getEntitlementEndDate(trialSubscriptionProduct.Duration, trialSubscriptionProduct.DurationType, registDt), NextRun = MyUtility.getEntitlementEndDate(trialSubscriptionProduct.Duration, trialSubscriptionProduct.DurationType, registDt), StatusId = GlobalConfig.Visible, Offering = offering, Package = (Package)productPackage.Package, SubscriberId = subscr_id, NumberOfAttempts = 0 }; context.RecurringBillings.Add(billing); context.SaveChanges(); } } } } } } catch (Exception e) { MyUtility.LogException(e); } }
public static CheckSubscriptionReturnObject HasActiveSubscriptionBasedOnProducts(IPTV2Entities context, User user, Offering offering, Product product) { var returnObject = new CheckSubscriptionReturnObject() { HasSubscription = false, Within5DaysOrLess = false }; try { var subProducts = user.GetSubscribedProducts(offering); if (product != null) { if (product is SubscriptionProduct) { if (product is PackageSubscriptionProduct) { var packageProduct = (PackageSubscriptionProduct)product; returnObject.SubscriptionEndDate = user.PackageEntitlements.FirstOrDefault(u => u.PackageId == packageProduct.Packages.First().PackageId).EndDate; } else if (product is ShowSubscriptionProduct) { var showProduct = (ShowSubscriptionProduct)product; returnObject.SubscriptionEndDate = user.ShowEntitlements.FirstOrDefault(u => u.CategoryId == showProduct.Categories.First().CategoryId).EndDate; } returnObject.HasSubscription = subProducts.Select(s => s.ProductId).Contains(product.ProductId); } } } catch (Exception e) { MyUtility.LogException(e); } return returnObject; }
private EntitlementRequest CreateEntitlementRequest(DateTime registDt, DateTime endDate, Product product, string source, string reference, DateTime startDate) { EntitlementRequest request = new EntitlementRequest() { DateRequested = registDt, EndDate = endDate, StartDate = startDate, Product = product, Source = source, ReferenceId = reference }; return request; }
private static void SendConfirmationEmails(User user, User recipient, Transaction transaction, string ProductNameBought, Product product, DateTime endDt, DateTime registDt, string mode, DateTime? autoRenewReminderDate = null, string GomsError = null) { if (isSendEmailEnabled) { string emailBody = String.Empty; string mailSubject = String.Empty; string toEmail = String.Empty; emailBody = String.Format(ExtendSubscriptionBodyWithAutoRenewTextOnly, user.FirstName, ProductNameBought, endDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.TransactionId, product.Name, registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, mode, transaction.Reference, ((DateTime)autoRenewReminderDate).ToString("MMMM dd, yyyy")); mailSubject = String.Format("Your {0} has been extended", ProductNameBought); toEmail = user.EMail; if (!String.IsNullOrEmpty(GomsError)) { emailBody = String.Format(AutoRenewFailureBodyTextOnly, user.FirstName, ProductNameBought, GomsError); mailSubject = "Unable to Auto-Renew your TFC.tv Subscription"; } try { if (!String.IsNullOrEmpty(toEmail)) SendEmailViaSendGrid(toEmail, NoReplyEmail, mailSubject, emailBody, MailType.TextOnly, emailBody); } catch (Exception e) { throw new Exception(String.Format("SendGrid: {0}", e.Message)); } } }
static public ErrorCode ValidateSubscriptionPpc(IPTV2Entities context, string serialNumber, string pin, string currencyCode, Product subscriptionProduct) { var ppc = context.Ppcs.FirstOrDefault(p => p.SerialNumber == serialNumber); if (ppc == null) return ErrorCode.InvalidSerialNumber; var returnCode = ErrorCode.UnknownError; if (!(ppc is SubscriptionPpc)) return ErrorCode.NotASubscriptionPpc; if (ppc.ExpirationDate < DateTime.Now) return ErrorCode.IsExpiredPpc; returnCode = ppc.Validate(pin, currencyCode); if (returnCode == ErrorCode.Success) { var sPpc = (SubscriptionPpc)ppc; if (sPpc.ProductId != subscriptionProduct.ProductId) return ErrorCode.PpcDoesNotMatchSubscriptionProduct; if (ppc.Currency != "---") // Not a trial card, check for the product price { ProductPrice price = subscriptionProduct.ProductPrices.FirstOrDefault(pp => pp.CurrencyCode == currencyCode); if (price == null) return ErrorCode.PpcHasNoMatchingProductPrice; if (price.Amount != sPpc.GetAmount(currencyCode)) return ErrorCode.PpcPriceDoesNotMatchProductPrice; } } return returnCode; }
private RecurringBillingReturnValue CheckIfUserIsEnrolledToSameRecurringProductGroup(IPTV2Entities context, Offering offering, User user, Product product) { RecurringBillingReturnValue returnValue = new RecurringBillingReturnValue() { container = null, value = false }; var profiler = MiniProfiler.Current; using (profiler.Step("Check Recurring Enrolment")) { try { if (product is SubscriptionProduct) { // check if user is part of recurring var subscriptionProduct = (SubscriptionProduct)product; //Get user's recurring productGroups var recurringProductGroups = user.GetRecurringProductGroups(offering); if (recurringProductGroups.Contains(subscriptionProduct.ProductGroup)) { var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId); if (productPackage != null) { var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId); if (entitlement != null) { var container = new RecurringBillingContainer() { user = user, product = product, entitlement = entitlement, package = (Package)productPackage.Package }; returnValue.value = true; returnValue.container = container; } } } } } catch (Exception e) { MyUtility.LogException(e); } } return returnValue; }
private bool IsProductGiftable(IPTV2Entities context, Product product, System.Guid userId) { Offering offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId); User user = context.Users.FirstOrDefault(u => u.UserId == userId); PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; if (user != null) { var subscribedProducts = user.GetSubscribedProductGroups(offering); if (subscribedProducts.Count == 0) return true; foreach (var item in subscribedProducts) { //checks if product to be bought and subscribed product belong to the same group if (item.ProductGroupId != subscription.ProductGroupId) //does not belong to same group { if (item.UpgradeableFromProductGroups().Contains(subscription.ProductGroup)) return false; else { // added this line if (item.UpgradeableToProductGroups().Contains(subscription.ProductGroup)) return false; else return true; } } else return true; } } return false; }
/// <summary> /// Product to be bought is TFC.tv Lite /// PackageId 48 /// </summary> /// <param name="context"></param> /// <param name="product"></param> /// <returns></returns> private bool isAllowedToBuyPremium(IPTV2Entities context, Product product, System.Guid userId) { if (product is PackageSubscriptionProduct) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; foreach (var item in subscription.Packages) { if (item.PackageId == GlobalConfig.PremiumPackageId) // If Product contains a Lite package, check for Premium { DateTime registDt = DateTime.Now; User user = context.Users.FirstOrDefault(u => u.UserId == userId); var LiteEntitlement = user.PackageEntitlements.FirstOrDefault(pe => pe.PackageId == GlobalConfig.LitePackageId && pe.EndDate > registDt); return LiteEntitlement != null ? false : true; } return true; } } return true; }
public static string GetCurrentSubscribeProduct(IPTV2Entities context, Product product, System.Guid userId, Offering offering) { if (product is SubscriptionProduct) { SubscriptionProduct sproduct = (SubscriptionProduct)product; User user = context.Users.FirstOrDefault(u => u.UserId == userId); var subscribedproducts = user.GetSubscribedProductGroups(offering); foreach (var item in subscribedproducts) { return item.Name; //if (item.ProductGroup.UpgradeableFromProductGroups().Contains(sproduct.ProductGroup)) //{ // //Product CurrentProduct = context.Products.FirstOrDefault(p => p.ProductId == item.ProductId); // //return CurrentProduct.Name; // return item.Name; //} } } return String.Empty; }
public static bool IsProductViewableInUserCountry(Product product) { if (IsProductBlockedInCountry(product)) return false; else return IsProductAllowedInCountry(product); }
public static bool IsProductBlockedInCountry(Product product) { var countryCodes = product.BlockedCountries.Where(o => o.StatusId == GlobalConfig.Visible).Select(o => o.CountryCode); if (countryCodes.Count() > 0) { if (countryCodes.Contains("--")) return true; else return countryCodes.Contains(MyUtility.GetCurrentCountryCodeOrDefault()); } return false; }
public static bool IsProductPurchaseable(IPTV2Entities context, Product product, User user, Offering offering) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; var subscribedProducts = user.GetSubscribedProductGroups(offering); foreach (var item in subscribedProducts) { //checks if product to be bought and subscribed product belong to the same group if (item.ProductGroupId != subscription.ProductGroupId) //does not belong to same group { if (item.UpgradeableFromProductGroups().Contains(subscription.ProductGroup)) return false; } } return true; }
public ActionResult SummaryOfOrder(int id, User user, Product product, ProductPrice productPrice) { try { var registDt = DateTime.Now; var ExpirationDate = registDt; //Get entitlement end date for user SubscriptionProductType subscriptionType = ContextHelper.GetProductType(product); switch (subscriptionType) { case SubscriptionProductType.Package: PackageSubscriptionProduct PackageSubscription = (PackageSubscriptionProduct)product; var package = PackageSubscription.Packages.FirstOrDefault(); if (package != null) { ViewBag.ListOfDescription = ContextHelper.GetPackageFeatures(user.CountryCode, package); PackageEntitlement UserPackageEntitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId); if (UserPackageEntitlement != null) ExpirationDate = MyUtility.getEntitlementEndDate(PackageSubscription.Duration, PackageSubscription.DurationType, ((UserPackageEntitlement.EndDate > registDt) ? UserPackageEntitlement.EndDate : registDt)); else ExpirationDate = MyUtility.getEntitlementEndDate(PackageSubscription.Duration, PackageSubscription.DurationType, registDt); } break; case SubscriptionProductType.Show: ShowSubscriptionProduct ShowSubscription = (ShowSubscriptionProduct)product; var show = ShowSubscription.Categories.FirstOrDefault(); if (show != null) { ViewBag.ShowDescription = show.Show.Blurb; ShowEntitlement UserShowEntitlement = user.ShowEntitlements.FirstOrDefault(s => s.CategoryId == show.CategoryId); if (UserShowEntitlement != null) ExpirationDate = MyUtility.getEntitlementEndDate(ShowSubscription.Duration, ShowSubscription.DurationType, ((UserShowEntitlement.EndDate > registDt) ? UserShowEntitlement.EndDate : registDt)); else ExpirationDate = MyUtility.getEntitlementEndDate(ShowSubscription.Duration, ShowSubscription.DurationType, registDt); } break; case SubscriptionProductType.Episode: EpisodeSubscriptionProduct EpisodeSubscription = (EpisodeSubscriptionProduct)product; var episode = EpisodeSubscription.Episodes.FirstOrDefault(); if (episode != null) { EpisodeEntitlement UserEpisodeEntitlement = user.EpisodeEntitlements.FirstOrDefault(e => e.EpisodeId == episode.EpisodeId); if (UserEpisodeEntitlement != null) ExpirationDate = MyUtility.getEntitlementEndDate(EpisodeSubscription.Duration, EpisodeSubscription.DurationType, ((UserEpisodeEntitlement.EndDate > registDt) ? UserEpisodeEntitlement.EndDate : registDt)); else ExpirationDate = MyUtility.getEntitlementEndDate(EpisodeSubscription.Duration, EpisodeSubscription.DurationType, registDt); } break; } ViewBag.ExpirationDate = ExpirationDate; ViewBag.ProductPrice = productPrice; return PartialView(product); } catch (Exception e) { MyUtility.LogException(e); } return null; }
private bool isLiteAllowedInCountry(IPTV2Entities context, Product product, System.Guid userId) { if (product is PackageSubscriptionProduct) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; foreach (var item in subscription.Packages) { if (item.PackageId == GlobalConfig.LitePackageId) { //Check users country User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user != null) if (user.Country != null) if (user.Country.Code == GlobalConfig.DefaultCountry) return false; } } } return true; }
private void SendGiftShareToSocialNetwork(Product product, User recipient) { //Publish user action List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.sgift_actionlink_href) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.sgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.sgift_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.sgift_mediaitem_href, User.Identity.Name)) }); UserAction action = new UserAction() { actorUID = User.Identity.Name, userMessage = String.Format(SNSTemplates.sgift_usermessage_external, product.Description, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)), title = SNSTemplates.sgift_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.sgift_subtitle), linkBack = String.Format(SNSTemplates.sgift_linkback, User.Identity.Name), description = SNSTemplates.sgift_description, actionLinks = actionlinks, mediaItems = mediaItems }; var userId = new Guid(User.Identity.Name); var userData = MyUtility.GetUserPrivacySetting(userId); if (userData.IsExternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "external"); //Modify action to suit Internal feed needs mediaItems.Clear(); mediaItems.Add(new MediaItem() { type = SNSTemplates.sgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.AssetsBaseUrl, SNSTemplates.sgift_mediaitem_src_internal), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.sgift_mediaitem_href, User.Identity.Name)) }); action.userMessage = String.Format(SNSTemplates.sgift_usermessage, product.Description, recipient.UserId, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)); action.description = String.Format(SNSTemplates.sgift_description_internal, product.Description, recipient.UserId, String.Format("{0} {1}", recipient.FirstName, recipient.LastName)); action.mediaItems = mediaItems; if (userData.IsInternalSharingEnabled.Contains("true")) GigyaMethods.PublishUserAction(action, new System.Guid(User.Identity.Name), "internal"); }
//public static ErrorCodes PayViaCreditCard(IPTV2Entities context, System.Guid userId, CreditCardInfo info, int productId, SubscriptionProductType subscriptionType, System.Guid recipientUserId) //{ // try // { // DateTime registDt = DateTime.Now; // User user = context.Users.FirstOrDefault(u => u.UserId == userId); // User recipient = context.Users.FirstOrDefault(u => u.UserId == recipientUserId); // UserWallet wallet = user.UserWallets.FirstOrDefault(w => w.Currency == MyUtility.GetCurrencyOrDefault(user.CountryCode)); // Offering offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId); // Product product = context.Products.FirstOrDefault(p => p.ProductId == productId); // ProductPrice priceOfProduct = product.ProductPrices.FirstOrDefault(p => p.CurrencyCode == MyUtility.GetCurrencyOrDefault(user.CountryCode)); // if (info == null) { } // if (String.IsNullOrEmpty(info.Number)) { } // if (String.IsNullOrEmpty(info.CardSecurityCode)) { } // if (String.IsNullOrEmpty(info.Name)) { } // if (String.IsNullOrEmpty(info.StreetAddress)) { } // if (String.IsNullOrEmpty(info.PostalCode)) { } // Purchase purchase = new Purchase() // { // Date = registDt, // Remarks = "Payment via Credit Card" // }; // user.Purchases.Add(purchase); // PurchaseItem item = new PurchaseItem() // { // RecipientUserId = userId, // ProductId = product.ProductId, // Price = priceOfProduct.Amount, // Currency = priceOfProduct.CurrencyCode, // Remarks = product.Name // }; // purchase.PurchaseItems.Add(item); // CreditCardPaymentTransaction transaction = new CreditCardPaymentTransaction() // { // Amount = priceOfProduct.Amount, // Currency = priceOfProduct.CurrencyCode, // Reference = info.CardType.ToString().Replace("_", " ").ToUpper(), // Date = registDt, // Purchase = purchase // }; // var gomsService = new GomsTfcTv(); // var response = gomsService.CreateOrderViaCreditCard(context, userId, transaction, info); // if (response.IsSuccess) // { // transaction.Reference += "-" + response.TransactionId.ToString(); // user.Transactions.Add(transaction); // item.SubscriptionProduct = (SubscriptionProduct)product; // switch (subscriptionType) // { // case SubscriptionProductType.Show: // break; // case SubscriptionProductType.Package: // if (product is PackageSubscriptionProduct) // { // // DateAndTime.DateAdd(DateInterval.Minute, 1, registDt); // //registDt = registDt.AddMinutes(1); // PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; // //EntitlementRequest request = new EntitlementRequest() // //{ // // DateRequested = registDt, // // EndDate = MyUtility.getEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt), // // Product = product, // // Source = String.Format("{0}-{1}", "Ppc", ppc.PpcId.ToString()), // // ReferenceId = purchase.PurchaseId.ToString() // //}; // //user.EntitlementRequests.Add(request); // foreach (var package in subscription.Packages) // { // PackageEntitlement currentPackage = recipient.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId); // DateTime endDate = registDt; // if (currentPackage != null) // { // currentPackage.EndDate = MyUtility.getEntitlementEndDate(subscription.Duration, subscription.DurationType, ((currentPackage.EndDate > registDt) ? currentPackage.EndDate : registDt)); // endDate = currentPackage.EndDate; // } // else // { // PackageEntitlement entitlement = new PackageEntitlement() // { // EndDate = MyUtility.getEntitlementEndDate(subscription.Duration, subscription.DurationType, registDt), // Package = (Package)package.Package, // OfferingId = GlobalConfig.offeringId // }; // recipient.PackageEntitlements.Add(entitlement); // } // EntitlementRequest request = new EntitlementRequest() // { // DateRequested = registDt, // EndDate = endDate, // Product = product, // Source = String.Format("{0}-{1}", "CC", info.CardTypeString.Replace('_', ' ')), // ReferenceId = System.Guid.NewGuid().ToString() // }; // recipient.EntitlementRequests.Add(request); // } // } // break; // case SubscriptionProductType.Episode: break; // } // if (context.SaveChanges() > 0) // { // return ErrorCodes.Success; // } // return ErrorCodes.EntityUpdateError; // } // ErrorCodes code = ErrorCodes.UnknownError; // switch (response.StatusCode) // { // case "7": code = ErrorCodes.CreditCardHasExpired; break; // default: code = ErrorCodes.EntityUpdateError; break; // } // return code; // } // catch (Exception) // { // //Debug.WriteLine(e.InnerException); // throw; // } //} private static bool IsAllowedUpgrade(IPTV2Entities context, System.Guid userId, Product product, System.Guid recipientUserId) { if (userId == recipientUserId) { if (product is PackageSubscriptionProduct) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; foreach (var item in subscription.Packages) { if (item.PackageId == GlobalConfig.PremiumPackageId) // If Product contains a Lite package, check for Premium { DateTime registDt = DateTime.Now; User user = context.Users.FirstOrDefault(u => u.UserId == new Guid(HttpContext.Current.User.Identity.Name)); var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId); var LiteEntitlement = user.PackageEntitlements.FirstOrDefault(pe => pe.PackageId == GlobalConfig.LitePackageId && pe.EndDate > registDt); return LiteEntitlement != null ? true : false; } return false; } } return false; } return false; }
private bool IsProductRestricted(IPTV2Entities context, Product product, System.Guid userId) { if (product is PackageSubscriptionProduct) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; User user = context.Users.FirstOrDefault(u => u.UserId == userId); if (user != null) { if (user.Country != null) { if (product.IsAllowed(user.Country)) { return true; } } } } return false; }
private static bool Upgrade(IPTV2Entities context, System.Guid userId, Product product, System.Guid recipientUserId, int? cpId) { if (userId == recipientUserId) { if (product is PackageSubscriptionProduct) { PackageSubscriptionProduct subscription = (PackageSubscriptionProduct)product; DateTime registDt = DateTime.Now; User user = context.Users.FirstOrDefault(u => u.UserId == new Guid(HttpContext.Current.User.Identity.Name)); string CurrencyCode = MyUtility.GetCurrencyOrDefault(user.Country != null ? user.Country.Code : GlobalConfig.DefaultCountry); var offering = context.Offerings.FirstOrDefault(o => o.OfferingId == GlobalConfig.offeringId); var currentSubscription = user.GetSubscribedProducts(offering).FirstOrDefault(s => s.ProductId == cpId); if (currentSubscription == null) return false; //Check if its upgrade to the product being bought if (currentSubscription.ProductGroup.UpgradeableToProductGroups().Contains(subscription.ProductGroup)) { //if true, deactivate the package based on product //Get all product Id inside the current subscription var list = currentSubscription.ProductGroup.SubscriptionProducts.Select(e => e.ProductId); //Get the Packagea var productPackage = context.ProductPackages.FirstOrDefault(p => list.Contains(p.ProductId)); //Get Package Entitlement based on the Package Id var packageEntitlement = user.PackageEntitlements.Where(e => e.PackageId == productPackage.PackageId); foreach (var entitlement in packageEntitlement) { //Compute for remaining days. var remainingDaysToBeAdded = GetEquivalentPremiumDuration(context, CurrencyCode, entitlement); //Deactivate the package DateTime originalExpirationDate = entitlement.EndDate; entitlement.EndDate = registDt; //DateTime newExpirationDate = MyUtility.getEntitlementEndDate((int)remainingDaysToBeAdded, "d", registDt); DateTime newExpirationDate = MyUtility.getEntitlementEndDate((int)remainingDaysToBeAdded, "d", GetPackageEndDateIfAvailable(user, subscription, registDt)); //Create an UpgradeTransaction UpgradeTransaction transaction = CreateUpgradeTransaction(originalExpirationDate, currentSubscription.ProductId, newExpirationDate, product.ProductId, CurrencyCode, registDt); user.Transactions.Add(transaction); //Add the new package foreach (var package in subscription.Packages) { PackageEntitlement currentPackage = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == package.PackageId); EntitlementRequest request = new EntitlementRequest() { DateRequested = registDt, EndDate = newExpirationDate, Product = product, Source = "SUBSCRIPTION UPGRADE", ReferenceId = "SUBSCRIPTION UPGRADE" }; if (currentPackage != null) { currentPackage.LatestEntitlementRequest = request; currentPackage.EndDate = newExpirationDate; request.EndDate = newExpirationDate; } else { PackageEntitlement pkgEntitlement = new PackageEntitlement() { EndDate = newExpirationDate, Package = (Package)package.Package, OfferingId = GlobalConfig.offeringId, LatestEntitlementRequest = request }; request.EndDate = pkgEntitlement.EndDate; user.PackageEntitlements.Add(pkgEntitlement); } user.EntitlementRequests.Add(request); } } } if (context.SaveChanges() > 0) return true; } return false; } return false; }
private void ProcessWishlist(string wid, Product product, User recipient, User user) { if (!String.IsNullOrEmpty(wid)) { GigyaMethods.DeleteWishlist(wid); // Delete from Wishlist SendGiftShareToSocialNetwork(product, recipient); ReceiveGiftShareToSocialNetwork(product, recipient, user); } }
private static void SendConfirmationEmails(User user, User recipient, Transaction transaction, string ProductNameBought, Product product, DateTime endDt, DateTime registDt, string mode, bool isGift, bool isExtension, bool isAutoRenew = false, DateTime? autoRenewReminderDate = null) { if (!HttpContext.Current.Request.IsLocal) { //Send email string emailBody = String.Empty; string mailSubject = String.Empty; string toEmail = String.Empty; string type = "Subscription"; if (isGift) { emailBody = String.Format(GlobalConfig.GiftingSenderBodyTextOnly, transaction.TransactionId, product.Name, registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, mode, transaction.Reference); mailSubject = String.Format("{0} {1} has received your TFC.tv gift", recipient.FirstName, recipient.LastName); toEmail = user.EMail; //Send to recipient try { string recipientEmailBody = String.Format(GlobalConfig.GiftingRecipientBodyTextOnly, recipient.FirstName, user.FirstName, user.LastName, ProductNameBought, endDt.ToString("MM/dd/yyyy hh:mm:ss tt"), GlobalConfig.baseUrl, user.UserId); string recipientMailSubject = String.Format("{0} {1} has sent you a TFC.tv gift", user.FirstName, user.LastName); string recipientToEmail = recipient.EMail; if (!String.IsNullOrEmpty(recipientToEmail)) MyUtility.SendEmailViaSendGrid(recipientToEmail, GlobalConfig.NoReplyEmail, recipientMailSubject, recipientEmailBody, MailType.TextOnly, recipientEmailBody); } catch (Exception) { } } else { mailSubject = String.Format("You are now subscribed to {0}", ProductNameBought); if (isAutoRenew) { type = "Subscription - On Automatic Renewal*"; } if (isExtension) { type = "Subscription Extension"; if (isAutoRenew) type = "Subscription Extension- On Automatic Renewal*"; mailSubject = String.Format("Your {0} has been extended", ProductNameBought); } toEmail = user.EMail; } try { if (!String.IsNullOrEmpty(toEmail)) { MyUtility.SendReceiptEmail(ProductNameBought, user, endDt.ToString("MM/dd/yyyy"), mailSubject, transaction.TransactionId.ToString(), registDt.ToString("MM/dd/yyyy hh:mm:ss tt"), transaction.Amount.ToString("F2"), transaction.Currency, type, mode, transaction.Reference,isExtension); } } catch (Exception) { } } }
private void ReceiveGiftShareToSocialNetwork(Product product, User recipient, User user) { //Publish user action List<ActionLink> actionlinks = new List<ActionLink>(); actionlinks.Add(new ActionLink() { text = SNSTemplates.actionlink_text, href = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_actionlink_href) }); List<MediaItem> mediaItems = new List<MediaItem>(); mediaItems.Add(new MediaItem() { type = SNSTemplates.rgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_mediaitem_src), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_mediaitem_href, recipient.UserId.ToString())) }); UserAction action = new UserAction() { actorUID = recipient.UserId.ToString(), userMessage = String.Format(SNSTemplates.rgift_usermessage_external, product.Description, String.Format("{0} {1}", user.FirstName, user.LastName)), title = SNSTemplates.rgift_title, subtitle = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_subtitle), linkBack = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_linkback, recipient.UserId.ToString())), description = SNSTemplates.rgift_description, actionLinks = actionlinks, mediaItems = mediaItems }; GigyaMethods.PublishUserAction(action, recipient.UserId, "external"); //Modify action to suit Internal feed needs mediaItems.Clear(); mediaItems.Add(new MediaItem() { type = SNSTemplates.rgift_mediaitem_type, src = String.Format("{0}{1}", GlobalConfig.baseUrl, SNSTemplates.rgift_mediaitem_src_internal), href = String.Format("{0}{1}", GlobalConfig.baseUrl, String.Format(SNSTemplates.rgift_mediaitem_href, recipient.UserId.ToString())) }); action.userMessage = String.Format(SNSTemplates.rgift_usermessage, product.Description, user.UserId, String.Format("{0} {1}", user.FirstName, user.LastName)); action.description = String.Format(SNSTemplates.rgift_description_internal, product.Description, user.UserId, String.Format("{0} {1}", user.FirstName, user.LastName)); action.mediaItems = mediaItems; GigyaMethods.PublishUserAction(action, recipient.UserId, "internal"); }
public static void AddToRecurringBilling(IPTV2Entities context, Product product, Offering offering, User user, DateTime registDt, CreditCardInfo info) { //Check if product is subscription product if (product is SubscriptionProduct) { //check if there are any recurring products that have the same productgroup SubscriptionProduct subscriptionProduct = (SubscriptionProduct)product; //Get user's recurring productGroups var recurringProductGroups = user.GetRecurringProductGroups(offering); if (!recurringProductGroups.Contains(subscriptionProduct.ProductGroup)) { var productPackage = context.ProductPackages.FirstOrDefault(p => p.ProductId == product.ProductId); if (productPackage != null) { var entitlement = user.PackageEntitlements.FirstOrDefault(p => p.PackageId == productPackage.PackageId); if (entitlement != null) { var billing = new CreditCardRecurringBilling() { CreatedOn = registDt, Product = product, User = user, UpdatedOn = registDt, EndDate = entitlement.EndDate, NextRun = entitlement.EndDate.AddDays(-3).Date, // Run day before expiry StatusId = GlobalConfig.Visible, Offering = offering, Package = (Package)productPackage.Package, CreditCardHash = MyUtility.GetSHA1(info.Number), NumberOfAttempts = 0 }; context.RecurringBillings.Add(billing); context.SaveChanges(); } } } } }
public RespCancelRecurringPayment CancelRecurringPayment(User user, Product product) { RespCancelRecurringPayment result = null; InitializeServiceClient(); try { TestConnect(); ReqCancelRecurringPayment req = new ReqCancelRecurringPayment() { CustomerId = (int)user.GomsCustomerId, Email = user.EMail, UID = ServiceUserId, PWD = ServicePassword, ServiceId = (int)user.GomsServiceId, ItemId = (int)product.GomsProductId, }; result = _serviceClient.CancelRecurringPayment(req); return result; } catch (GomsException e) { result = new RespCancelRecurringPayment { IsSuccess = false, StatusCode = e.StatusCode, StatusMessage = e.StatusMessage }; } return (result); }
private static DateTime GetStartDateBasedOnProductBreakingDate(Product product, DateTime registDt) { var currentDt = registDt; if (product.BreakingDate != null) registDt = (DateTime)product.BreakingDate > currentDt ? (DateTime)product.BreakingDate : currentDt; return registDt; }
private PurchaseItem CreatePurchaseItem(System.Guid userId, Product product, ProductPrice priceOfProduct) { PurchaseItem item = new PurchaseItem() { RecipientUserId = userId, ProductId = product.ProductId, Price = priceOfProduct.Amount, Currency = priceOfProduct.CurrencyCode, Remarks = product.Name }; return item; }
private static PurchaseItem CreatePurchaseItem(System.Guid userId, Product product, decimal Amount, string CurrencyCode) { PurchaseItem item = new PurchaseItem() { RecipientUserId = userId, ProductId = product.ProductId, Price = Amount, Currency = CurrencyCode, Remarks = product.Name }; return item; }