示例#1
0
        public ActionResult AddCoupon(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var customerService = new StripeCustomerService();
            var stripeCustomer  = customerService.Get(id);

            var user = UserManager.Users.First(u => u.Email == stripeCustomer.Email);

            if (stripeCustomer == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var couponService = new StripeCouponService();
            var coupons       = couponService.List().Select(c =>
                                                            new SelectListItem
            {
                Value = c.Id,
                Text  = c.Id
            });

            var model = new CustomerAddCouponViewModel
            {
                CustomerDescription = string.Format("{0} {1} ({2})", user.FirstName, user.LastName, user.Email),
                CustomerId          = id,
                SelectedCoupon      = "",
                Coupons             = coupons
            };

            return(View(model));
        }
示例#2
0
        public ActionResult Details(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var couponService = new StripeCouponService();
            var stripeCoupon  = couponService.Get(id);

            if (stripeCoupon == null)
            {
                return(HttpNotFound());
            }

            var coupon = new CouponDetailViewModel
            {
                AmountOff        = stripeCoupon.AmountOff,
                Currency         = stripeCoupon.Currency,
                Created          = stripeCoupon.Created,
                Duration         = stripeCoupon.Duration,
                DurationInMonths = stripeCoupon.DurationInMonths,
                Id             = stripeCoupon.Id,
                LiveMode       = stripeCoupon.LiveMode,
                MaxRedemptions = stripeCoupon.MaxRedemptions,
                Metadata       = stripeCoupon.Metadata,
                Object         = stripeCoupon.Object,
                Valid          = stripeCoupon.Valid,
                TimesRedeemed  = stripeCoupon.TimesRedeemed,
                RedeemBy       = stripeCoupon.RedeemBy,
                PercentOff     = stripeCoupon.PercentOff
            };

            return(View(coupon));
        }
示例#3
0
        public coupons_fixture()
        {
            CouponCreateOptions = new StripeCouponCreateOptions()
            {
                // Add a space at the end to ensure the ID is properly URL encoded
                // when passed in the URL for other methods
                Id               = "test-coupon-" + Guid.NewGuid().ToString() + " ",
                PercentOff       = 25,
                Duration         = "repeating",
                DurationInMonths = 3,
            };

            CouponUpdateOptions = new StripeCouponUpdateOptions {
                Metadata = new Dictionary <string, string> {
                    { "key_1", "value_1" }
                }
            };

            var service = new StripeCouponService(Cache.ApiKey);

            Coupon          = service.Create(CouponCreateOptions);
            CouponRetrieved = service.Get(Coupon.Id);
            CouponUpdated   = service.Update(Coupon.Id, CouponUpdateOptions);
            CouponsList     = service.List();
            CouponDeleted   = service.Delete(Coupon.Id);
        }
示例#4
0
        public ActionResult DeleteConfirmed(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var couponService = new StripeCouponService();

            couponService.Delete(id);

            return(RedirectToAction("Index"));
        }
示例#5
0
        public static StripeCoupon GetCoupon(string Id)
        {
            var couponService = new StripeCouponService();

            try
            {
                return(couponService.Get(Id));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
示例#6
0
 public StripeCoupon RetrieveCoupon(string coupon)
 {
     try
     {
         var          couponService = new StripeCouponService();
         StripeCoupon response      = couponService.Get(coupon);
         return(response);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#7
0
        public static bool DeleteCoupon(String couponId)
        {
            var couponService = new StripeCouponService();

            try
            {
                StripeDeleted coupon = couponService.Delete(couponId);
                return(coupon.Deleted);
            }
            catch
            {
                return(false);
            }
        }
        public JsonResult DeleteCode(string CodeID)
        {
            String res = "";

            try
            {
                var couponService = new StripeCouponService();
                StripeHelper.DeleteCoupon(CodeID);
                res = adata.DeleteCouponData(CodeID);
            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            return(new JsonResult {
                Data = res, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#9
0
        // GET: Admin/Coupons
        public ActionResult Index()
        {
            var couponService = new StripeCouponService();
            var coupons       = couponService.List().Select(c =>
                                                            new CouponListViewModel
            {
                Id               = c.Id,
                AmountOff        = c.AmountOff,
                Currency         = c.Currency,
                Duration         = c.Duration,
                DurationInMonths = c.DurationInMonths,
                MaxRedemptions   = c.MaxRedemptions,
                PercentOff       = c.PercentOff,
                RedeemBy         = c.RedeemBy,
                TimesRedeemed    = c.TimesRedeemed
            });

            return(View(coupons));
        }
        public IEnumerable <CouponView> GetCoupons()
        {
            SetStripeKey();
            var couponService = new StripeCouponService();
            StripeList <StripeCoupon> couponItems = couponService.List(
                new StripeCouponListOptions
            {
                Limit = _maximumItemsToReturn,
            }
                );

            var jsonProducts = couponItems
                               .Where(c => c.Valid)
                               .Select(p => new CouponView {
                Id = p.Id, Name = p.Name, AmountOff = p.AmountOff, PercentOff = p.PercentOff, Currency = p.Currency
            });

            return(jsonProducts);
        }
        public StripeCouponServiceTest()
        {
            this.service = new StripeCouponService();

            this.createOptions = new StripeCouponCreateOptions()
            {
                PercentOff = 25,
                Duration   = "forever",
            };

            this.updateOptions = new StripeCouponUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new StripeCouponListOptions()
            {
                Limit = 1,
            };
        }
示例#12
0
        public ActionResult Create(CouponCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var options = new StripeCouponCreateOptions
            {
                Id               = model.Id,
                AmountOff        = model.AmountOff,
                Currency         = model.Currency,
                Duration         = model.Duration,
                DurationInMonths = model.DurationInMonths,
                MaxRedemptions   = model.MaxRedemptions,
                PercentOff       = model.PercentOff,
                RedeemBy         = model.RedeemBy
            };

            var couponService = new StripeCouponService();
            var coupon        = couponService.Create(options);

            return(RedirectToAction("Index"));
        }
 public StripeCouponCreateOptionsTest()
 {
     this.service = new StripeCouponService();
 }
示例#14
0
        public static void CreateCoupon(StripeCouponCreateOptions couponOptions)
        {
            var couponService = new StripeCouponService();

            couponService.Create(couponOptions);
        }
        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);
        }