public Task Create(MessageContext context, CreatePaymentEvent inputEvent)
        {
            var payment = paymentsRepository.Create(inputEvent.Amount, inputEvent.StartTimestamp, inputEvent.Interval, inputEvent.AccountId, inputEvent.Recipient);

            if (context.ReplyTo != null)
            {
                publishingRouter.Publish(context.ReplyTo, new SelectedPaymentsEvent {
                    Payments = new[] { payment }
                }, context.FlowId);
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
        internal void Create(CreatePaymentEvent e)
        {
            if (Status != PaymentStatus.Unknown)
            {
                throw new Exception("Payment has already been created");
            }

            Status     = PaymentStatus.Created;
            CardNumber = e.CardNumber;
            Amount     = e.Amount;
            Currency   = e.Currency;
            Created    = e.TimeStamp;
            Id         = e.Id;
        }
コード例 #3
0
ファイル: Payment.cs プロジェクト: IbraWorks/CheckoutTechTest
        public void HandleCreatePayment(CreatePaymentEvent ev)
        {
            if (PaymentState != PaymentState.Unknown)
            {
                throw new Exception("This payment has already been created.");
            }

            PaymentState = PaymentState.Created;
            TimeStamp    = ev.Timestamp;
            Id           = ev.Id;

            Currency   = ev.Currency;
            CardNumber = ev.CardNumber;
            Amount     = ev.Amount;
        }
コード例 #4
0
        //this handler will actually fire off multiple events instead of just creating the payment, we should ideally refactor this with a payment service
        // and split the functionality up as the process gets more complicated.
        public async Task <Response <Guid> > Handle(CreatePaymentCommand request, CancellationToken cancellationToken)
        {
            var paymentExists = await IsPaymentDuplicate(request.Id);

            if (paymentExists)
            {
                return(Response.Failure <Guid>($"Error, a payment with id {request.Id} already exists"));
            }

            // dont need to create the payment and process the events. we can get a payment by processing the events on the fly
            // see GetPaymentHandler for details. For now just dispatch the necessary events.

            var createPaymentEvent = new CreatePaymentEvent(DateTime.UtcNow, request.Id, request.CardNumber, request.Currency, request.Amount);
            await _eventDispatcher.DispatchEvent(createPaymentEvent);


            await _eventDispatcher.DispatchEvent(new PaymentSentToAcquiringBankEvent(DateTime.UtcNow, request.Id));

            //TODO: Extract this to a config file property in appsettings.json
            var baseUrl  = "http://localhost:4000";
            var response = await _acquiringBankHttpClient.Post <Guid>($"{baseUrl}/api/AcquiringBank", new
            {
                request.CardNumber,
                request.MonthExpired,
                request.YearExpired,
                request.Ccv,
                request.Amount,
                request.Currency
            });

            if (!response.Error)
            {
                await _eventDispatcher.DispatchEvent(new PaymentSucceededEvent(DateTime.UtcNow, request.Id, response.Data));

                return(Response.Success <Guid>(response.Data, response.Message));
            }
            else
            {
                await _eventDispatcher.DispatchEvent(new PaymentFailedEvent(DateTime.UtcNow, request.Id, response.Message));

                return(Response.Failure(response.Message, response.Data));
            }
        }
コード例 #5
0
        public async Task Handle_ProduceBankResponseTransactionMessageAsync_Success()
        {
            // Arrange
            var createPaymentEvent = new CreatePaymentEvent(Guid.NewGuid(), Guid.NewGuid(), new CreditCardProtected(), Money.Zero);

            var createTransactionEvent = new CreateTransactionEvent(createPaymentEvent.EventID, Guid.NewGuid(), "Approved");

            var deliveryMessageReport = new DeliveryMessageReport("Payment.gateway-events-v2", DateTime.Now);

            var mockITopicProducer = new Mock <ITopicProducer <CreateTransactionEvent> >();

            mockITopicProducer.Setup(t => t.ProduceAsync(createTransactionEvent))
            .ReturnsAsync(deliveryMessageReport);

            // Act
            var bankEventHandler = new BankEventHandler(mockITopicProducer.Object);
            await bankEventHandler.HandleAsync(createPaymentEvent);

            // Assert
            mockITopicProducer.Verify(mock => mock.ProduceAsync(It.IsAny <CreateTransactionEvent>()), new Times());
        }