public ActionResult PaymentAccept(CheckBoxValue useDiscount, Guid?couponId, CreditCard creditCard, CheckBoxValue authoriseCreditCard) { var coupon = GetCoupon(couponId); var order = PrepareOrder(Pageflow.ContactProductId, coupon, useDiscount != null && useDiscount.IsChecked, creditCard); try { // Validate the coupon first. ValidateCoupon(Pageflow.ContactProductId, couponId, coupon); // Check that the terms have been accepted but process the other fields as well. if (!authoriseCreditCard.IsChecked) { ModelState.AddModelError(new[] { new CreditCardAuthorisationValidationError("authoriseCreditCard") }, new NewOrderErrorHandler()); } // Validate the coupon. if (couponId != null && coupon == null) { ModelState.AddModelError(new[] { new NotFoundValidationError("coupon", couponId) }, new NewOrderErrorHandler()); } // Validate the credit card. creditCard.Validate(); if (authoriseCreditCard.IsChecked && (couponId == null || coupon != null)) { // Create the user if needed. var employer = CurrentEmployer ?? CreateEmployer(); // Purchase the order. _employerOrdersCommand.PurchaseOrder(employer.Id, order, CreatePurchaser(employer), creditCard); // Save the data. Pageflow.UseDiscount = useDiscount != null && useDiscount.IsChecked; Pageflow.CreditCard = creditCard; Pageflow.AuthoriseCreditCard = true; Pageflow.OrderId = order.Id; // Go to the next page. return(Next()); } } catch (UserException ex) { ModelState.AddModelError(ex, new NewOrderErrorHandler()); } // Show the user the errors. return(PaymentView(Pageflow.ContactProductId, order, Pageflow.CouponCode, useDiscount != null && useDiscount.IsChecked, creditCard, authoriseCreditCard != null && authoriseCreditCard.IsChecked)); }
public ActionResult PaymentPurchase(Guid jobAdId, JobAdFeaturePack featurePack, Guid?couponId, CreditCard creditCard, CheckBoxValue authoriseCreditCard) { var employer = CurrentEmployer; var jobAd = GetJobAd(employer.Id, jobAdId); if (jobAd == null) { return(NotFound("job ad", "id", jobAdId)); } var product = _employerOrdersQuery.GetJobAdFeaturePackProduct(featurePack); if (product == null) { return(NotFound("feature pack", "featurePack", featurePack)); } var coupon = GetCoupon(couponId); var order = _employerOrdersCommand.PrepareOrder(new[] { product.Id }, coupon, null, GetCreditCardType(creditCard)); try { // Validate the coupon first. ValidateCoupon(product.Id, couponId, coupon); // Check that the terms have been accepted but process the other fields as well. if (!authoriseCreditCard.IsChecked) { ModelState.AddModelError(new[] { new CreditCardAuthorisationValidationError("authoriseCreditCard") }, new NewOrderErrorHandler()); } // Validate the coupon. if (couponId != null && coupon == null) { ModelState.AddModelError(new[] { new NotFoundValidationError("coupon", couponId) }, new NewOrderErrorHandler()); } // Validate the credit card. creditCard.Validate(); if (authoriseCreditCard.IsChecked && (couponId == null || coupon != null)) { // Purchase the order. _employerOrdersCommand.PurchaseOrder(employer.Id, order, CreatePurchaser(employer), creditCard); // Publish the job ad with the appropriate features. jobAd.Features = _employerOrdersQuery.GetJobAdFeatures(featurePack); jobAd.FeatureBoost = _employerOrdersQuery.GetJobAdFeatureBoost(featurePack); _employerJobAdsCommand.UpdateJobAd(employer, jobAd); return(Publish(employer, jobAd, order.Id)); } } catch (UserException ex) { ModelState.AddModelError(ex, new NewOrderErrorHandler()); } // Show the user the errors. return(View(new PaymentJobAdModel { AuthoriseCreditCard = authoriseCreditCard != null && authoriseCreditCard.IsChecked, CouponCode = coupon == null ? null : coupon.Code, CreditCard = creditCard, OrderDetails = _employerOrdersQuery.GetOrderDetails(_creditsQuery, order, _productsQuery.GetProducts()), Product = product, })); }