private StripeCard GetCardById(string customerId, string cardId)
        {
            var        cardService = new StripeCardService();
            StripeCard stripeCard  = cardService.Get(customerId, cardId);

            return(stripeCard);
        }
Beispiel #2
0
        public static StripeCard GetCardDetails(String custmId, String cardId)
        {
            var cardService = new StripeCardService();

            try
            {
                return(cardService.Get(custmId, cardId));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Beispiel #3
0
        public void PassingTest()
        {
            var configuration = new ConfigurationBuilder().AddUserSecrets().Build();

            StripeConfiguration.SetApiKey(configuration["stripe-api-key"]);

            var planService     = new StripePlanService();
            var customerService = new StripeCustomerService();
            var cardService     = new StripeCardService();

            var testPlan = planService.Get("UnitTestPlan") ?? planService.Create(new StripePlanCreateOptions
            {
                Id            = "UnitTestPlan",
                Amount        = 31,
                Currency      = "usd",
                Interval      = "month",
                IntervalCount = 1,
                Name          = "Test plan created from unit test"
            });
            var customer = customerService.Get("cus_8OFUUhfJqfAdm9") ?? customerService.Create(new StripeCustomerCreateOptions
            {
                Email       = "*****@*****.**",
                Description = "test customer description",
                PlanId      = testPlan.Id,
                SourceCard  = new SourceCard()
            });
            var card = cardService.Get(customer.Id, "card_187T8ILiuPyBUDeGL5nbR4PP") ?? cardService.Create(customer.Id, new StripeCardCreateOptions
            {
                SourceCard = new SourceCard
                {
                    Number          = "4242424242424242",
                    ExpirationYear  = "2022",
                    ExpirationMonth = "10",
                    AddressCountry  = "US",
                    AddressLine1    = "24 Beef Flank St",
                    AddressLine2    = "Apt 24",
                    AddressCity     = "Biggie Smalls",
                    AddressState    = "NC",
                    AddressZip      = "27617",
                    Name            = "Joe Meatballs",
                    Cvc             = "1223"
                }
            });

            Assert.NotNull(card);
        }
Beispiel #4
0
        public ActionResult CancelSubscription(long userID)
        {
            string         customerID      = Convert.ToString(SessionController.UserSession.CustomerID);
            var            customerService = new StripeCustomerService();
            StripeCustomer stripeCustomer  = customerService.Get(customerID);

            var subscriptionID = stripeCustomer.Subscriptions.Data[0].Id;

            var subscriptionService = new StripeSubscriptionService();
            var status = subscriptionService.Cancel(subscriptionID, true); // optional cancelAtPeriodEnd flag

            SessionController.UserSession.IsPaid = false;

            //Delete the customer's card from stripe
            var           cardService = new StripeCardService();
            StripeCard    stripeCard  = cardService.Get(customerID, stripeCustomer.DefaultSourceId);
            StripeDeleted card        = cardService.Delete(customerID, stripeCard.Id);

            return(Json(status, JsonRequestBehavior.AllowGet));
        }
Beispiel #5
0
        public ActionResult AddCustomer(string stripeEmail, string stripeToken)
        {
            //create customer with stripeToken
            var myCustomer = new StripeCustomerCreateOptions();

            myCustomer.Email       = stripeEmail;
            myCustomer.SourceToken = stripeToken;

            //get customerID
            var            customerService = new StripeCustomerService();
            StripeCustomer stripeCustomer  = customerService.Create(myCustomer);

            stripeCustomerId = stripeCustomer.Id;

            //get cardId from stripeCustomer
            cardId = stripeCustomer.DefaultSourceId;

            //get card information from cardId
            var myCard = new StripeCardCreateOptions();

            myCard.SourceToken = cardId;

            var        cardService = new StripeCardService();
            StripeCard stripeCard  = cardService.Get(stripeCustomerId, cardId);


            //save the customerID, cardID, CC4, company name, expiry object into the database
            string   customerID = stripeCustomer.Id;
            string   cardID     = stripeCustomer.DefaultSourceId;
            string   cc4        = stripeCard.Last4;
            string   company    = stripeCard.Brand;
            int      month      = Convert.ToInt32(stripeCard.ExpirationMonth);
            int      year       = Convert.ToInt32(stripeCard.ExpirationYear);
            DateTime expiry     = new DateTime(year, month, 1);

            var currentUserID = User.Identity.GetUserId();

            this.Edit((String)currentUserID, customerID, cardID, cc4, company, expiry);
            TempData["notice"] = "Card successfully added!";
            return(RedirectToAction("Index", "Manage"));
        }
Beispiel #6
0
        public ActionResult GetSubscriptionPopup(SubscriptionOption model)
        {
            var subscriptionModel = new SubscriptionModel();

            subscriptionModel.subscriptionOption  = model;
            subscriptionModel.CardType            = GetPaymentCardType();
            subscriptionModel.ExpirationYearList  = GetExpirationYear();
            subscriptionModel.ExpirationMonthList = GetExpirationMonth();
            var customerID = SessionController.UserSession.CustomerID;           //Check whether the user already has credit card details or not

            if (customerID != null && customerID != "")
            {
                var            customerService = new StripeCustomerService();
                StripeCustomer stripeCustomer  = customerService.Get(customerID);
                var            cardService     = new StripeCardService();
                StripeCard     stripeCard      = cardService.Get(customerID, stripeCustomer.DefaultSourceId); // optional isRecipient
                foreach (var card in subscriptionModel.CardType)
                {
                    stripeCard.Brand             = subscriptionModel.CardType[0].Name;
                    subscriptionModel.CardTypeID = Convert.ToInt32(subscriptionModel.CardType[0].ID);
                }
                subscriptionModel.ExpirationMonth = stripeCard.ExpirationMonth;
                subscriptionModel.ExpirationYear  = stripeCard.ExpirationYear;
                subscriptionModel.CardTypeID      = subscriptionModel.CardTypeID;
                subscriptionModel.CardNumber      = "************" + stripeCard.Last4;
                subscriptionModel.NameOnCard      = stripeCard.Name;
            }
            //----------------------
            if (model.RoleId == 2)
            {
                ViewBag.SubscriptionTitle = "Find unlimited investment opportunities for " + model.AmountPerMonth + " per month.";
            }
            else if (model.RoleId == 3)
            {
                ViewBag.SubscriptionTitle = "List unlimited investment opportunities for " + model.AmountPerMonth + " per month.";
            }
            return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
        }
        protected void CheckInDateLink_OnClick(object sender, EventArgs e)
        {
            int  ticketAvailable;
            bool availableProduct = PublicBooking.CheckinDate == null ||
                                    DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(PublicHotel.TimeZoneId).AddDays(2).Date <= PublicBooking.CheckinDate.Value;
            var param = new CheckAvailableProductParams
            {
                ProductId   = PublicProduct.ProductId,
                CheckInDate = _selectedCheckInDate,
                TotalTicket = PublicBooking.Quantity,
                BookingId   = PublicBooking.BookingId,
                IsAdmin     = false,
                TimezoneId  = PublicHotel.TimeZoneId
            };

            availableProduct &= _productRepository.CheckAvailableProduct(param, out ticketAvailable);

            if (!availableProduct)
            {
                Session.Remove("CheckInDate" + PublicBooking.BookingId);
                CheckInDateLink.Text     = "SELECT<br/>CHECK-IN DATE";
                CheckInDateLink.CssClass = "select-checkin-date";
                ScriptManager.RegisterStartupScript(CheckInDateChangePanel, CheckInDateChangePanel.GetType(), "Update_Not_Available", "$(function(){$('#updateFail').modal('show');});", true);
                return;
            }

            var  logs     = new CustomerCreditLogs();
            bool isRefund = false;

            try
            {
                if (!PublicBooking.HasInvoice)
                {
                    MaintainOldInvoices();
                }

                var newPrice = _productRepository.GetById(PublicProduct.ProductId, _selectedCheckInDate).ActualPriceWithDate;

                double actualPrice = GetActualPrice(newPrice);

                double diffPrice = actualPrice * PublicBooking.Quantity - PublicBooking.TotalPrice;

                // Charge
                if (diffPrice > 0)
                {
                    Charges(diffPrice, newPrice, actualPrice);

                    PublicBooking.TotalPrice   += diffPrice;
                    PublicBooking.HotelPrice    = actualPrice;
                    PublicBooking.MerchantPrice = newPrice.Price;
                }
                else if (diffPrice < 0) //Refund
                {
                    double payByCard = Math.Abs(diffPrice) - PublicBooking.PayByCredit;
                    if (PublicBooking.PayByCredit > 0)
                    {
                        var market = (from mh in _productRepository.MarketHotelList
                                      join m in _productRepository.MarketList on mh.MarketId equals m.Id
                                      where mh.HotelId == PublicHotel.HotelId
                                      select m).FirstOrDefault();
                        logs = new CustomerCreditLogs
                        {
                            CustomerId = PublicCustomerInfos != null
                                ? PublicCustomerInfos.CustomerId
                                : PublicBooking.CustomerId,
                            ProductId   = PublicBooking.ProductId,
                            Description = string.Format("{0} – {1} – {2} – {3}",
                                                        PublicProduct.ProductName,
                                                        PublicHotel.HotelName,
                                                        market != null ? market.LocationName : "",
                                                        PublicBooking.BookingIdString),
                            CreatedBy   = PublicCustomerInfos != null ? PublicCustomerInfos.CustomerId : 0,
                            CreatedDate = DateTime.UtcNow,
                            CreditType  = payByCard >= 0
                                ? (byte)Enums.CreditType.FullPurchaseRefund
                                : (byte)Enums.CreditType.PartialPuchaseRefund,
                            ReferralId = 0,
                            BookingId  = PublicBooking.BookingId,
                            Status     = true,
                            GiftCardId = 0
                        };
                        PublicBooking.PaymentType = (byte)Enums.PaymentType.DayAxeCredit;

                        // Refund All of Credit Used
                        if (payByCard >= 0)
                        {
                            PublicBooking.PayByCredit = 0;
                        }
                        else
                        {
                            PublicBooking.PayByCredit -= Math.Abs(diffPrice);
                        }
                    }

                    // Refund More with Stripe
                    if (payByCard > 0)
                    {
                        Refund(payByCard, new KeyValuePair <double, double>(PublicBooking.MerchantPrice, 0),
                               PublicBooking.HotelPrice);

                        PublicBooking.PaymentType = (byte)Enums.PaymentType.Stripe;

                        var        cardService = new StripeCardService();
                        StripeCard stripeCard  = cardService.Get(PublicCustomerInfos.StripeCustomerId,
                                                                 PublicCustomerInfos.StripeCardId);
                        StripeCardString = string.Format("{0} {1}", stripeCard.Brand, stripeCard.Last4);
                    }

                    PublicBooking.TotalPrice   += diffPrice;
                    PublicBooking.HotelPrice    = actualPrice;
                    PublicBooking.MerchantPrice = newPrice.Price;
                    isRefund = true;

                    PublicBooking.StripeCardString = StripeCardString;
                    _bookingRepository.RefundBooking(PublicBooking, logs);
                }
                else
                {
                    PublicBooking.TotalPrice   += diffPrice;
                    PublicBooking.HotelPrice    = actualPrice;
                    PublicBooking.MerchantPrice = newPrice.Price;
                }
            }
            catch (Exception ex)
            {
                UpdateNotPossibleLit.Text = ex.Message;
                ScriptManager.RegisterStartupScript(CheckInDateChangePanel, CheckInDateChangePanel.GetType(), "UpdateFail", "$(function(){$('#updateFail').modal('show');});", true);
                return;
            }

            PublicBooking.CheckinDate = _selectedCheckInDate.AddHours(Math.Abs(PublicHotel.TimeZoneOffset));
            PublicBooking.ExpiredDate = _selectedCheckInDate.AddDays(1).AddHours(Math.Abs(PublicHotel.TimeZoneOffset));
            if (isRefund)
            {
                _bookingRepository.Update(PublicBooking);
            }
            else
            {
                _bookingRepository.Update(PublicBooking, 0, logs);
            }

            Session.Remove("CheckInDate" + PublicBooking.BookingId);
            BindExpiredDate();
            CacheLayer.ClearAll();
            updateSuccess.Visible    = true;
            CheckInDateLink.Text     = "SELECT<br/>CHECK-IN DATE";
            CheckInDateLink.CssClass = "select-checkin-date";
            ScriptManager.RegisterStartupScript(CheckInDateChangePanel, CheckInDateChangePanel.GetType(), "ConfirmUpdate", "$(function(){$('#updateSuccess').modal('show');});", true);
        }
        private void CancelBookingClick(object sender, CommandEventArgs e)
        {
            var bookingId = int.Parse(e.CommandArgument.ToString());
            var bookings  = _bookingRepository.GetById(bookingId);
            var products  = _bookingRepository.ProductList.First(x => x.ProductId == bookings.ProductId);
            var hotels    = _bookingRepository.HotelList.First(x => x.HotelId == products.HotelId);
            var market    = (from mh in _bookingRepository.MarketHotelList
                             join m in _bookingRepository.MarketList on mh.MarketId equals m.Id
                             where mh.HotelId == hotels.HotelId
                             select m).FirstOrDefault();

            var dateNow  = DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(hotels.TimeZoneId).AddDays(2).AddHours(9);
            var bookDate = bookings.BookedDate.ToLosAngerlesTimeWithTimeZone(hotels.TimeZoneId).AddDays(14);

            if ((products.IsCheckedInRequired && bookings.CheckinDate <= dateNow) ||
                (!products.IsCheckedInRequired && bookDate.Date < DateTime.UtcNow.ToLosAngerlesTimeWithTimeZone(hotels.TimeZoneId).Date))
            {
                ClientScript.RegisterStartupScript(GetType(), "Cancel_Not_Available", "$(function(){$('#updateNotPossible').modal('show');});", true);
                return;
            }

            if (!string.IsNullOrEmpty(bookings.StripeChargeId))
            {
                MaintainOldInvoices(bookings);
            }

            var    logs      = new CustomerCreditLogs();
            double payByCard = bookings.TotalPrice - bookings.PayByCredit;

            if (bookings.PayByCredit > 0)
            {
                logs = new CustomerCreditLogs
                {
                    CustomerId  = bookings.CustomerId,
                    ProductId   = bookings.ProductId,
                    Description = string.Format("{0} – {1} – {2} – {3}",
                                                products.ProductName,
                                                hotels.HotelName,
                                                market != null ? market.LocationName : "",
                                                bookings.BookingIdString),
                    Amount      = Math.Abs(bookings.PayByCredit),
                    CreatedBy   = PublicCustomerInfos != null ? PublicCustomerInfos.CustomerId : 0,
                    CreatedDate = DateTime.UtcNow,
                    CreditType  = payByCard >= 0 ? (byte)Enums.CreditType.FullPurchaseRefund : (byte)Enums.CreditType.PartialPuchaseRefund,
                    ReferralId  = 0,
                    BookingId   = bookings.BookingId,
                    Status      = true,
                    GiftCardId  = 0
                };
                bookings.PaymentType        = (byte)Enums.PaymentType.DayAxeCredit;
                bookings.RefundCreditAmount = bookings.PayByCredit;
            }

            if (payByCard > 0)
            {
                Refund(bookings, PublicCustomerInfos, payByCard, bookings.MerchantPrice, bookings.HotelPrice);

                bookings.PaymentType = (byte)Enums.PaymentType.Stripe;
                var        cardService = new StripeCardService();
                StripeCard stripeCard  = cardService.Get(PublicCustomerInfos.StripeCustomerId, PublicCustomerInfos.StripeCardId);
                StripeCardString            = string.Format("{0} {1}", stripeCard.Brand, stripeCard.Last4);
                bookings.StripeRefundAmount = payByCard;
            }

            bookings.TotalRefundAmount = bookings.TotalPrice;
            bookings.StripeCardString  = StripeCardString;
            bookings.CancelDated       = DateTime.UtcNow;
            bookings.PassStatus        = (int)Enums.BookingStatus.Refunded;
            _bookingRepository.RefundBooking(bookings, logs);
            CacheLayer.Clear(CacheKeys.CustomerCreditsCacheKey);
            CacheLayer.Clear(CacheKeys.CustomerCreditLogsCacheKey);

            BindMyDayPassInfo();
        }
Beispiel #9
0
        public ActionResult UserProfile(bool passwordIfCorrect = true)
        {
            var serialization         = new Serialization();
            var userRegistration      = new UserRegistration();
            var HashCriteria          = new Hashtable();
            var actualCriteria        = string.Empty;
            var objUserProfileDetails = new List <UserProfileEditModel>();

            HashCriteria.Add("UserID", userID);
            actualCriteria = serialization.SerializeBinary((object)HashCriteria);
            var result = userRegistration.GetUserSpecificDetails(actualCriteria);

            objUserProfileDetails = (List <UserProfileEditModel>)(serialization.DeSerializeBinary(Convert.ToString(result)));
            var UserProfileDetails = objUserProfileDetails.FirstOrDefault();

            //UserProfileDetails.ProfileImage = CheckFileExists(UserProfileDetails.ProfileImage, "ProfileImagePath", Convert.ToString(UserProfileDetails.ID), "UserProfile");
            UserProfileDetails.ProfileImage      = CheckFileExistsGender(UserProfileDetails.ProfileImage, UserProfileDetails.Gender, "ProfileImagePath", Convert.ToString(UserProfileDetails.ID), "UserProfile");
            UserProfileDetails.SubscriptionModel = new SubscriptionModel();
            var subscriptionController = new SubscriptionController();

            UserProfileDetails.SubscriptionModel.CardType            = subscriptionController.GetPaymentCardType();
            UserProfileDetails.SubscriptionModel.ExpirationYearList  = subscriptionController.GetExpirationYear();
            UserProfileDetails.SubscriptionModel.ExpirationMonthList = subscriptionController.GetExpirationMonth();
            Session["ProfileImage"] = null;
            if (!passwordIfCorrect)
            {
                ViewBag.Error = "Please enter correct password";
            }
            else
            {
                //To get the customer credit card information for this user
                string customerID = UserProfileDetails.CustomerID;
                if (customerID != null && customerID != "")
                {
                    var            customerService = new StripeCustomerService();
                    StripeCustomer stripeCustomer  = customerService.Get(customerID);
                    var            cardService     = new StripeCardService();
                    StripeCard     stripeCard      = cardService.Get(customerID, stripeCustomer.DefaultSourceId); // optional isRecipient
                    foreach (var card in UserProfileDetails.SubscriptionModel.CardType)
                    {
                        //stripeCard.Brand = UserProfileDetails.SubscriptionModel.CardType[0].Name;
                        UserProfileDetails.SubscriptionModel.CardType[0].Name = stripeCard.Brand;
                        UserProfileDetails.SubscriptionModel.CardTypeID       = Convert.ToInt32(UserProfileDetails.SubscriptionModel.CardType[0].ID);
                    }
                    if (stripeCard.AddressCity != null)
                    {
                        UserProfileDetails.SubscriptionModel.BillingAddress = stripeCard.AddressCity;
                    }
                    UserProfileDetails.SubscriptionModel.ExpirationMonth = stripeCard.ExpirationMonth;
                    UserProfileDetails.SubscriptionModel.ExpirationYear  = stripeCard.ExpirationYear;
                    UserProfileDetails.SubscriptionModel.CardTypeID      = UserProfileDetails.SubscriptionModel.CardTypeID;
                    UserProfileDetails.SubscriptionModel.CardNumber      = "********" + stripeCard.Last4;
                    UserProfileDetails.SubscriptionModel.NameOnCard      = stripeCard.Name;
                    UserProfileDetails.SubscriptionModel.BillingAddress  = stripeCard.AddressLine1;
                    UserProfileDetails.SubscriptionModel.City            = stripeCard.AddressCity;
                    if (stripeCard.AddressState != null)
                    {
                        UserProfileDetails.SubscriptionModel.State = stripeCard.AddressState;
                    }
                    if (stripeCard.AddressZip != null)
                    {
                        UserProfileDetails.SubscriptionModel.Zip = stripeCard.AddressZip;
                    }
                }
            }
            return(View(UserProfileDetails));
        }