/// <summary> /// Handles the payment. /// </summary> /// <param name="umbracoContext">The umbraco context.</param> /// <param name="publishedContent">Content of the published.</param> /// <param name="viewModel">The view model.</param> /// <param name="currentUser">The current user.</param> /// <returns></returns> /// <inheritdoc /> public string MakePayment( UmbracoContext umbracoContext, IPublishedContent publishedContent, MakePaymentViewModel viewModel, string currentUser) { loggingService.Info(GetType()); PageModel pageModel = new PageModel(publishedContent); if (string.IsNullOrEmpty(pageModel.NextPageUrl)) { throw new ApplicationException("Next Page Url Not Set"); } if (string.IsNullOrEmpty(pageModel.ErrorPageUrl)) { throw new ApplicationException("Error Page Url Not Set"); } PaymentSettingsModel paymentSettingsModel = paymentProvider.GetPaymentSettingsModel(umbracoContext); if (paymentSettingsModel.Provider != Constants.PaymentProviders.Braintree) { //// we currently only support Braintree throw new ApplicationException("Unsupported Payment Provider"); } Result <Transaction> transaction = paymentProvider.MakePayment(paymentSettingsModel, viewModel); if (transaction != null) { //// at this point the payment has worked //// so need to be careful from here as to what we raise as errors etc. //// make sure we clear the cache! transactionsRepository.SetKey(umbracoContext); transactionsRepository.Clear(); string paymentId = transaction.Target.Id; loggingService.Info(GetType(), "Payment Succesful Id=" + paymentId); try { eventPublisher.Publish(new TransactionMadeMessage( umbracoContext, transaction.Target, viewModel, currentUser, pageModel.EmailTemplateName, paymentSettingsModel.Provider, paymentSettingsModel.Environment)); } catch (Exception exception) { loggingService.Error(GetType(), "Publish of payment Failed", exception); } return(pageModel.NextPageUrl); } loggingService.Info(GetType(), "Payment Failed"); return(pageModel.ErrorPageUrl); }