protected void Page_Init(object sender, EventArgs e) { Session["Active"] = "SearchBookingsList"; int customerId; int.TryParse(Request.Params["id"], out customerId); CurrentCustomerId = customerId; if (!IsPostBack) { Session["CurrentPage"] = 1; CustomerInfosDetails = _customerInfoRepository.GetById(CurrentCustomerId); string json = JsonConvert.SerializeObject(CustomerInfosDetails, CustomSettings.SerializerSettings()); Session["CustomerInfosDetails"] = json; _response = _helper.SearchDataByCustomerId(CurrentCustomerId); _currentData = _response.ListBookingsData.ToList(); string jsonData = JsonConvert.SerializeObject(_currentData, CustomSettings.SerializerSettings()); Session["SearchCustomerBookings"] = jsonData; BindRepeater(_currentData.Take(10)); } else { string session = Session["CustomerInfosDetails"] != null ? Session["CustomerInfosDetails"].ToString() : string.Empty; CustomerInfosDetails = JsonConvert.DeserializeObject <CustomerInfos>(session); string sessionData = Session["SearchCustomerBookings"] != null ? Session["SearchCustomerBookings"].ToString() : string.Empty; _currentData = JsonConvert.DeserializeObject <List <SearchDataObject> >(sessionData); } if (CustomerInfosDetails == null) { Response.Redirect(Constant.SearchBookingsAdminpage); } // Get Membership Info PublicDiscounts = _customerInfoRepository.GetSubscriptionDiscount(CustomerInfosDetails.CustomerId); if (PublicDiscounts != null) { _subscriptionBookings = _subscriptionBookingRepository.GetByCustomerId(CustomerInfosDetails.CustomerId, PublicDiscounts.Id); if (_subscriptionBookings != null && _subscriptionBookings.Status == (byte)Enums.SubscriptionBookingStatus.Active) { CancelMembershipLinkButton.Visible = true; } } BindCustomerData(); }
protected void btnViewSubscription_Click(object sender, EventArgs e) { int subscriptionId = AppConfiguration.SubscriptionUpgradeId; var upgradeSubscription = _bookingRepository.SubscriptionsList.FirstOrDefault(s => s.Id == subscriptionId && s.IsActive); SubscriptionBookings subscriptionBookings = _subscriptionBookingRepository.GetByCustomerId(PublicCustomerInfos.CustomerId, PublicDiscounts.Id); if (subscriptionBookings != null) { var subscriptionDetailUrl = string.Format(Constant.SubscriptionConfirmPage, upgradeSubscription.StripePlanId, subscriptionBookings.Id, "/" + Page.RouteData.Values["bookingId"]); Response.Redirect(subscriptionDetailUrl, false); } }
private int PurchaseSubscription(out bool success) { // Check customer change their email success = true; bool isPayByCredit; var bookingExists = _subscriptionBookingRepository.GetBookingInLast3Minutes(PublicSubscription.Id, PublicCustomerInfos != null ? PublicCustomerInfos.EmailAddress : email.Text.Replace(" ", "")); if (bookingExists != null) { success = false; newBookingModal.Visible = true; return(bookingExists.Id); } if (PublicCustomerInfos == null) { PublicCustomerInfos = new CustomerInfos { EmailAddress = email.Text.Replace(" ", ""), FirstName = FirstName.Text.Trim(), LastName = LastName.Text.Trim(), ZipCode = txtzipcode.Text.Trim() }; // Create new account with email var response = _customerInfoRepository.GetVipAccess(email.Text.Replace(" ", ""), Constant.SearchPageDefault, FirstName.Text.Trim(), LastName.Text.Trim()); PublicCustomerInfos.CustomerId = response.CustomerId; PublicCustomerInfos.StripeCustomerId = response.StripeCustomerId; CacheLayer.Clear(CacheKeys.CustomerInfosCacheKey); CacheLayer.Clear(CacheKeys.CustomerCreditsCacheKey); Session["ReferralCode"] = response.ReferralCode; string searchPage = !string.IsNullOrEmpty((string)Session["SearchPage"]) ? Session["SearchPage"].ToString() : Constant.SearchPageDefault; // Send email new account var responseEmail = EmailHelper.EmailNewAccount(PublicCustomerInfos.EmailAddress, PublicCustomerInfos.FirstName, response.Password, Helper.ResolveRelativeToAbsoluteUrl(Request.Url, string.Format("{0}?sp={1}", searchPage, response.PasswordKey)), // Reset Password Url Helper.ResolveRelativeToAbsoluteUrl(Request.Url, string.Format("{0}?c={1}", searchPage, response.AccessKey))); // Browse Day Pass PublicCustomerCredits = _subscriptionBookingRepository.GetCustomerCredits(response.CustomerId); Session["UserSession"] = response.AccessKey; Session["IsRegister"] = true; Session["ReferralCode"] = response.ReferralCode; } Regex regex = new Regex(@"([\d]+)(\s)?/(\s)?([\d]+)"); int month; int year; int.TryParse(regex.Match(txtexpdat.Value).Groups[1].Value, out month); int.TryParse("20" + regex.Match(txtexpdat.Value).Groups[4].Value, out year); string fullName = string.Format("{0} {1}", FirstName.Text, LastName.Text); // Check customer has exists with email int customerId = PublicCustomerInfos.CustomerId; StripeCustomer stripeCustomer = null; Discounts discounts = new Discounts(); double actualPrice = PublicSubscription.Price; double totalPrice; bool hasCoupon = false; string stripeCouponId = string.Empty; // update user info with exists if (!string.IsNullOrEmpty(PublicCustomerInfos.StripeCustomerId)) { stripeCustomer = GetCustomerById(PublicCustomerInfos.StripeCustomerId); } // Use New Card if (MVCardInfo.ActiveViewIndex == 0) { StripeToken stripeToken = CreateToken(cctextbox.Text.Replace(" ", ""), year, month, txtzipcode.Text, fullName, txtseccode.Value); // update new card for customer PublicCustomerInfos.StripeTokenId = stripeToken.Id; PublicCustomerInfos.StripeCardId = stripeToken.StripeCard.Id; PublicCustomerInfos.BankAccountLast4 = stripeToken.StripeCard.Last4; PublicCustomerInfos.CardType = Helper.GetCreditCardType(cctextbox.Text.Replace(" ", "")); PublicCustomerInfos.ZipCode = txtzipcode.Text; if (stripeCustomer == null) { stripeCustomer = CreateCustomer(PublicCustomerInfos.EmailAddress, fullName, stripeToken.Id); PublicCustomerInfos.StripeCustomerId = stripeCustomer.Id; } else { // Update Stripe exists customer with New Card var card = CreateCard(stripeToken.Id, PublicCustomerInfos.StripeCustomerId); UpdateCustomer(PublicCustomerInfos.EmailAddress, fullName, PublicCustomerInfos.StripeCustomerId, card.Id); } _customerInfoRepository.Update(PublicCustomerInfos); isPayByCredit = IsPayByCreditCheckBox.Checked; } else { isPayByCredit = DCreditCheckBox.Checked; } if (string.IsNullOrWhiteSpace(PromoText.Text)) { Session.Remove(_discountKey); } // Not available upgrade so checkout with this hotel if (Session[_discountKey] != null) { discounts = JsonConvert.DeserializeObject <Discounts>(Session[_discountKey].ToString()); } // Have Discount if (discounts != null && discounts.Id > 0) { discounts = _discountRepository.VerifyDiscountsSubscription(discounts, customerId, PublicSubscription.Id); // Discount Invalid if (discounts != null) { actualPrice = Helper.CalculateDiscount(discounts, actualPrice, TotalTickets); hasCoupon = true; } else { InitDefaultPromo(Message.ExceedLimit, false); Session[_discountKey] = null; success = false; return(0); } if (discounts.BillingCycleNumber > 1) { stripeCouponId = string.Format("{0}C{1}", PublicCustomerInfos.CustomerId, Helper.RandomString(Constant.BookingCodeLength)); if (discounts.PercentOff > 0) { var couponPrice = PublicSubscription.Price - actualPrice; //Create the Coupon var coupon = new StripeCouponCreateOptions { Duration = "repeating", Id = stripeCouponId, MaxRedemptions = discounts.BillingCycleNumber, DurationInMonths = discounts.BillingCycleNumber }; if (discounts.PromoType == (int)Enums.PromoType.Fixed) { coupon.AmountOff = (int)(couponPrice * 100); coupon.Currency = "usd"; } if (discounts.PromoType == (int)Enums.PromoType.Percent) { coupon.PercentOff = (int)(discounts.PercentOff); } //coupon.AmountOff - AmountOff is not a property of StripeCouponCreateOptions var couponService = new StripeCouponService(); StripeCoupon createdCoupon = couponService.Create(coupon); //Apply it to the customer var customerOptions = new StripeCustomerUpdateOptions { Coupon = createdCoupon.Id }; var customerService = new StripeCustomerService(); customerService.Update(PublicCustomerInfos.StripeCustomerId, customerOptions); } } } if (PublicCustomerInfos.FirstName != FirstName.Text.Trim() || PublicCustomerInfos.LastName != LastName.Text.Trim()) { PublicCustomerInfos.FirstName = FirstName.Text.Trim(); PublicCustomerInfos.LastName = LastName.Text.Trim(); _customerInfoRepository.Update(PublicCustomerInfos); // Update Stripe exists customer UpdateCustomer(PublicCustomerInfos.EmailAddress, fullName, PublicCustomerInfos.StripeCustomerId, string.Empty); } // Discount 100% ?? // Price equal 0, so we should not charge with this totalPrice = actualPrice * TotalTickets; double chargePrice = totalPrice; string creditLogDescription = string.Empty; var subscriptionOptions = new StripeSubscriptionCreateOptions { PlanId = PublicSubscription.StripePlanId }; // Use DayAxe Credit if (isPayByCredit && PublicCustomerCredits != null && PublicCustomerCredits.Amount > 0) { hasCoupon = true; chargePrice = totalPrice - PublicCustomerCredits.Amount; if (chargePrice <= 0) { chargePrice = 0; } } if (hasCoupon && string.IsNullOrEmpty(stripeCouponId)) { var couponPrice = PublicSubscription.Price - chargePrice; if (couponPrice > 0) { // Create Coupon Id because we used DayAxe Credit stripeCouponId = string.Format("{0}C{1}", PublicCustomerInfos.CustomerId, Helper.RandomString(Constant.BookingCodeLength)); var couponOptions = new StripeCouponCreateOptions { Id = stripeCouponId, AmountOff = Convert.ToInt32(couponPrice * 100), // USD Duration = "once", Currency = "USD" }; // Create Coupon var couponService = new StripeCouponService(); var coupon = couponService.Create(couponOptions); subscriptionOptions.CouponId = stripeCouponId; creditLogDescription = string.Format("{0} – {1}", PublicSubscription.Name, coupon.Id); } } // Create Subscription on Stripe var subscriptionService = new StripeSubscriptionService(); StripeSubscription subscription = subscriptionService.Create(PublicCustomerInfos.StripeCustomerId, subscriptionOptions); var booking = new SubscriptionBookings { SubscriptionId = PublicSubscription.Id, Quantity = TotalTickets, StripeCouponId = stripeCouponId, BookedDate = DateTime.UtcNow, ActivedDate = subscription.Start, StartDate = subscription.CurrentPeriodStart, EndDate = subscription.CurrentPeriodEnd, Status = (int)Enums.SubscriptionBookingStatus.Active, CustomerId = customerId, LastUpdatedDate = DateTime.UtcNow, LastUpdatedBy = customerId, StripeSubscriptionId = subscription.Id }; var param = new AddSubscriptionBookingParams { SubscriptionBookingsObject = booking, CustomerCreditsObject = PublicCustomerCredits, Description = creditLogDescription, SubscriptionName = PublicSubscription.Name, FirstName = PublicCustomerInfos.FirstName, LastName = PublicCustomerInfos.LastName, SubscriptionBookingDiscounts = discounts, ActualPrice = actualPrice, MerchantPrice = PublicSubscription.Price, PayByCredit = totalPrice.Equals(chargePrice) ? 0 : totalPrice - chargePrice, TotalPrice = chargePrice, MaxPurchases = PublicSubscription.MaxPurchases }; int bookingId = _subscriptionBookingRepository.Add(param); //Session.Remove(_discountKey); CacheLayer.Clear(CacheKeys.SubscriptionBookingsCacheKey); CacheLayer.Clear(CacheKeys.CustomerInfosCacheKey); CacheLayer.Clear(CacheKeys.CustomerCreditsCacheKey); CacheLayer.Clear(CacheKeys.CustomerCreditLogsCacheKey); CacheLayer.Clear(CacheKeys.DiscountsCacheKey); CacheLayer.Clear(CacheKeys.SubscriptionBookingDiscountsCacheKey); CacheLayer.Clear(CacheKeys.SubsciptionDiscountUsedCacheKey); CacheLayer.Clear(CacheKeys.SubscriptionDiscountsCacheKey); CacheLayer.Clear(CacheKeys.SubscriptionCyclesCacheKey); return(bookingId); }
protected void Page_Init(object sender, EventArgs e) { if (PublicCustomerInfos == null) { var loginLinkButton = (HtmlAnchor)ControlExtensions.FindControlRecursive(Master, "LoginLinkButton"); loginLinkButton.Visible = false; Response.Redirect(string.Format(Constant.SignIpPage, HttpUtility.UrlEncode(Request.Url.PathAndQuery))); } MemberShipDetailView.ActiveViewIndex = 0; YourPlanLabel.Text = ErrorMessage.MembershipNotActive; reactiveMembershipLink.Visible = true; cancelMembershipLink.Visible = false; _subscriptionBookings = _subscriptionBookingRepository.GetSuspendedByCustomerId(PublicCustomerInfos.CustomerId); if (_subscriptionBookings != null) { PublicDiscounts = _customerInfoRepository.GetSubscriptionDiscountSuspended(PublicCustomerInfos.CustomerId); ErrorMessageLabel.Text = "Your subscription is suspended. Please contact our customer support at <a href=\"mailto:[email protected]\">[email protected]</a> to resolve this issue."; ErrorMessageLabel.Visible = true; ErrorMessageLabel.CssClass = "error-message"; } if (PublicDiscounts != null) { MemberShipDetailView.ActiveViewIndex = 1; _subscriptions = _customerInfoRepository.GetSubscriptionByCustomerId(PublicCustomerInfos.CustomerId, PublicDiscounts.Id); if (_subscriptions != null) { YourPlanLabel.Text = string.Format("{0} - {1} <br/> {2} / month", _subscriptions.Name.ToUpper(), _subscriptions.ProductHighlight, Helper.FormatPrice(_subscriptions.Price)); WhatYouGetLit.Text = _subscriptions.WhatYouGet; } // Avoid get again by Suspended case if (_subscriptionBookings == null) { _subscriptionBookings = _subscriptionBookingRepository.GetByCustomerId(PublicCustomerInfos.CustomerId, PublicDiscounts.Id); } if (_subscriptionBookings != null) { switch (_subscriptionBookings.Status) { case (int)Enums.SubscriptionBookingStatus.Active: NextCycleLit.Text = string.Format("Next cycle begins {0:MMMM dd}", PublicDiscounts.EndDate.HasValue ? PublicDiscounts.EndDate.Value.ToLosAngerlesTime().AddDays(1) : DateTime.UtcNow); reactiveMembershipLink.Visible = false; cancelMembershipLink.Visible = true; break; case (int)Enums.SubscriptionBookingStatus.End: NextCycleLit.Visible = false; break; case (int)Enums.SubscriptionBookingStatus.Suspended: reactiveMembershipLink.Visible = false; cancelMembershipLink.Visible = false; break; } } ValidLit.Text = string.Format("Valid through {0:MMMM dd, yyyy}", PublicDiscounts.EndDate.HasValue ? PublicDiscounts.EndDate.Value.ToLosAngerlesTime() : DateTime.UtcNow); MembershipIdLabel.Text = PublicDiscounts.Code; } }