public ActionResult CashIn(CashInView cash_in_view)
        {
            this.FlashInfo("You have cashed in $30.00.");

            var cash_in = new CashInCommand
            {
                player_token = _player_authenticator.get_player_token(),
                amount       = 30
            };

            _command_bus.send(cash_in);

            return(RedirectToAction("Index", "AccountHome"));
        }
Exemplo n.º 2
0
        public async Task <CommandHandlingResult> Handle(CashInCommand command, IEventPublisher eventPublisher)
        {
            var tx = await _paymentTransactionsRepository.GetByTransactionIdAsync(command.TransactionId);

            if (tx != null && (tx.Status == PaymentStatus.NotifyDeclined || tx.Status == PaymentStatus.NotifyProcessed || tx.Status == PaymentStatus.Processing))
            {
                return(CommandHandlingResult.Ok());
            }

            var transactionStatus = await _link4PayApiService.GetTransactionInfoAsync(command.TransactionId);

            if (!string.IsNullOrEmpty(transactionStatus.Card?.CardHash) && transactionStatus.OriginalTxnStatus == TransactionStatus.Successful)
            {
                await _paymentTransactionsRepository.SaveCardHashAsync(command.TransactionId, transactionStatus.Card.CardHash);

                if (tx != null)
                {
                    var evt = new CreditCardUsedEvent
                    {
                        ClientId     = tx.ClientId,
                        OrderId      = command.TransactionId,
                        CardHash     = transactionStatus.Card.CardHash,
                        CardNumber   = transactionStatus.Card.CardNo,
                        CustomerName = transactionStatus.Card.CardHolderName
                    };

                    eventPublisher.PublishEvent(evt);
                }
                else
                {
                    _log.Warning("CreditCardUsedEvent is not sent!", context: new { tranasactionId = transactionStatus.TxnReference }.ToJson());
                }
            }

            switch (transactionStatus.OriginalTxnStatus)
            {
            case TransactionStatus.Successful:
                tx = await _paymentTransactionsRepository.StartProcessingTransactionAsync(command.TransactionId);

                if (tx != null)     // initial status
                {
                    eventPublisher.PublishEvent(new ProcessingStartedEvent
                    {
                        OrderId = command.TransactionId
                    });
                }

                return(CommandHandlingResult.Ok());

            case TransactionStatus.Failed:
                await _paymentTransactionsRepository.SetStatusAsync(command.TransactionId, PaymentStatus.NotifyDeclined);

                await _paymentTransactionEventsLog.WriteAsync(
                    PaymentTransactionLogEvent.Create(
                        command.TransactionId, command.Request, "Declined by Payment status from payment system", nameof(CashInCommand)));

                return(CommandHandlingResult.Ok());

            default:
                return(new CommandHandlingResult {
                    Retry = true, RetryDelay = (long)TimeSpan.FromMinutes(1).TotalMilliseconds
                });
            }
        }