Esempio n. 1
0
        public async Task <PaymentAggregate> CreatePaymentAsync(CancellationToken cancellationToken, string cardNumber,
                                                                int amount, string currency, PaymentStatus paymentStatus, Guid bankTransactionUid,
                                                                DateTimeOffset createdDateUtc)
        {
            var aggregate = new PaymentAggregate(cardNumber, amount, currency, paymentStatus, bankTransactionUid, createdDateUtc);
            await _database.Payments.AddAsync(aggregate.State, cancellationToken);

            return(aggregate);
        }
Esempio n. 2
0
        public async Task Handle(OrderPlacedEvent message, IMessageHandlerContext context)
        {
            var payment = PaymentAggregate.Create(message.OrderId, message.Amount);

            payment.ProcessPayment();
            await _paymentRepository.Create(payment);

            await context.Publish(new PaymentProcessedEvent(payment.OrderId, DateTime.Now, payment.Amount));
        }
        public void ReturnsAggregate_WithCorrectParameters()
        {
            //Setup

            //Test
            var sut = new PaymentAggregate(CardNumber, Amount, Currency, PaymentStatus.PaymentSucceeded, _bankTransactionUid, _createdDateUtc);

            //Verify
            Assert.Equal(TransformedCardNumber, sut.State.ObfuscatedCardNumber);
            Assert.Equal(Amount, sut.State.Amount);
            Assert.Equal(Currency, sut.State.Currency);
            Assert.Equal(_bankTransactionUid, sut.State.BankTransactionUid);
            Assert.Equal(_createdDateUtc, sut.State.CreatedDateUtc);
            Assert.NotEqual(default(Guid), sut.State.Uid);
        }
Esempio n. 4
0
        public async Task <string> Handle(PaymentRequestCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            _logger.LogTrace($"Handling {nameof(PaymentRequestCommand)} with id {command.Id}.");

            var payment = new PaymentAggregate(command.Id, command.MerchantId, command.CardNumber, command.ExpMonth, command.ExpYear, command.Amount, command.Currency);
            await payment.RequestAsync(_bank, command.CVV);

            await _repository.SaveAggregateAsync(payment);

            return(payment.Status.ToString());
        }
Esempio n. 5
0
 public Task Create(PaymentAggregate payment)
 {
     return(Task.Run(() => _payments.Add(payment)));
 }