public Order executeOrder(OrderDTO orderdto, string UserName, string StripeClientId) { var order = _orderFactory.Create(orderdto, UserName); var invoice = _invoiceFactory.Create(order); if (!_orderRepo.CheckOrder(order)) { return(null); } order = _orderRepo.addOrder(order); invoice = _invoiceRepo.addInvoice(invoice); var succeded = _stripeService.executeCharge(order.OrderId, invoice.TotalSum, StripeClientId); Payment payment; if (succeded.Item2) { payment = _paymentFactory.Create(succeded.Item1, order.OrderId); _orderRepo.SetExecuted(order); _paymentRepo.addPayment(payment); } else { payment = _paymentFactory.Create(succeded.Item1, order.OrderId); _paymentRepo.addPayment(payment); } return(order); //create charge for stripe from order, complete it //create invoice from return of stripe call }
public void ShouldConvertJsonToSpecifiedFormat() { string jsonFromDb = "{\"numero_pedido\":\"OR1234\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriinho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; string jsonFromRequest = "{\"numero_pedido\":\"OR1235\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriinho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; //string jsonFromRequest = "{\"numero_pedido\":\"OR1234\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriniho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; Assert.True(jsonFromRequest.HasSameKeys(jsonFromDb)); var jsonDataDictionary = jsonFromRequest.GetKeyAndValuesToDictionary(); Assert.True(jsonDataDictionary.CanBeMappedTo(_customerPropertyMappings)); Assert.True(jsonDataDictionary.CanBeMappedTo(_itemPropertyMappings)); Assert.True(jsonDataDictionary.CanBeMappedTo(_paymentPropertyMappings)); var mundiPaggOrder = new MundiPaggOrder(); var payment = PaymentFactory.Create(jsonDataDictionary, _paymentPropertyMappings); mundiPaggOrder.Payments.Add(payment); var customer = CustomerFactory.Create(jsonDataDictionary, _customerPropertyMappings); mundiPaggOrder.Customer = customer; var itens = ItensFactory.CreateList(jsonDataDictionary, _itemPropertyMappings); mundiPaggOrder.Items = itens; Assert.True(mundiPaggOrder.Items.Any() && mundiPaggOrder.Payments.Any() && !string.IsNullOrEmpty(mundiPaggOrder.Customer.Name)); }
public async override Task <CommandExecutionResult> ExecuteAsync() { var totalAmount = OrderItems.Sum(item => item.Price * item.Quantity); var orderItems = OrderItems.Select(items => new OrderItem(items.ProductId, items.Quantity, items.Price * items.Quantity, PaymentMethod)); var paymentDetails = new PaymentDetails(CashAmount, CardNumber, CardOwner, totalAmount, PaymentMethod); var paymentFactory = PaymentFactory.Create(paymentDetails); var paymentResult = paymentFactory.Pay(paymentDetails); if (!paymentResult.IsSuccess) { return(await FailAsync(ErrorCode.PaymentUnsuccesfull)); } var order = new Domain.OrderManagement.Order(BoothId, totalAmount, OrderStatus.Placed, orderItems.ToList()); await SaveAsync(order, _orderRepository); return(await OkAsync(DomainOperationResult.CreateEmpty())); }
public void Should_have_an_initial_status_set_to_pending() { // Act var aggregate = PaymentFactory.Create(_dateProvider); // Assert aggregate.Status.Should().Be(PaymentStatus.Pending); }
public HasAlreadyBeenProcessedTests() { var today = new DateTimeOffset(new DateTime(2019, 08, 19, 0, 0, 0, DateTimeKind.Utc)); var dateProvider = Substitute.For <IProvideDateTime>(); dateProvider.UtcNow().Returns(today); _payment = PaymentFactory.Create(dateProvider); }
public UpdatePaymentTests() { var today = new DateTimeOffset(new DateTime(2019, 08, 19, 0, 0, 0, DateTimeKind.Utc)); var dateProvider = Substitute.For<IProvideDateTime>(); dateProvider.UtcNow().Returns(today); _payment = PaymentFactory.Create(dateProvider); _service = new DomainServices.PaymentService(); }
public void Should_set_the_status_to_rejected_when_Reject_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); // Act aggregate.Reject(BankTransactionId.Create()); // Assert aggregate.Status.Should().Be(PaymentStatus.Rejected); }
public void Should_raise_a_PaymentApproved_event_when_Approve_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); // Act aggregate.Approve(BankTransactionId.Create()); // Assert aggregate.Should().HaveRaisedEventOfType <PaymentApproved>(); }
public void Should_raise_an_PaymentRequested_event_when_a_new_aggregate_instance_is_created() { // Act var aggregate = PaymentFactory.Create(_dateProvider); // Assert aggregate.Should().HaveRaisedEventOfType <PaymentRequested>(); aggregate.Should().HaveEventMatching <PaymentRequested>(@event => @event.Id == aggregate.Id); aggregate.Should().HaveEventMatching <PaymentRequested>(@event => @event.CreditCard == aggregate.CreditCard); aggregate.Should().HaveEventMatching <PaymentRequested>(@event => @event.Amount == aggregate.Amount); }
public void Should_throw_when_the_transaction_id_null() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); // Act Action action = () => aggregate.Reject(null); // Assert action.Should().Throw <TransactionIdCannotBeNullException>(); }
public void ShouldCreatePayment() { //act var payment = _sut.Create(_request); //arrange payment.Should().NotBeNull(); payment.Card.Should().BeEquivalentTo(_request.Card); payment.Currency.Should().Be(_request.Currency); payment.Amount.Should().Be(_request.Amount); }
public void Should_raise_a_PaymentRejected_event_when_Reject_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); var transactionId = BankTransactionId.Create(); // Act aggregate.Reject(transactionId); // Assert aggregate.Should().HaveRaisedEventOfType <PaymentRejected>(); aggregate.TransactionId.Should().Be(transactionId); }
public void Should_set_the_status_to_approved_when_Approve_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); var transactionId = BankTransactionId.Create(); // Act aggregate.Approve(transactionId); // Assert aggregate.Status.Should().Be(PaymentStatus.Approved); aggregate.TransactionId.Should().Be(transactionId); }
public void Should_throw_when_Reject_is_called_and_status_is_not_pending() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); aggregate.Reject(BankTransactionId.Create()); // Act Action action = () => aggregate.Reject(BankTransactionId.Create()); // Assert action.Should().Throw <PaymentAlreadyProcessedException>(); }
public void AddNewTransaction(CategoryType categoryType) { var newPayment = PaymentFactory.Create(Element, categoryType); var newTransaction = TransactionFactory.Create(Element, newPayment); var transactionVm = new TransactionViewModelFacotry(Services).ConvertToVm(newTransaction); AddTransaction(transactionVm); transactionVm.PaymentViewModel.AddTransaction(transactionVm); transactionVm.CurrentMonthVm = this; UpdateLists(); }
public PaymentProcessorTests() { var today = new DateTimeOffset(new DateTime(2019, 08, 19, 0, 0, 0, DateTimeKind.Utc)); var dateProvider = Substitute.For <IProvideDateTime>(); dateProvider.UtcNow().Returns(today); var payment = PaymentFactory.Create(dateProvider); _paymentId = payment.Id; _paymentService = Substitute.For <IPaymentService>(); _bank = Substitute.For <IAcquiringBank>(); _paymentRepo = Substitute.For <IAggregateRepository <Payment, PaymentId> >(); _paymentRepo.Get(Arg.Is(_paymentId)).Returns(payment); }