Ejemplo n.º 1
0
        public void BookReceivable(Receivable receivable)
        {
            Guard.NotNull(receivable, nameof(receivable));
            var bookingResult = receivable.Book(this.RemainingCredit);

            this.receivableTotal += bookingResult.Coverage;
            this.receivables.Add(receivable);
            this.RaiseEvent(new ReceivableBooked(bookingResult.OrderId, this.receivableTotal, this.Id, bookingResult.OrderStatus));
        }
Ejemplo n.º 2
0
        private void BookIfSuspended(Receivable receivable)
        {
            var bookingResult = receivable.BookIfSuspended(this.RemainingCredit);

            if (bookingResult != ReceivableBookingResult.EmptyResult)
            {
                this.receivableTotal += bookingResult.Coverage;
                this.RaiseEvent(new ReceivableBooked(bookingResult.OrderId, this.receivableTotal, this.Id, bookingResult.OrderStatus));
            }
        }
Ejemplo n.º 3
0
        public void BookPayment(Guid orderId, Money paidAmount)
        {
            this.receivableTotal -= paidAmount;
            Receivable paidReceivable = null;
            var        comparer       = Receivable.ByCreatedAuditTrailComparerInstance;

            foreach (var receivable in this.receivables.OrderBy(o => o, comparer))
            {
                paidReceivable = receivable.TryBookPayment(orderId, paidAmount) ? receivable : paidReceivable;
                this.BookIfSuspended(receivable);
            }

            Guard.NotNull(paidReceivable, new InvalidOperationException("Cannot find requested receivable."));
            this.receivables.Remove(paidReceivable);
            this.RaiseEvent(new PaymentBooked(orderId));
        }