private async Task CreateOnlyOnceAnonBuyerConfig(EnvironmentSeed seed, string token) { // validate AnonymousShoppingBuyerID or provide fallback if none is defined var allBuyers = await _oc.Buyers.ListAllAsync(accessToken : token); if (seed.AnonymousShoppingBuyerID != null) { if (!allBuyers.Select(b => b.ID).Contains(seed.AnonymousShoppingBuyerID)) { throw new Exception("The buyer defined by AnonymousShoppingBuyerID does not exist"); } } else { seed.AnonymousShoppingBuyerID = SeedConstants.DefaultBuyerID; } //create and assign initial buyer location await _buyerLocationCommand.Save(seed.AnonymousShoppingBuyerID, $"{seed.AnonymousShoppingBuyerID}-{SeedConstants.DefaultLocationID}", SeedConstants.DefaultBuyerLocation(), token, _oc); // create user var anonBuyerUser = await _oc.Users.SaveAsync(seed.AnonymousShoppingBuyerID, SeedConstants.AnonymousBuyerUser().ID, SeedConstants.AnonymousBuyerUser(), token); // save assignment between user and buyergroup (location) var assignment = new UserGroupAssignment() { UserGroupID = $"{seed.AnonymousShoppingBuyerID}-{SeedConstants.DefaultLocationID}", UserID = anonBuyerUser.ID }; await _oc.UserGroups.SaveUserAssignmentAsync(seed.AnonymousShoppingBuyerID, assignment, accessToken : token); }
private async Task CreateBuyers(EnvironmentSeed seed, string token) { var defaultBuyer = SeedConstants.DefaultBuyer(); seed.Buyers.Add(defaultBuyer); foreach (var buyer in seed.Buyers) { var superBuyer = new SuperHSBuyer() { Buyer = buyer, Markup = new BuyerMarkup() { Percent = 0 } }; var exists = await BuyerExistsAsync(buyer.Name, token); if (exists == null || exists.Count == 0) { var createdBuyer = await _buyerCommand.Create(superBuyer, token, _oc); if (createdBuyer.Buyer.Name == defaultBuyer.Name && seed.AnonymousShoppingBuyerID == null) { seed.AnonymousShoppingBuyerID = createdBuyer.Buyer.ID; } } else { seed.AnonymousShoppingBuyerID = exists.FirstOrDefault().ID; } } }
private async Task CreateOnlyOnceApiClients(EnvironmentSeed seed, string token) { var existingClients = await _oc.ApiClients.ListAllAsync(accessToken : token); await CreateOrGetBuyerClient(existingClients, SeedConstants.BuyerClient(seed), seed, token); await CreateOrGetApiClient(existingClients, SeedConstants.IntegrationsClient(), token); await CreateOrGetApiClient(existingClients, SeedConstants.SellerClient(), token); await CreateOrGetApiClient(existingClients, SeedConstants.BuyerLocalClient(seed), token); }
private async Task CreateApiClients(string token) { var existingClients = await _oc.ApiClients.ListAllAsync(accessToken : token); var integrationsClientRequest = GetClientRequest(existingClients, SeedConstants.IntegrationsClient(), token); var sellerClientRequest = GetClientRequest(existingClients, SeedConstants.SellerClient(), token); var buyerClientRequest = GetClientRequest(existingClients, SeedConstants.BuyerClient(), token); var buyerLocalClientRequest = GetClientRequest(existingClients, SeedConstants.BuyerLocalClient(), token); await Task.WhenAll(integrationsClientRequest, sellerClientRequest, buyerClientRequest, buyerLocalClientRequest); }
private async Task CreateAndAssignIntegrationEvents(string[] buyerClientIDs, string localBuyerClientID, string token) { var checkoutEvent = SeedConstants.CheckoutEvent(_settings); await _oc.IntegrationEvents.SaveAsync(checkoutEvent.ID, checkoutEvent, token); var localCheckoutEvent = SeedConstants.LocalCheckoutEvent(_settings); await _oc.IntegrationEvents.SaveAsync(localCheckoutEvent.ID, localCheckoutEvent, token); await _oc.ApiClients.PatchAsync(localBuyerClientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckoutLOCAL" }, token); await Throttler.RunAsync(buyerClientIDs, 500, 20, clientID => _oc.ApiClients.PatchAsync(clientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckout" }, token)); }
private async Task CreateMessageSenders(EnvironmentSeed seed, string accessToken) { var defaultMessageSenders = new List <MessageSender>() { SeedConstants.BuyerEmails(_settings), SeedConstants.SellerEmails(_settings), SeedConstants.SuplierEmails(_settings) }; foreach (var sender in defaultMessageSenders) { var messageSender = await _oc.MessageSenders.SaveAsync(sender.ID, sender, accessToken); if (messageSender.ID == "BuyerEmails") { foreach (var buyer in seed.Buyers) { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, BuyerID = buyer.ID }, accessToken); } } else if (messageSender.ID == "SellerEmails") { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID }, accessToken); } catch (Exception ex) { } } else if (messageSender.ID == "SupplierEmails") { foreach (var supplier in seed.Suppliers) { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, SupplierID = supplier.ID }, accessToken); } } } }
private async Task CreateAndAssignIntegrationEvents(string[] buyerClientIDs, string localBuyerClientID, string token, EnvironmentSeed seed = null) { var middlewareBaseUrl = seed != null ? seed.MiddlewareBaseUrl : _settings.EnvironmentSettings.MiddlewareBaseUrl; var webhookHashKey = seed != null ? seed.OrderCloudSettings.WebhookHashKey : _settings.OrderCloudSettings.WebhookHashKey; var checkoutEvent = SeedConstants.CheckoutEvent(middlewareBaseUrl, webhookHashKey); await _oc.IntegrationEvents.SaveAsync(checkoutEvent.ID, checkoutEvent, token); var localCheckoutEvent = SeedConstants.LocalCheckoutEvent(webhookHashKey); await _oc.IntegrationEvents.SaveAsync(localCheckoutEvent.ID, localCheckoutEvent, token); await _oc.ApiClients.PatchAsync(localBuyerClientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckoutLOCAL" }, token); await Throttler.RunAsync(buyerClientIDs, 500, 20, clientID => _oc.ApiClients.PatchAsync(clientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckout" }, token)); }
private async Task CreateDefaultSellerUsers(EnvironmentSeed seed, string token) { // the middleware api client will use this user as the default context user var middlewareIntegrationsUser = SeedConstants.MIddlewareIntegrationsUser(); await _oc.AdminUsers.SaveAsync(middlewareIntegrationsUser.ID, middlewareIntegrationsUser, token); // used to log in immediately after seeding the organization var initialAdminUser = new User { ID = "InitialAdminUser", Username = seed.InitialAdminUsername, Password = seed.InitialAdminPassword, Email = "*****@*****.**", Active = true, FirstName = "Initial", LastName = "User" }; await _oc.AdminUsers.SaveAsync(initialAdminUser.ID, initialAdminUser, token); }
private async Task CreateConfigureAnonBuyer(EnvironmentSeed seed, string token) { var anonBuyer = SeedConstants.AnonymousBuyerUser(); var defaultBuyer = SeedConstants.DefaultBuyer(); //create anonymous buyer user var createUser = _oc.Users.SaveAsync(seed.AnonymousShoppingBuyerID, anonBuyer.ID, anonBuyer, token); //create and assign initial buyer location var createBuyerLocation = _buyerLocationCommand.Save(seed.AnonymousShoppingBuyerID, $"{seed.AnonymousShoppingBuyerID}-{SeedConstants.DefaultLocationID}", SeedConstants.DefaultBuyerLocation(), token, true); var assignment = new UserGroupAssignment() { UserGroupID = $"{seed.AnonymousShoppingBuyerID}-{SeedConstants.DefaultLocationID}", UserID = anonBuyer.ID }; var saveAssignment = _oc.UserGroups.SaveUserAssignmentAsync(seed.AnonymousShoppingBuyerID, assignment, token); await Task.WhenAll(createUser, createBuyerLocation, saveAssignment); }
private async Task CreateOnlyOnceBuyers(EnvironmentSeed seed, string token) { // create default buyer if it does not exist // default buyer will have a well-known ID we can use to query with var defaultBuyer = await GetBuyerByID(SeedConstants.DefaultBuyerID, token); if (defaultBuyer == null) { var superBuyer = new SuperHSBuyer() { Buyer = SeedConstants.DefaultBuyer(), Markup = new BuyerMarkup() { Percent = 0 } }; await _buyerCommand.Create(superBuyer, token, _oc); } // create seed buyers if they don't exist // seed buyers may not have ID defined, we are relying on Name instead foreach (var buyer in seed.Buyers) { var seedBuyer = await GetBuyerByName(buyer.Name, token); if (seedBuyer == null) { var superBuyer = new SuperHSBuyer() { Buyer = buyer, Markup = new BuyerMarkup() { Percent = 0 } }; await _buyerCommand.Create(superBuyer, token, _oc); } } }
private async Task CreateOrUpdateAndAssignIntegrationEvents(string token, EnvironmentSeed seed = null) { var storefrontApiClientIDs = await GetStoreFrontClientIDs(token); var apiClients = await GetApiClients(token); var localBuyerClientID = apiClients.BuyerLocalUiApiClient.ID; // this gets called by both the /seed command and the post-staging restore so we need to handle getting settings from two sources var middlewareBaseUrl = seed != null ? seed.MiddlewareBaseUrl : _settings.EnvironmentSettings.MiddlewareBaseUrl; var webhookHashKey = seed != null ? seed.OrderCloudSettings.WebhookHashKey : _settings.OrderCloudSettings.WebhookHashKey; var checkoutEvent = SeedConstants.CheckoutEvent(middlewareBaseUrl, webhookHashKey); await _oc.IntegrationEvents.SaveAsync(checkoutEvent.ID, checkoutEvent, token); var localCheckoutEvent = SeedConstants.LocalCheckoutEvent(webhookHashKey); await _oc.IntegrationEvents.SaveAsync(localCheckoutEvent.ID, localCheckoutEvent, token); await _oc.ApiClients.PatchAsync(localBuyerClientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckoutLOCAL" }, token); await Throttler.RunAsync(storefrontApiClientIDs, 500, 20, clientID => _oc.ApiClients.PatchAsync(clientID, new PartialApiClient { OrderCheckoutIntegrationEventID = "HeadStartCheckout" }, token)); }
private async Task CreateMessageSenders(EnvironmentSeed seed, string accessToken) { var defaultMessageSenders = new List <MessageSender>() { SeedConstants.BuyerEmails(seed), SeedConstants.SellerEmails(seed), SeedConstants.SuplierEmails(seed) }; foreach (var sender in defaultMessageSenders) { var messageSender = await _oc.MessageSenders.SaveAsync(sender.ID, sender, accessToken); if (messageSender.ID == "BuyerEmails") { foreach (var buyer in seed.Buyers) { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, BuyerID = buyer.ID }, accessToken); } catch (OrderCloudException ex) { if (ex.HttpStatus != HttpStatusCode.Conflict) // this is a bug in the api https://four51.atlassian.net/browse/EX-2210 { throw ex; } } } } else if (messageSender.ID == "SellerEmails") { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID }, accessToken); } catch (OrderCloudException ex) { if (ex.HttpStatus != HttpStatusCode.Conflict) // this is a bug in the api https://four51.atlassian.net/browse/EX-2210 { throw ex; } } } else if (messageSender.ID == "SupplierEmails") { foreach (var supplier in seed.Suppliers) { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, SupplierID = supplier.ID }, accessToken); } catch (OrderCloudException ex) { if (ex.HttpStatus != HttpStatusCode.Conflict) // this is a bug in the api https://four51.atlassian.net/browse/EX-2210 { throw ex; } } } } } }
private async Task CreateOrUpdateMessageSendersAndAssignments(EnvironmentSeed seed, string accessToken) { var defaultMessageSenders = new List <MessageSender>() { SeedConstants.BuyerEmails(seed), SeedConstants.SellerEmails(seed), SeedConstants.SuplierEmails(seed) }; var existingMessageSenders = await _oc.MessageSenders.ListAllAsync(accessToken : accessToken); foreach (var sender in defaultMessageSenders) { var messageSender = await GetOrCreateMessageSender(existingMessageSenders, sender, accessToken); if (messageSender.ID == "BuyerEmails") { var allBuyers = await _oc.Buyers.ListAllAsync(accessToken : accessToken); foreach (var buyer in allBuyers) { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, BuyerID = buyer.ID }, accessToken); } catch (OrderCloudException ex) { // this is a bug in the api PUTs should never return 409s so ignore those errors // https://four51.atlassian.net/browse/EX-2210 if (ex.HttpStatus != HttpStatusCode.Conflict) { throw ex; } } } } else if (messageSender.ID == "SellerEmails") { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID }, accessToken); } catch (OrderCloudException ex) { // this is a bug in the api PUTs should never return 409s so ignore those errors // https://four51.atlassian.net/browse/EX-2210 if (ex.HttpStatus != HttpStatusCode.Conflict) { throw ex; } } } else if (messageSender.ID == "SupplierEmails") { var allSuppliers = await _oc.Suppliers.ListAllAsync(accessToken : accessToken); foreach (var supplier in allSuppliers) { try { await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment { MessageSenderID = messageSender.ID, SupplierID = supplier.ID }, accessToken); } catch (OrderCloudException ex) { // this is a bug in the api PUTs should never return 409s so ignore those errors // https://four51.atlassian.net/browse/EX-2210 if (ex.HttpStatus != HttpStatusCode.Conflict) { throw ex; } } } } } }
private async Task CreateOrUpdateProductFacets(string token) { var defaultFacet = SeedConstants.DefaultProductFacet(); await _oc.ProductFacets.SaveAsync <HSProductFacet>(defaultFacet.ID, defaultFacet, token); }