Esempio n. 1
0
        public async Task BuildRMA(HSOrder order, List <string> supplierIDs, LineItemStatusChanges lineItemStatusChanges, List <HSLineItem> lineItemsChanged, DecodedToken decodedToken)
        {
            foreach (string supplierID in supplierIDs)
            {
                HSSupplier supplier = await _oc.Suppliers.GetAsync <HSSupplier>(supplierID);

                RMA rma = new RMA()
                {
                    PartitionKey     = "PartitionValue",
                    SourceOrderID    = order.ID,
                    TotalCredited    = 0M,
                    ShippingCredited = 0M,
                    RMANumber        = await BuildRMANumber(order),
                    SupplierID       = supplierID,
                    SupplierName     = supplier.Name,
                    Type             = lineItemStatusChanges.Status == LineItemStatus.CancelRequested ? RMAType.Cancellation : RMAType.Return,
                    DateCreated      = DateTime.Now,
                    DateComplete     = null,
                    Status           = RMAStatus.Requested,
                    LineItems        = BuildLineItemRMA(supplierID, lineItemStatusChanges, lineItemsChanged, order),
                    Logs             = new List <RMALog>(),
                    FromBuyerID      = order.FromCompanyID,
                    FromBuyerUserID  = order.FromUser.ID
                };
                await PostRMA(rma);
            }
        }
Esempio n. 2
0
 public static ZohoContact Map(ZohoContact contact, HSSupplier supplier,
                               HSAddressSupplier address, User user, ZohoCurrency currency)
 {
     return(new ZohoContact()
     {
         contact_id = contact.contact_id,
         company_name = supplier.ID,
         contact_name = supplier.Name,
         contact_type = "vendor",
         billing_address = ZohoAddressMapper.Map(address),
         shipping_address = ZohoAddressMapper.Map(address),
         contact_persons = contact.contact_persons = (contact.contact_persons != null &&
                                                      contact.contact_persons.Any(c => c.email == user.Email))
             ? new List <ZohoContactPerson>()
         {
             new ZohoContactPerson()
             {
                 email = user.Email,
                 first_name = user.FirstName,
                 last_name = user.LastName,
                 phone = user.Phone
             }
         }
             : null,
         currency_id = currency.currency_id
     });
 }
Esempio n. 3
0
 public async Task <HSSupplier> Create([FromBody] HSSupplier supplier)
 {
     return(await _command.Create(supplier, VerifiedUserContext));
 }
Esempio n. 4
0
        public async Task <HSSupplier> Create(HSSupplier supplier, string accessToken, bool isSeedingEnvironment = false)
        {
            var token = isSeedingEnvironment ? accessToken : null;

            // Create Supplier
            supplier.ID = "{supplierIncrementor}";
            var ocSupplier = await _oc.Suppliers.CreateAsync(supplier, token);

            supplier.ID = ocSupplier.ID;
            var ocSupplierID = ocSupplier.ID;

            // This supplier user is created so that we can define an api client with it as the default context user
            // this allows us to perform elevated supplier actions on behalf of that supplier company
            // It is not an actual user that will login so there is no password or valid email
            var supplierUser = await _oc.SupplierUsers.CreateAsync(ocSupplierID, new User()
            {
                Active    = true,
                FirstName = "Integration",
                LastName  = "Developer",
                Username  = $"dev_{ocSupplierID}",
                Email     = "*****@*****.**"
            }, token);

            await CreateUserTypeUserGroupsAndSecurityProfileAssignments(supplierUser, token, ocSupplierID);

            // Create API Client for new supplier
            var apiClient = await _oc.ApiClients.CreateAsync(new ApiClient()
            {
                AppName = $"Integration Client {ocSupplier.Name}",
                Active  = true,
                DefaultContextUserName = supplierUser.Username,
                ClientSecret           = _settings.OrderCloudSettings.MiddlewareClientSecret,
                AccessTokenDuration    = 600,
                RefreshTokenDuration   = 43200,
                AllowAnyBuyer          = false,
                AllowAnySupplier       = false,
                AllowSeller            = false,
                IsAnonBuyer            = false,
            }, token);


            // not adding api client ID on supplier Create because that approach would require creating the API client first
            // but creating supplier first is preferable in case there are error in the request
            ocSupplier = await _oc.Suppliers.PatchAsync(ocSupplier.ID, new PartialSupplier()
            {
                xp = new
                {
                    ApiClientID = apiClient.ID
                }
            }, token);

            // Assign Supplier API Client to new supplier
            await _oc.ApiClients.SaveAssignmentAsync(new ApiClientAssignment()
            {
                ApiClientID = apiClient.ID,
                SupplierID  = ocSupplierID
            }, token);

            // assign to message sender
            await _oc.MessageSenders.SaveAssignmentAsync(new MessageSenderAssignment
            {
                MessageSenderID = "SupplierEmails",
                SupplierID      = ocSupplierID
            });

            return(supplier);
        }
Esempio n. 5
0
 public async Task <HSSupplier> Create([FromBody] HSSupplier supplier)
 {
     return(await _command.Create(supplier, UserContext.AccessToken));
 }
Esempio n. 6
0
        public async Task <HSSupplier> Create(HSSupplier supplier, VerifiedUserContext user, bool isSeedingEnvironment = false)
        {
            var token = isSeedingEnvironment ? user.AccessToken : null;

            // Create Supplier
            supplier.ID = "{supplierIncrementor}";
            var ocSupplier = await _oc.Suppliers.CreateAsync(supplier, token);

            supplier.ID = ocSupplier.ID;
            var ocSupplierID = ocSupplier.ID;

            // Create Integrations Supplier User
            var supplierUser = await _oc.SupplierUsers.CreateAsync(ocSupplierID, new User()
            {
                Active    = true,
                Email     = user.Email,
                FirstName = "Integration",
                LastName  = "Developer",
                Password  = "******", // _settings.OrderCloudSettings.DefaultPassword,
                Username  = $"dev_{ocSupplierID}"
            }, token);

            await CreateUserTypeUserGroupsAndSecurityProfileAssignments(supplierUser, token, ocSupplierID);

            // Create API Client for new supplier
            var apiClient = await _oc.ApiClients.CreateAsync(new ApiClient()
            {
                AppName = $"Integration Client {ocSupplier.Name}",
                Active  = true,
                DefaultContextUserName = supplierUser.Username,
                ClientSecret           = _settings.OrderCloudSettings.MiddlewareClientSecret,
                AccessTokenDuration    = 600,
                RefreshTokenDuration   = 43200,
                AllowAnyBuyer          = false,
                AllowAnySupplier       = false,
                AllowSeller            = false,
                IsAnonBuyer            = false,
            }, token);


            // not adding api client ID on supplier Create because that approach would require creating the API client first
            // but creating supplier first is preferable in case there are error in the request
            ocSupplier = await _oc.Suppliers.PatchAsync(ocSupplier.ID, new PartialSupplier()
            {
                xp = new
                {
                    ApiClientID = apiClient.ID
                }
            }, token);

            // Assign Supplier API Client to new supplier
            await _oc.ApiClients.SaveAssignmentAsync(new ApiClientAssignment()
            {
                ApiClientID = apiClient.ID,
                SupplierID  = ocSupplierID
            }, token);

            // list message senders
            var msList = await _oc.MessageSenders.ListAsync(accessToken : token);

            // create message sender assignment
            var assignmentList = msList.Items.Select(ms =>
            {
                return(new MessageSenderAssignment
                {
                    MessageSenderID = ms.ID,
                    SupplierID = ocSupplierID
                });
            });
            await Throttler.RunAsync(assignmentList, 100, 5, a => _oc.MessageSenders.SaveAssignmentAsync(a, token));

            return(supplier);
        }