Esempio n. 1
0
        public ActionResult HandleDonationForm(DonationFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CurrentUmbracoPage());
            }


            string key = Guid.NewGuid().ToString();

            model.Amount = model.Amount * 100;
            Money money = new Money(model.Amount, Money.CurrencyEnum.USD);

            try
            {
                var            customerId     = CreateCustomer(model);
                ChargeRequest  body           = new ChargeRequest(key, money, model.Nonce, null, null, null, null, customerId);
                TransactionApi transactionApi = new TransactionApi();
                var            response       = transactionApi.Charge(squareAuthorization, squareLocationId, body);
                var            confirm        = response;
            }
            catch (Exception)
            {
                TempData["DonationError"] = true;
                return(RedirectToCurrentUmbracoPage());
            }

            TempData["DonationSuccessful"] = true;
            return(RedirectToCurrentUmbracoPage());
        }
Esempio n. 2
0
        public IActionResult Donate([FromServices] DonationFormModel vm)
        {
            vm.FillCategories(_donationsService.GetCategories());
            vm.FillInstitutions(_institutionsService.GetInstitutions());

            ViewBag.ShowFormSlogan = true;
            return(View(vm));
        }
Esempio n. 3
0
        public string CreateCustomer(DonationFormModel model)
        {
            Address address                   = new Address(model.StreetAddress1, model.StreetAddress2, null, model.City, null, null, null, model.State, null, null, model.ZipCode, null, model.FirstName, model.LastName, null);
            CreateCustomerRequest body        = new CreateCustomerRequest(model.FirstName, model.LastName, null, null, model.Email, address, model.Phone, null, null);
            CustomerApi           customerAPI = new CustomerApi();
            var response = customerAPI.CreateCustomer(squareAuthorization, body);

            return(response.Customer.Id);
        }
Esempio n. 4
0
        public IActionResult DonateExecute([FromForm] DonationFormModel vm)
        {
            var userId   = _userManager.GetUserId(User);
            var cats     = HttpContext.Request.Form["CategoriesString"];
            var catsInts = StringArrayToIntArray(cats);
            var date     = DateTime.Parse(vm.CollectionData.Date + "T" + vm.CollectionData.Time);

            _donationsService.AddDonation(userId, vm.SelectedInstitutionId, vm.CollectionData.Street, vm.CollectionData.City, vm.CollectionData.ZipCode, date, vm.CollectionData.Notes, vm.NumberOfBags, catsInts);

            ViewBag.ShowConfirmationSlogan = true;
            return(View());
        }