public async Task <string> PrepareOrderForUnAuthenticatedCustomer([FromBody] OrderViewModel orderDetails) { DateTime startTime = DateTime.Now; if (!ModelState.IsValid) { List <string> errorList = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); string errorMessage = JsonConvert.SerializeObject(errorList); throw new PartnerDomainException(ErrorCode.InvalidInput).AddDetail("ErrorMessage", errorMessage); } // Validate & Normalize the order information. OrderNormalizer orderNormalizer = new OrderNormalizer(ApplicationDomain.Instance, orderDetails); orderDetails = await orderNormalizer.NormalizePurchaseSubscriptionOrderAsync().ConfigureAwait(false); // prepare the redirect url so that client can redirect to PayPal. string redirectUrl = string.Format(CultureInfo.InvariantCulture, "{0}/#ProcessOrder?ret=true&customerId={1}", Request.RequestUri.GetLeftPart(UriPartial.Authority), orderDetails.CustomerId); // execute to paypal and get paypal action URI. IPaymentGateway paymentGateway = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, Resources.NewPurchaseOperationCaption); string generatedUri = await paymentGateway.GeneratePaymentUriAsync(redirectUrl, orderDetails).ConfigureAwait(false); // Track the event measurements for analysis. Dictionary <string, double> eventMetrics = new Dictionary <string, double> { { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds } }; ApplicationDomain.Instance.TelemetryService.Provider.TrackEvent("api/order/NewCustomerPrepareOrder", null, eventMetrics); return(generatedUri); }
/// <summary> /// Factory method to create the right payment gateway for this customer. /// </summary> /// <param name="operationDescription">The payment operation description.</param> /// <param name="customerId">The customer who is transacting.</param> /// <returns>The payment gateway instance.</returns> private static async Task <IPaymentGateway> CreatePaymentGateway(string operationDescription, string customerId) { operationDescription.AssertNotEmpty(nameof(operationDescription)); customerId.AssertNotEmpty(nameof(customerId)); bool isCustomerPreApproved = false; isCustomerPreApproved = await ApplicationDomain.Instance.PreApprovedCustomersRepository.IsCustomerPreApprovedAsync(customerId).ConfigureAwait(false); // if customer is preapproved then use PreApprovedGateway else use PayPalGateway. if (isCustomerPreApproved) { return(new PreApprovalGateway(ApplicationDomain.Instance, operationDescription)); } else { return(PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, operationDescription)); } }
public async Task <PaymentConfiguration> UpdatePaymentConfiguration(PaymentConfiguration paymentConfiguration) { IPaymentGateway paymentGateway = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, "configure payment"); //// validate the payment configuration before saving. paymentGateway.ValidateConfiguration(paymentConfiguration); // check if branding configuration has been setup else don't create web experience profile. bool isBrandingConfigured = await ApplicationDomain.Instance.PortalBranding.IsConfiguredAsync().ConfigureAwait(false); if (isBrandingConfigured) { // create a web experience profile using the branding for the web store. BrandingConfiguration brandConfig = await ApplicationDomain.Instance.PortalBranding.RetrieveAsync().ConfigureAwait(false); paymentConfiguration.WebExperienceProfileId = paymentGateway.CreateWebExperienceProfile(paymentConfiguration, brandConfig, ApplicationDomain.Instance.PortalLocalization.CountryIso2Code); } // Save the validated & complete payment configuration to repository. PaymentConfiguration paymentConfig = await ApplicationDomain.Instance.PaymentConfigurationRepository.UpdateAsync(paymentConfiguration).ConfigureAwait(false); return(paymentConfig); }
public async Task <BrandingConfiguration> UpdateBrandingConfiguration() { BrandingConfiguration brandingConfiguration = new BrandingConfiguration() { AgreementUserId = HttpContext.Current.Request.Form["AgreementUserId"], OrganizationName = HttpContext.Current.Request.Form["OrganizationName"], ContactUs = new ContactUsInformation() { Email = HttpContext.Current.Request.Form["ContactUsEmail"], Phone = HttpContext.Current.Request.Form["ContactUsPhone"], }, ContactSales = new ContactUsInformation() { Email = HttpContext.Current.Request.Form["ContactSalesEmail"], Phone = HttpContext.Current.Request.Form["ContactSalesPhone"], } }; string organizationLogo = HttpContext.Current.Request.Form["OrganizationLogo"]; HttpPostedFile organizationLogoPostedFile = HttpContext.Current.Request.Files["OrganizationLogoFile"]; if (organizationLogoPostedFile != null && Path.GetFileName(organizationLogoPostedFile.FileName) == organizationLogo) { // there is a new organization logo to be uploaded if (!organizationLogoPostedFile.ContentType.Trim().StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)) { throw new PartnerDomainException(ErrorCode.InvalidFileType, Resources.InvalidOrganizationLogoFileTypeMessage).AddDetail("Field", "OrganizationLogoFile"); } brandingConfiguration.OrganizationLogoContent = organizationLogoPostedFile.InputStream; } else if (!string.IsNullOrWhiteSpace(organizationLogo)) { try { // the user either did not specify a logo or he did but changed the organization logo text to point to somewhere else i.e. a URI brandingConfiguration.OrganizationLogo = new Uri(organizationLogo, UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidOrganizationLogoUriMessage, invalidUri).AddDetail("Field", "OrganizationLogo"); } } string headerImage = HttpContext.Current.Request.Form["HeaderImage"]; HttpPostedFile headerImageUploadPostedFile = HttpContext.Current.Request.Files["HeaderImageFile"]; if (headerImageUploadPostedFile != null && Path.GetFileName(headerImageUploadPostedFile.FileName) == headerImage) { // there is a new header image to be uploaded if (!headerImageUploadPostedFile.ContentType.Trim().StartsWith("image/", StringComparison.InvariantCultureIgnoreCase)) { throw new PartnerDomainException(ErrorCode.InvalidFileType, Resources.InvalidHeaderImageMessage).AddDetail("Field", "HeaderImageFile"); } brandingConfiguration.HeaderImageContent = headerImageUploadPostedFile.InputStream; } else if (!string.IsNullOrWhiteSpace(headerImage)) { try { // the user either did not specify a header image or he did but changed the organization logo text to point to somewhere else i.e. a URI brandingConfiguration.HeaderImage = new Uri(headerImage, UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidHeaderImageUriMessage, invalidUri).AddDetail("Field", "HeaderImage"); } } if (!string.IsNullOrWhiteSpace(HttpContext.Current.Request.Form["PrivacyAgreement"])) { try { brandingConfiguration.PrivacyAgreement = new Uri(HttpContext.Current.Request.Form["PrivacyAgreement"], UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidPrivacyUriMessage, invalidUri).AddDetail("Field", "PrivacyAgreement"); } } if (!string.IsNullOrWhiteSpace(HttpContext.Current.Request.Form["InstrumentationKey"])) { brandingConfiguration.InstrumentationKey = HttpContext.Current.Request.Form["InstrumentationKey"]; } BrandingConfiguration updatedBrandingConfiguration = await ApplicationDomain.Instance.PortalBranding.UpdateAsync(brandingConfiguration).ConfigureAwait(false); bool isPaymentConfigurationSetup = await ApplicationDomain.Instance.PaymentConfigurationRepository.IsConfiguredAsync().ConfigureAwait(false); if (isPaymentConfigurationSetup) { // update the web experience profile. PaymentConfiguration paymentConfiguration = await ApplicationDomain.Instance.PaymentConfigurationRepository.RetrieveAsync().ConfigureAwait(false); paymentConfiguration.WebExperienceProfileId = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, "retrieve payment").CreateWebExperienceProfile(paymentConfiguration, updatedBrandingConfiguration, ApplicationDomain.Instance.PortalLocalization.CountryIso2Code); await ApplicationDomain.Instance.PaymentConfigurationRepository.UpdateAsync(paymentConfiguration).ConfigureAwait(false); } return(updatedBrandingConfiguration); }
public ActionResult PaymentSetup() { return(this.PartialView(PaymentGatewayConfig.GetPaymentConfigView())); }
public async Task <SubscriptionsSummary> ProcessOrderForUnAuthenticatedCustomer(string customerId, string paymentId, string payerId) { DateTime startTime = DateTime.Now; customerId.AssertNotEmpty(nameof(customerId)); paymentId.AssertNotEmpty(nameof(paymentId)); payerId.AssertNotEmpty(nameof(payerId)); BrandingConfiguration branding = await ApplicationDomain.Instance.PortalBranding.RetrieveAsync().ConfigureAwait(false); CustomerViewModel customerRegistrationInfoPersisted = await ApplicationDomain.Instance.CustomerRegistrationRepository.RetrieveAsync(customerId).ConfigureAwait(false); Customer newCustomer = new Customer() { CompanyProfile = new CustomerCompanyProfile() { Domain = customerRegistrationInfoPersisted.DomainName, }, BillingProfile = new CustomerBillingProfile() { Culture = customerRegistrationInfoPersisted.BillingCulture, Language = customerRegistrationInfoPersisted.BillingLanguage, Email = customerRegistrationInfoPersisted.Email, CompanyName = customerRegistrationInfoPersisted.CompanyName, DefaultAddress = new Address() { FirstName = customerRegistrationInfoPersisted.FirstName, LastName = customerRegistrationInfoPersisted.LastName, AddressLine1 = customerRegistrationInfoPersisted.AddressLine1, AddressLine2 = customerRegistrationInfoPersisted.AddressLine2, City = customerRegistrationInfoPersisted.City, State = customerRegistrationInfoPersisted.State, Country = customerRegistrationInfoPersisted.Country, PostalCode = customerRegistrationInfoPersisted.ZipCode, PhoneNumber = customerRegistrationInfoPersisted.Phone, } } }; // Register customer newCustomer = await ApplicationDomain.Instance.PartnerCenterClient.Customers.CreateAsync(newCustomer).ConfigureAwait(false); ResourceCollection <AgreementMetaData> agreements = await ApplicationDomain.Instance.PartnerCenterClient.AgreementDetails.GetAsync().ConfigureAwait(false); // Obtain reference to the Microsoft Cloud Agreement. AgreementMetaData microsoftCloudAgreement = agreements.Items.FirstOrDefault(agr => agr.AgreementType == AgreementType.MicrosoftCloudAgreement); // Attest that the customer has accepted the Microsoft Cloud Agreement (MCA). await ApplicationDomain.Instance.PartnerCenterClient.Customers[newCustomer.Id].Agreements.CreateAsync( new Agreement { DateAgreed = DateTime.UtcNow, PrimaryContact = new PartnerCenter.Models.Agreements.Contact { Email = customerRegistrationInfoPersisted.Email, FirstName = customerRegistrationInfoPersisted.FirstName, LastName = customerRegistrationInfoPersisted.LastName, PhoneNumber = customerRegistrationInfoPersisted.Phone }, TemplateId = microsoftCloudAgreement.TemplateId, Type = AgreementType.MicrosoftCloudAgreement, UserId = branding.AgreementUserId }); string newCustomerId = newCustomer.CompanyProfile.TenantId; CustomerViewModel customerViewModel = new CustomerViewModel() { AddressLine1 = newCustomer.BillingProfile.DefaultAddress.AddressLine1, AddressLine2 = newCustomer.BillingProfile.DefaultAddress.AddressLine2, City = newCustomer.BillingProfile.DefaultAddress.City, State = newCustomer.BillingProfile.DefaultAddress.State, ZipCode = newCustomer.BillingProfile.DefaultAddress.PostalCode, Country = newCustomer.BillingProfile.DefaultAddress.Country, Phone = newCustomer.BillingProfile.DefaultAddress.PhoneNumber, Language = newCustomer.BillingProfile.Language, FirstName = newCustomer.BillingProfile.DefaultAddress.FirstName, LastName = newCustomer.BillingProfile.DefaultAddress.LastName, Email = newCustomer.BillingProfile.Email, CompanyName = newCustomer.BillingProfile.CompanyName, MicrosoftId = newCustomer.CompanyProfile.TenantId, UserName = newCustomer.BillingProfile.Email, Password = newCustomer.UserCredentials.Password, AdminUserAccount = newCustomer.UserCredentials.UserName + "@" + newCustomer.CompanyProfile.Domain }; IPaymentGateway paymentGateway = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, "ProcessingOrder"); OrderViewModel orderToProcess = await paymentGateway.GetOrderDetailsFromPaymentAsync(payerId, paymentId, string.Empty, string.Empty).ConfigureAwait(false); // Assign the actual customer Id orderToProcess.CustomerId = newCustomerId; CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, newCustomerId, paymentGateway); await commerceOperation.PurchaseAsync(orderToProcess).ConfigureAwait(false); SubscriptionsSummary summaryResult = await GetSubscriptionSummaryAsync(newCustomerId).ConfigureAwait(false); // Remove the persisted customer registration info. await ApplicationDomain.Instance.CustomerRegistrationRepository.DeleteAsync(customerId).ConfigureAwait(false); // Capture the request for the customer summary for analysis. Dictionary <string, string> eventProperties = new Dictionary <string, string> { { "CustomerId", orderToProcess.CustomerId } }; // Track the event measurements for analysis. Dictionary <string, double> eventMetrics = new Dictionary <string, double> { { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds } }; ApplicationDomain.Instance.TelemetryService.Provider.TrackEvent("api/order/NewCustomerProcessOrder", eventProperties, eventMetrics); summaryResult.CustomerViewModel = customerViewModel; return(summaryResult); }
public CallbackController(ILogger <CallbackController> logger, IPaymentTransactionService paymentsService, PaymentGatewayConfig config) { this.logger = logger; this.paymentService = paymentsService; this.config = config; }
public async Task <SubscriptionsSummary> ProcessOrderForUnAuthenticatedCustomer(string customerId, string paymentId, string payerId) { var startTime = DateTime.Now; customerId.AssertNotEmpty(nameof(customerId)); paymentId.AssertNotEmpty(nameof(paymentId)); payerId.AssertNotEmpty(nameof(payerId)); // Retrieve customer registration details persisted CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance); CustomerViewModel customerRegistrationInfoPersisted = await ApplicationDomain.Instance.CustomerRegistrationRepository.RetrieveAsync(customerId); var newCustomer = new Customer() { CompanyProfile = new CustomerCompanyProfile() { Domain = customerRegistrationInfoPersisted.DomainName, }, BillingProfile = new CustomerBillingProfile() { Culture = customerRegistrationInfoPersisted.BillingCulture, Language = customerRegistrationInfoPersisted.BillingLanguage, Email = customerRegistrationInfoPersisted.Email, CompanyName = customerRegistrationInfoPersisted.CompanyName, DefaultAddress = new Address() { FirstName = customerRegistrationInfoPersisted.FirstName, LastName = customerRegistrationInfoPersisted.LastName, AddressLine1 = customerRegistrationInfoPersisted.AddressLine1, AddressLine2 = customerRegistrationInfoPersisted.AddressLine2, City = customerRegistrationInfoPersisted.City, State = customerRegistrationInfoPersisted.State, Country = customerRegistrationInfoPersisted.Country, PostalCode = customerRegistrationInfoPersisted.ZipCode, PhoneNumber = customerRegistrationInfoPersisted.Phone, } } }; // Register customer newCustomer = await ApplicationDomain.Instance.PartnerCenterClient.Customers.CreateAsync(newCustomer); var newCustomerId = newCustomer.CompanyProfile.TenantId; CustomerViewModel customerViewModel = new CustomerViewModel() { AddressLine1 = newCustomer.BillingProfile.DefaultAddress.AddressLine1, AddressLine2 = newCustomer.BillingProfile.DefaultAddress.AddressLine2, City = newCustomer.BillingProfile.DefaultAddress.City, State = newCustomer.BillingProfile.DefaultAddress.State, ZipCode = newCustomer.BillingProfile.DefaultAddress.PostalCode, Country = newCustomer.BillingProfile.DefaultAddress.Country, Phone = newCustomer.BillingProfile.DefaultAddress.PhoneNumber, Language = newCustomer.BillingProfile.Language, FirstName = newCustomer.BillingProfile.DefaultAddress.FirstName, LastName = newCustomer.BillingProfile.DefaultAddress.LastName, Email = newCustomer.BillingProfile.Email, CompanyName = newCustomer.BillingProfile.CompanyName, MicrosoftId = newCustomer.CompanyProfile.TenantId, UserName = newCustomer.BillingProfile.Email, Password = newCustomer.UserCredentials.Password, AdminUserAccount = newCustomer.UserCredentials.UserName + "@" + newCustomer.CompanyProfile.Domain }; IPaymentGateway paymentGateway = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, "ProcessingOrder"); OrderViewModel orderToProcess = await paymentGateway.GetOrderDetailsFromPaymentAsync(payerId, paymentId, string.Empty, string.Empty); // Assign the actual customer Id orderToProcess.CustomerId = newCustomerId; CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, newCustomerId, paymentGateway); await commerceOperation.PurchaseAsync(orderToProcess); SubscriptionsSummary summaryResult = await this.GetSubscriptionSummaryAsync(newCustomerId); // Remove the persisted customer registration info. var deleteResult = ApplicationDomain.Instance.CustomerRegistrationRepository.DeleteAsync(customerId); // Capture the request for the customer summary for analysis. var eventProperties = new Dictionary <string, string> { { "CustomerId", orderToProcess.CustomerId } }; // Track the event measurements for analysis. var eventMetrics = new Dictionary <string, double> { { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds } }; ApplicationDomain.Instance.TelemetryService.Provider.TrackEvent("api/order/NewCustomerProcessOrder", eventProperties, eventMetrics); summaryResult.CustomerViewModel = customerViewModel; return(summaryResult); }