Ejemplo n.º 1
0
        public ActionResult Index()
        {
            var model = new PaymentModel();

            var    member = _memberProvider.GetLoggedInMember();
            string state  = Request.QueryString["state"];
            bool   canProcessPaymentCompletion = _sessionProvider.CanProcessPaymentCompletion;

            if (member == null || !canProcessPaymentCompletion || string.IsNullOrEmpty(state))
            {
                model.HasPaymentDetails = false;
                return(View(model));
            }

            var    paymentState         = (PaymentStates)Enum.Parse(typeof(PaymentStates), state);
            string mandateId            = member.GetValue <string>(MemberProperty.directDebitMandateId);
            bool   requiresFlowRedirect = string.IsNullOrWhiteSpace(_sessionProvider.GoCardlessRedirectFlowId) == false;

            if (requiresFlowRedirect)
            {
                mandateId = _goCardlessProvider.CompleteRedirectRequest(_sessionProvider.GoCardlessRedirectFlowId, _sessionProvider.SessionId);
                member.SetValue(MemberProperty.directDebitMandateId, mandateId);
                _memberService.Save(member);
                _sessionProvider.GoCardlessRedirectFlowId = null;
            }
            else if (string.IsNullOrEmpty(mandateId))
            {
                return(RedirectToMandatePage(paymentState));
            }

            MapPaymentStateToModel(model, member, paymentState);

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult ConfirmPayment(RegistrationCompleteModel model)
        {
            model.PromptForConfirmation = false;
            RegistrationDetails registrationDetails = _sessionProvider.RegistrationDetails;

            if (registrationDetails == null || string.IsNullOrWhiteSpace(_sessionProvider.GoCardlessRedirectFlowId))
            {
                TempData["Model"] = model;
                return(CurrentUmbracoPage());
            }

            string mandateId = _goCardlessProvider.CompleteRedirectRequest(_sessionProvider.GoCardlessRedirectFlowId, _sessionProvider.SessionId);

            registrationDetails.PersonalDetails.DirectDebitMandateId = mandateId;

            var regDetails  = registrationDetails.PersonalDetails;
            int costInPence = _membershipCostCalculator.Calculate(registrationDetails.MemberOptions, DateTime.Now);

            model.Cost = (costInPence / 100m).ToString("N2");
            var paymentDescription = MemberProvider.GetPaymentDescription(registrationDetails.MemberOptions);
            var paymentResponse    = _goCardlessProvider.CreatePayment(Logger, regDetails.DirectDebitMandateId, regDetails.Email, costInPence, paymentDescription);

            model.IsRegistered = paymentResponse == PaymentResponseDto.Success;

            if (model.IsRegistered)
            {
                var member = _memberProvider.CreateMember(regDetails, new string[] { MSTCRoles.Member });
                _memberProvider.UpdateMemberDetails(member, registrationDetails.PersonalDetails, registrationDetails.MemberOptions);

                //Login the member
                FormsAuthentication.SetAuthCookie(member.Username, true);

                string content = GetRegEmailContent(registrationDetails, true);
                _emailProvider.SendEmail(EmailProvider.MembersEmail, EmailProvider.SupportEmail,
                                         "New MSTC member registration", content);

                _sessionProvider.RegistrationDetails      = null;
                _sessionProvider.GoCardlessRedirectFlowId = null;
                TempData["Model"] = model;
                return(CurrentUmbracoPage());
            }
            else
            {
                string content = GetRegEmailContent(registrationDetails, false);
                _emailProvider.SendEmail(EmailProvider.SupportEmail, EmailProvider.SupportEmail,
                                         "MSTC member registration problem", content);
            }

            TempData["Model"] = model;
            return(CurrentUmbracoPage());
        }