Exemplo n.º 1
0
        public static async Task <IDisposableEntity <Order> > CreateOrderAsync(
            this TestServiceScope scope,
            Registration registration,
            Product[] products        = null,
            ProductVariant[] variants = null,
            int[] quantities          = null,
            ApplicationUser user      = null,
            string userId             = null,
            Order.OrderStatus status  = Order.OrderStatus.Verified,
            PaymentMethod.PaymentProvider paymentProvider = PaymentMethod.PaymentProvider.EmailInvoice,
            Instant?time = null)
        {
            var order = new Order
            {
                OrderTime     = time ?? SystemClock.Instance.Now(),
                UserId        = user?.Id ?? userId ?? registration.UserId,
                Registration  = registration,
                PaymentMethod = paymentProvider,
                OrderLines    = products?.Select((p, i) => new OrderLine
                {
                    Product                   = p,
                    ProductVariant            = variants?.Length > i ? variants[i] : null,
                    Quantity                  = quantities?.Length > i ? quantities[i] : p.MinimumQuantity,
                    ProductDescription        = products[i].Description,
                    ProductVariantDescription = variants?.Length > i ? variants[i]?.Description : null,
                    VatPercent                = p.VatPercent,
                    Price              = variants?.Length > i ? variants[i]?.Price ?? p.Price : p.Price,
                    ProductName        = p.Name,
                    ProductVariantName = variants?.Length > i ? variants[i]?.Name : null,
                }).ToList()
            };

            if (status == Order.OrderStatus.Invoiced ||
                status == Order.OrderStatus.Refunded)
            {
                order.Status = Order.OrderStatus.Verified;
            }

            if (status == Order.OrderStatus.Refunded)
            {
                order.Status = Order.OrderStatus.Invoiced;
            }

            if (status != Order.OrderStatus.Draft)
            {
                order.Status = status;
            }

            await scope.Db.Orders.AddAsync(order);

            await scope.Db.SaveChangesAsync();

            return(new DisposableEntity <Order>(order, scope.Db));
        }
Exemplo n.º 2
0
 public static async Task <IDisposableEntity <Order> > CreateOrderAsync(
     this TestServiceScope scope,
     Registration registration,
     Product product,
     ProductVariant variant   = null,
     int quantity             = 1,
     Order.OrderStatus status = Order.OrderStatus.Verified,
     ApplicationUser user     = null,
     string userId            = null,
     PaymentMethod.PaymentProvider paymentProvider = PaymentMethod.PaymentProvider.EmailInvoice)
 {
     return(await scope.CreateOrderAsync(registration,
                                         new[] { product },
                                         variant != null?new[] { variant } : null,
                                         new[] { quantity },
                                         user, userId,
                                         status, paymentProvider));
 }
Exemplo n.º 3
0
 public bool AcceptPaymentProvider(PaymentMethod.PaymentProvider provider)
 {
     return(provider is PaymentMethod.PaymentProvider.StripeInvoice);
 }
Exemplo n.º 4
0
 public bool AcceptPaymentProvider(PaymentMethod.PaymentProvider provider)
 {
     return(provider == PaymentMethod.PaymentProvider.EmailInvoice);
 }