Пример #1
0
        private void ProcessPayment(PayAccount cmd)
        {
            try
            {
                var luckObligation = _accountState.Obligations.FirstOrDefault(x => x.Key == "AccountAdjustments").Value;
                if (luckObligation == null)
                {
                    throw new Exception($"[ProcessPayment]: Inconvibable! Why is there no obligation?");
                }

                var @event = new PaymentAppliedToObligation(
                    luckObligation.ObligationNumber
                    , new CreditCardPayment(cmd.AmountToPay)
                    , cmd.AmountToPay
                    , "CreditCard Payment Applied To Dues"
                    );
                Persist(@event, s =>
                {
                    _accountState = _accountState.ApplyEvent(@event);
                    Self.Tell(new PublishAccountStateToKafka());
                    ApplySnapShotStrategy();
                    Sender.Tell(new MyAccountStatus("Payment Applied", (AccountState)_accountState.Clone()));
                });
            }
            catch (Exception e)
            {
                _log.Error($"[ProcessPayment]: {e.Message} {e.StackTrace}");
                throw;
            }
        }
Пример #2
0
        private AccountState ApplyEvent(PaymentAppliedToObligation occurred)
        {
            var trans = new FinancialTransaction(occurred.FinancialBucket, occurred.Amount);

            Obligations[occurred.ObligationNumber].PostTransaction(trans);
            decimal newBal = CurrentBalance - decimal.Parse(occurred.Amount.ToString());

            return(new AccountState(
                       AccountNumber,
                       newBal,
                       AccountStatus,
                       Obligations,
                       SimulatedFields,
                       AuditLog.Add(new StateLog(
                                        "PaymentAppliedToObligation",
                                        $"{occurred.Message} Balance After: {newBal :C}",
                                        occurred.UniqueGuid(),
                                        occurred.OccurredOn()))
                       , OpeningBalance
                       , Inventroy
                       , UserName
                       , lastPaymentAmount: occurred.Amount
                       , lastPaymentDate: DateTime.Today));
        }