private int PurchaseGiftCard(out bool success) { // Check customer change their email success = true; bool isPayByCredit; 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 = _customerInfoRepository.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.TryParse(regex.Match(txtexpdat.Value).Groups[1].Value, out month); int year; 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 StripeCustomer stripeCustomer = null; //var discounts = new Discounts(); double actualPrice; // 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 (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 stripeCustomer = UpdateCustomer(PublicCustomerInfos.EmailAddress, fullName, PublicCustomerInfos.StripeCustomerId, string.Empty); } // Discount 100% ?? // Price equal 0, so we should not charge with this double.TryParse(ValueText.Text, out actualPrice); double chargePrice = actualPrice; string creditLogDescription = string.Format("eGift Cards – {0}", Helper.FormatPrice(actualPrice * -1)); DateTime deliveryDate; string stripeChargeId = string.Empty; // Use DayAxe Credit if (isPayByCredit && PublicCustomerCredits != null && PublicCustomerCredits.Amount > 0) { // Create Coupon Id because we used DayAxe Credit chargePrice = actualPrice - PublicCustomerCredits.Amount; if (chargePrice <= 0) { chargePrice = 0; } } if (chargePrice > 0) { StripeCharge stripeCharge = CreateCharges(chargePrice, stripeCustomer.Id, creditLogDescription); stripeChargeId = stripeCharge.Id; } DateTime.TryParseExact(DeliveryDateText.Text, "MM/dd/yyyy", null, DateTimeStyles.None, out deliveryDate); double userBookedDate; double.TryParse(HidUserBookedDate.Value, out userBookedDate); var param = new GiftCardBookings { CustomerId = PublicCustomerInfos.CustomerId, GiftCardId = 0, Price = chargePrice, PayByCredit = actualPrice - chargePrice, TotalPrice = actualPrice, StripeChargeId = stripeChargeId, BookedDate = DateTime.UtcNow, RecipientEmail = ToText.Text.Trim(), RecipientName = NameText.Text.Trim(), Message = !string.IsNullOrEmpty(MessageText.Text) ? MessageText.Text : "Enjoy the gift of DayAxe from me!", DeliveryDate = deliveryDate.Date.AddHours(9 + 5), // 9AM + EST = 5 hours Description = creditLogDescription, LastUpdatedBy = PublicCustomerInfos.CustomerId, LastUpdatedDate = DateTime.UtcNow, UserBookedDate = userBookedDate }; int giftCardBooking = _giftCardBookingRepository.Add(param); CacheLayer.Clear(CacheKeys.GiftCardCacheKey); CacheLayer.Clear(CacheKeys.GiftCardBookingCacheKey); CacheLayer.Clear(CacheKeys.CustomerCreditsCacheKey); CacheLayer.Clear(CacheKeys.CustomerCreditLogsCacheKey); return(giftCardBooking); }