/// <summary> /// Finds and creats authorizations for order /// For expended objects need add assign values /// </summary> /// <param name="order"><see cref="IOrder"/></param> /// <param name="params">Params to create</param> protected virtual void OnCreateAuth(IOrder order, NewOrder @params) { var listDate = new List <DateTime>(); foreach (var identifier in @params.Identifiers) { // get actual or create new authorization var authz = AuthorizationService.GetActual(order.AccountId, identifier) ?? AuthorizationService.Create(order.AccountId, identifier); // create order authorization var orderAuthz = OrderAuthorizationRepository.Create(order.Id, authz.Id); OrderAuthorizationRepository.Add(orderAuthz); // check expires if (authz.Expires != null) { listDate.Add(authz.Expires.Value); } } // set min expiration date from authorizations order.Expires = listDate.Min(o => o); }
protected void RefreshStatus(IOrder order) { if (!(order == null || order.Status == OrderStatus.Invalid)) { // Checks expires if (order.Expires != null && order.Expires < DateTime.UtcNow) { order.Status = OrderStatus.Invalid; } else { // RefreshStatus authorizations var authorizations = OrderAuthorizationRepository.GetByOrder(order.Id) .Select(o => AuthorizationService.GetById(order.AccountId, o.AuthorizationId)) .ToArray(); if (order.Status == OrderStatus.Pending) { // Check Authz statuses if (!authorizations.All(o => o.Status == AuthorizationStatus.Pending || o.Status == AuthorizationStatus.Valid)) { order.Status = OrderStatus.Invalid; } else if (authorizations.All(o => o.Status == AuthorizationStatus.Valid)) { order.Status = OrderStatus.Ready; } } } // Update repository OrderRepository.Update(order); Logger.Info("Order {id} status updated to {status}", order.Id, order.Status); } }