Пример #1
0
        public async Task <int> Handle(CreateOrderCommandModel request, CancellationToken cancellationToken)
        {
            var user = await userQueryService.GetRawByIdAsync(request.UserId);

            var productOrders = await productOrderQueryService.CreateAsync(request.Products);

            var shipment = await shipmentQueryService.GetRawAsync(request.ShipmentId);

            var payment = await paymentsRepository.GetPaymentAsync(request.PaymentId);

            if ((shipment.Type == ShipmentType.CashOnDelivery && payment.PaymentType != PaymentType.PaymentOnDelivery) ||
                (shipment.Type != ShipmentType.CashOnDelivery && payment.PaymentType == PaymentType.PaymentOnDelivery))
            {
                throw new StreetwoodException(ErrorCode.InvalidShipmentType);
            }

            var orderDiscount = await orderDiscountQueryService.GetRawByCodeAsync(request.PromoCode);

            var address = await addressQueryService.GetAsync(request.Address, request.AddressId, request.UserId);

            var order = await orderFactory.CreateOrderAsync(user, productOrders, shipment, payment, orderDiscount, request.Comment, address);

            await emailService.SendNewOrderEmailAsync(order);

            return(order.Id);
        }
Пример #2
0
        public async Task <PaymentRecord?> GetPaymentAsync(Guid paymentId, Guid companyId)
        {
            var result = await _instrumentor.ApplyAsync(
                () => _instrumentedPaymentsRepository.GetPaymentAsync(paymentId, companyId),
                "InstrumentedGetPaymentRepository");

            return(result);
        }
        public async Task <PaymentRecord?> GetPaymentAsync(Guid paymentId, Guid companyId)
        {
            var payment = await _paymentsRepository.GetPaymentAsync(paymentId, companyId);

            if (payment == null)
            {
                _logger.Write(LogLevel.Warning,
                              $"{EventCodes.PaymentRequestedNotFound} - TransactionId: {paymentId}, CompanyId: {companyId}");
            }

            return(payment);
        }
        public async Task <PaymentRecord?> GetPaymentAsync(Guid paymentId, Guid companyId)
        {
            var innerResult = await _innerRepository.GetPaymentAsync(paymentId, companyId);

            if (innerResult != null)
            {
                innerResult.CardNumber = _encryptor.Decrypt(innerResult.CardNumber);
                innerResult.CardName   = _encryptor.Decrypt(innerResult.CardName);
            }

            return(innerResult);
        }