public override void Execute() { CheckoutEvent e = new CheckoutEvent(); foreach (GroceryItem item in _groceryItems) { if (item.IsInCart) { e.Ids.Add(item.Id); } } _eventAggregator.Publish(e); }
public void Handle(CheckoutEvent e) { Requires.NotNull(e, "e"); foreach (Guid id in e.Ids) { GroceryItem item = _groceryItems.Find(id); if (item == null) { continue; } _groceryItems.Remove(item); } }
public async Task <ActionResult <bool> > Checkout(string clienteId, [FromBody] CadastroViewModel input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CarrinhoCliente carrinho; try { carrinho = await _repository.GetCarrinhoAsync(clienteId); } catch (KeyNotFoundException) { return(NotFound()); } var itens = carrinho.Itens.Select(i => new CheckoutEventItem(i.Id, i.ProdutoId, i.ProdutoNome, i.PrecoUnitario, i.Quantidade)).ToList(); var checkoutEvent = new CheckoutEvent (clienteId, input.Nome, input.Email, input.Telefone , input.Endereco, input.Complemento, input.Bairro , input.Municipio, input.UF, input.CEP , Guid.NewGuid() , itens); // Assim que fazemos a finalização, envia um evento de integração para // API OrdemDeCompra converter o carrinho em pedido e continuar com // processo de criação de pedido await _bus.Publish(checkoutEvent); var cadastroEvent = new CadastroEvent (clienteId, input.Nome, input.Email, input.Telefone , input.Endereco, input.Complemento, input.Bairro , input.Municipio, input.UF, input.CEP); await _bus.Publish(cadastroEvent); await _repository.DeleteCarrinhoAsync(clienteId); return(Accepted(true)); }
public ActionResult CheckOut(CheckoutViewModel cvm) { if (ModelState.IsValid) { var checkoutEvent = new CheckoutEvent { DateTimeCheckedOut = cvm.TimeCheckedOut, BookId = cvm.BookId, PatronId = cvm.PatronId }; var book = db.Books.Single(x => x.BookId == cvm.BookId); book.PatronId = cvm.PatronId; db.CheckoutEvents.Add(checkoutEvent); db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cvm)); }
private async Task PublicarEventoFechamentoDoCarrinho(string clienteId, CadastroViewModel input, CarrinhoCliente carrinho) { var itens = carrinho.Itens.Select(i => new CheckoutEventItem(i.Id, i.ProdutoId, i.ProdutoNome, i.PrecoUnitario, i.Quantidade)).ToList(); var checkoutEvent = new CheckoutEvent (clienteId, input.Nome, input.Email, input.Telefone , input.Endereco, input.Complemento, input.Bairro , input.Municipio, input.UF, input.CEP , Guid.NewGuid() , itens); // Assim que fazemos a finalização, envia um evento de integração para // API OrdemDeCompra converter o carrinho em pedido e continuar com // processo de criação de pedido await _bus.Publish(checkoutEvent); _logger.LogInformation(eventId: EventId_Checkout, message: "Evento de check out foi enviado: {CheckoutEvent}", args: checkoutEvent); }
public void PublishCheckout(string queueName, CheckoutEvent publishModel) { using (var channel = _rabbitMqConnection.CreateModel()) { channel.QueueDeclare(queue: queueName, durable: false, exclusive: false, autoDelete: false, arguments: null); var message = JsonConvert.SerializeObject(publishModel); var body = Encoding.UTF8.GetBytes(message); IBasicProperties properties = channel.CreateBasicProperties(); properties.Persistent = true; properties.DeliveryMode = 2; channel.ConfirmSelect(); channel.BasicPublish(exchange: "", routingKey: queueName, mandatory: true, basicProperties: properties, body: body); channel.WaitForConfirmsOrDie(); channel.BasicAcks += (sender, eventArgs) => { Console.WriteLine("Sent to RabbitMQ"); }; channel.ConfirmSelect(); } }
private static async Task Execute() { var client = new RavelinClient("sk_live_XXXXXXXX"); // change with a valid key var customerEvent = new CustomerEvent { Customer = new Customer { CustomerId = "61283761287361", RegistrationTimeUtc = DateTime.UtcNow.AddDays(-5), Name = "Mark Twain", GivenName = "Mark", FamilyName = "Twain", DateOfBirth = "1980-01-27", Gender = "Male", Email = "*****@*****.**", EmailVerifiedTimeUtc = DateTime.UtcNow.AddDays(-5), Username = "******", Location = new Location { Street1 = "James St", City = "Darwen", Region = "Blackburn with Darwen", PostalCode = "BB3 1AS", Country = "GBR", Latitude = 53.697471, Longitude = -2.470891 }, Custom = new { Newsletter = false, InvitedBy = "7198737117" } } }; OutputResponse(await client.SendEvent(EventType.Customer, customerEvent)); var loginEvent = new LoginEvent { CustomerId = "61283761287361", Device = new Device { DeviceId = "2b6f0cc904d137be2e1730235f5664094b831186", Type = "phone", Manufacturer = "apple", Model = "iPhone8,1", OperatingSystem = "iOS 8", IpAddress = "22.231.113.64" } }; OutputResponse(await client.SendEvent(EventType.Login, loginEvent)); var orderEvent = new OrderEvent { CustomerId = "61283761287361", Order = new Order { OrderId = "n1QSYK0ceGNZqU28ien3", Price = 4675, Currency = "GBP", Market = "europe", Country = "GBR", MarketCity = "london", Items = new List <Item> { new Item { Sku = "3726-8", Name = "Women's Arch Sweater M 55", Price = 1990, Currency = "GBP", Quantity = 2 }, new Item { Sku = "3731-4", Name = "Women's Yellow Tee M 54", Price = 695, Currency = "GBP", Quantity = 1 } }, From = new Location { Street1 = "19 Gosport Walk", PostalCode = "N17 9QD", Region = "London", Country = "GBR" }, To = new Location { Street1 = "73 Braganza St", PostalCode = "SE17 3RD", Region = "London", Country = "GBR" }, CreationTimeUtc = DateTime.UtcNow, ExecutionTimeUtc = DateTime.UtcNow, Status = new OrderStatus { Stage = OrderStage.Pending, Actor = "buyer" } }, DeviceId = "2b6f0cc904d137be2e1730235f5664094b831186" }; OutputResponse(await client.SendEvent(EventType.Order, orderEvent)); // Send card payment method event var paymentMethodEvent = new PaymentMethodEvent { CustomerId = "61283761287361", PaymentMethod = new PaymentMethod { PaymentMethodId = "783917", InstrumentId = "card_16nWlGHD2LFseSsHaUp9kIW2", RegistrationTimeUtc = DateTime.UtcNow, NickName = "MasterCard **** 4242", MethodType = PaymentMethodType.Card, CardBin = "123456", CardLastFour = "4242", CardType = CardType.Mastercard, ExpiryMonth = 6, ExpiryYear = 2019, SuccessfulRegistration = true, CountryIssued = "GBR", Active = true, BillingAddress = new Location { Street1 = "73 Braganza St", PostalCode = "SE17 3RD", Region = "London", Country = "GBR" }, Banned = false } }; OutputResponse(await client.SendEvent(EventType.PaymentMethod, paymentMethodEvent)); var preTransactionEvent = new PreTransactionEvent { CustomerId = "61283761287361", PaymentMethodId = "783917", OrderId = "n1QSYK0ceGNZqU28ien3", Transaction = new PreTransaction { TransactionId = "f61f8594e06459fa046707c36159bb36", Email = "*****@*****.**", Debit = 4675, Credit = 0, Currency = "GBP", Type = TransactionType.AuthCapture, Gateway = "stripe", SecureProtocol = new SecureProtocol { Attempted = true, StartTimeUtc = DateTime.UtcNow } } }; OutputScoredResponse(await client.SendEventAndScore(EventType.PreTransaction, preTransactionEvent)); var transactionEvent = new TransactionEvent { CustomerId = "61283761287361", PaymentMethodId = "783917", OrderId = "n1QSYK0ceGNZqU28ien3", Transaction = new Transaction { TransactionId = "f61f8594e06459fa046707c36159bb36", Email = "*****@*****.**", Debit = 4675, Credit = 0, Currency = "GBP", Success = true, AuthCode = "1000", Gateway = "stripe", GatewayReference = "tr_16oaY72eZvKYlo2CE5ZDq9Vh", AvsResultCode = new AvsResult { Street = "A", PostalCode = "M" }, CvvResultCode = "M", Type = TransactionType.AuthCapture, SecureProtocol = new SecureProtocol { Attempted = true, Success = true, StartTimeUtc = DateTime.UtcNow, EndTimeUtc = DateTime.UtcNow } } }; OutputScoredResponse(await client.SendEventAndScore(EventType.Transaction, transactionEvent)); // Update pending order to accepted order status stage orderEvent = new OrderEvent { CustomerId = "61283761287361", Order = new Order { OrderId = "n1QSYK0ceGNZqU28ien3", Price = 4675, ExecutionTimeUtc = DateTime.UtcNow, Status = new OrderStatus { Stage = OrderStage.Accepted, Actor = "seller" } } }; OutputResponse(await client.SendEvent(EventType.Order, orderEvent)); // Check-out (All-in-One) with PAN (sent to vault) var checkoutEvent = new CheckoutEvent { Customer = new Customer { CustomerId = "71983561248363", RegistrationTimeUtc = DateTime.UtcNow.AddDays(-2), GivenName = "Arya", FamilyName = "Wayne", Gender = "Female", Email = "*****@*****.**", Username = "******", Location = new Location { Street1 = "Baker St", City = "London", Region = "London", PostalCode = "NW1 6XE", Country = "GBR", Latitude = 51.523774, Longitude = -0.158537 } }, Order = new Order { OrderId = "g1QSYD0ceGNZqU28iev3", Price = 4675, Currency = "GBP", Items = new List <Item> { new Item { Sku = "3726-8", Name = "Women's Arch Sweater M 55", Price = 1990, Currency = "GBP", Quantity = 2 }, new Item { Sku = "3731-4", Name = "Women's Yellow Tee M 54", Price = 695, Currency = "GBP", Quantity = 1 } } }, PaymentMethod = new PaymentMethod { PaymentMethodId = "453237", InstrumentId = "card_19nWlGHD2LFseSsHaUp9kIW3", RegistrationTimeUtc = DateTime.UtcNow, NickName = "MasterCard **** 2424", MethodType = PaymentMethodType.Card, CardBin = "654321", CardLastFour = "2424", CardType = CardType.Mastercard, ExpiryMonth = 8, ExpiryYear = 2020, SuccessfulRegistration = true, PrepaidCard = false, CountryIssued = "GBR", Active = true, Banned = false, Pan = "5454545454545454" }, Transaction = new Transaction { TransactionId = "d12f8594e06459fa046707c53159bb30", Email = "*****@*****.**", Debit = 4675, Credit = 0, Currency = "GBP", Success = true, Gateway = "stripe", GatewayReference = "tr_67oaY72eZvKYlo2CE5ZDq9Vh", Type = TransactionType.AuthCapture } }; OutputScoredResponse(await client.SendEventAndScore(EventType.Checkout, checkoutEvent)); // Chargeback var chargebackEvent = new ChargebackEvent(new Chargeback { ChargebackId = "dp_15RsQX2eZvKYlo2C0MFNUWJC", Gateway = "stripe", GatewayReference = "ch_15RsQR2eZvKYlo2CA8IfzCX0", Reason = "general", ChargebackStatus = ChargebackStatus.Lost, Amount = 195, Currency = "USD", DisputeTimeUtc = DateTime.UtcNow.AddHours(-2) }); OutputResponse(await client.SendEvent(EventType.Chargeback, chargebackEvent)); // Backfill Events var backfillCustomerEvent = new CustomerEvent { Customer = new Customer { CustomerId = "35248561944321", RegistrationTimeUtc = DateTime.UtcNow.AddDays(-20), GivenName = "John", FamilyName = "Butler", Gender = "Male", Email = "*****@*****.**", Username = "******" }, Timestamp = DateTime.UtcNow.AddDays(-20) }; OutputBackfillResponse(await client.SendBackfillEvent(EventType.Customer, backfillCustomerEvent)); var backfillCheckoutEvent = new CheckoutEvent { CustomerId = "35248561944321", Order = new Order { OrderId = "h1DSYD0ceNPSqU28isd3", Price = 4675, Currency = "GBP", Items = new List <Item> { new Item { Sku = "3726-8", Name = "Women's Arch Sweater M 55", Price = 1990, Currency = "GBP", Quantity = 2 }, new Item { Sku = "3731-4", Name = "Women's Yellow Tee M 54", Price = 695, Currency = "GBP", Quantity = 1 } } }, PaymentMethod = new PaymentMethod { PaymentMethodId = "533228", InstrumentId = "card_19nWlGDR2LFseSsSaUk9kIC3", RegistrationTimeUtc = DateTime.UtcNow.AddDays(-6), NickName = "MasterCard **** 3213", MethodType = PaymentMethodType.Card, CardBin = "742589", CardLastFour = "3213", CardType = CardType.Mastercard, ExpiryMonth = 7, ExpiryYear = 2019, SuccessfulRegistration = true, PrepaidCard = false, CountryIssued = "GBR", Active = true, Banned = false }, Transaction = new Transaction { TransactionId = "k12f8594e06gj9fa046707c53155fb30", Email = "*****@*****.**", Debit = 4675, Credit = 0, Currency = "GBP", Success = true, Gateway = "stripe", GatewayReference = "tr_67oaY72eYhOPlo2CE5ZDq5gKh", Type = TransactionType.AuthCapture }, Timestamp = DateTime.UtcNow.AddDays(-6) }; OutputBackfillResponse(await client.SendBackfillEvent(EventType.Checkout, backfillCheckoutEvent)); Console.WriteLine("\n\nPress <Enter> to continue."); Console.ReadLine(); }
public async Task <ActionResult <bool> > Checkout(string customerId, [FromBody] RegistrationViewModel input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CustomerBasket basket; try { basket = await _repository.GetBasketAsync(customerId); } catch (KeyNotFoundException) { return(NotFound()); } var items = basket.Items.Select(i => new CheckoutEventItem(i.Id, i.ProductId, i.ProductName, i.UnitPrice, i.Quantity)).ToList(); var checkoutEvent = new CheckoutEvent (customerId, input.Name, input.Email, input.Phone , input.Address, input.AdditionalAddress, input.District , input.City, input.State, input.ZipCode , Guid.NewGuid() , items); //Once we complete it, it sends an integration event to API Ordering //to convert the basket to order and continue with the order //creation process await _bus.Publish(checkoutEvent); _logger.LogInformation(eventId: EventId_Checkout, message: "Check out event has been dispatched: {CheckoutEvent}", args: checkoutEvent); var registryEvent = new RegistryEvent (customerId, input.Name, input.Email, input.Phone , input.Address, input.AdditionalAddress, input.District , input.City, input.State, input.ZipCode); await _bus.Publish(registryEvent); _logger.LogInformation(eventId: EventId_Registry, message: "Registry event has been dispatched: {RegistryEvent}", args: registryEvent); try { await _repository.DeleteBasketAsync(customerId); await this._connection .InvokeAsync("UpdateUserBasketCount", $"{customerId}", 0); return(Accepted(true)); } catch (Exception e) { _logger.LogError(e, e.Message); throw; } }