Ejemplo n.º 1
0
        public ActionResult SetupPaymentPlan(string paymentCustomerId, string customerId)
        {
            var viewModel = new PlanSetupModel
            {
                StripePlanList = GetPlans(),
                YearsList      = GetYears(),
                MonthsList     = GetMonths(),

                PaymentCustomerId = paymentCustomerId,
                CustomerId        = customerId
            };

            return(PartialView("Partials/_SetupPlan", viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult SetupPaymentPlan(PlanSetupModel planModel)
        {
            planModel.StripePlanList = GetPlans();
            planModel.YearsList      = GetYears();
            planModel.MonthsList     = GetMonths();

            if (ModelState.IsValid)
            {
                SetupPaymentPlanReponse reponse = _customerService.SetupPaymentPlan(planModel);

                if (reponse.HasError && reponse.ErrorCode == ErrorCode.StripeSetupError)
                {
                    LoggingFactory.GetLogger()
                    .Log("Stripe Error - Error is thrown during setting plan and payment.", EventLogSeverity.Error);

                    return(RedirectToAction("payments", "customers", new { id = planModel.CustomerId })
                           .AndAlert(AlertType.Danger, "Stripe error.", "Error is thrown during setting plan and payment."));
                }
                else if (!reponse.IsStatusActive)
                {
                    LoggingFactory.GetLogger()
                    .Log("Stripe Error - Setting plan and payment result is not correct.", EventLogSeverity.Error);

                    return(RedirectToAction("payments", "customers", new { id = planModel.CustomerId })
                           .AndAlert(AlertType.Danger, "Stripe error.", "Setting plan and payment result is not correct."));
                }
                else if (reponse.HasPlan && reponse.Status.ToLower() == "active")
                {
                    LoggingFactory.GetLogger()
                    .Log("Stripe Error - Previous plan wasn't closed.", EventLogSeverity.Error);

                    return(RedirectToAction("payments", "customers", new { id = Guid.Parse(planModel.CustomerId) })
                           .AndAlert(AlertType.Danger, "Stripe error.", "Previous plan wasn't closed."));
                }

                return(RedirectToAction("payments", "customers", new { id = planModel.CustomerId })
                       .AndAlert(AlertType.Success, "Stripe payment.", "Stripe plan and payment were created sucessfully."));
            }

            return(RedirectToAction("payments", "customers", new { id = planModel.CustomerId })
                   .AndAlert(AlertType.Danger, "Error.", "Provided data is incorrect."));
        }
Ejemplo n.º 3
0
        public SetupPaymentPlanReponse SetupPaymentPlan(PlanSetupModel planModel)
        {
            var response = new SetupPaymentPlanReponse();

            try
            {
                Customer customer = _customerRepository.Get(Guid.Parse(planModel.CustomerId));
                if (customer == null)
                {
                    throw new Exception("Incorrect Customer identifier");
                }

                if (customer.Plan != null)
                {
                    response.HasPlan = true;
                    var status = StripeFactory.GetStripeService().CloseCustomerPlan(customer.PaymentCustomerId);
                    response.Status = status;

                    //return response;
                }

                Plan dbPlan =
                    _planRepository.Query().FirstOrDefault(p => p.PlanCode.ToLower() == planModel.StripePlanId.ToLower());
                if (dbPlan == null)
                {
                    throw new Exception("Incorrect plan identifier");
                }

                var result = StripeFactory.GetStripeService().AssignCustomerPlan(
                    planModel.PaymentCustomerId, planModel.StripePlanId, planModel.CreditCardNumber,
                    planModel.Cvc, planModel.CardExpirationMonth, planModel.CardExpirationYear);

                if (result != "active")
                {
                    response.IsStatusActive = false;
                    return(response);
                }
                else
                {
                    //dbPlan.Customers.
                    response.IsStatusActive = true;
                }

                customer.UpdatePlan(dbPlan);
                _unitOfWork.Commit();

                return(response);
            }
            catch (StripeException ex)
            {
                LoggingFactory.GetLogger().LogError(ex);
                response.HasError  = true;
                response.ErrorCode = ErrorCode.StripeSetupError;
                response.Message   = ex.Message;
            }
            catch (Exception ex)
            {
                LoggingFactory.GetLogger().LogError(ex);
                response.HasError  = true;
                response.ErrorCode = ErrorCode.StripeSetupError;
                response.Message   = ErrorCode.StripeSetupError.ToString();
            }
            return(response);
        }