Пример #1
0
        public void Create(
            Merchant merchant,
            ulong cardNumber,
            Money saleValue,
            ICardNumberResolutionService cardNumberResolutionService,
            IRateService rateService)
        {
            ESInv.DBC.Ensure.That(base.State.Id == Guid.Empty, "Order has already been created");

            // Request data is already good at this stage ? i.e. At the stage where Billy and Noel said a lookup was going to get created
            // Merchant has already been resolved at the domain service layer command handler
            // Probably best to re-use Billy and Noel's context - that is a good place to start these aggregate methods

            // Offers
            var _nonDCCOffer = new PaymentOffer(1M, saleValue);
            var _offers      = new[] { _nonDCCOffer };

            var _cardCurrency = cardNumberResolutionService.Resolve(cardNumber);

            if (_cardCurrency != saleValue.Currency)
            {
                var _DCCOfferExchangeRateIncludingMargin = rateService.GetRate(saleValue.Currency, _cardCurrency);
                var _DCCOfferAmount = saleValue.Amount * _DCCOfferExchangeRateIncludingMargin;
                var _DCCOffer       = new PaymentOffer(_DCCOfferExchangeRateIncludingMargin, new Money(_cardCurrency, _DCCOfferAmount));

                _offers = new[] { _nonDCCOffer, _DCCOffer };
            }

            var _createdEvent = new ESInv.Messages.OrderCreated(
                Guid.NewGuid(),
                Guid.NewGuid(),
                merchant.Id,
                saleValue.ToMessage(),
                _offers.Select(offer => offer.ToMessage()),
                DateTimeOffset.Now);

            base.Apply(_createdEvent);
        }
Пример #2
0
 public static ESInv.Messages.PaymentOffer ToMessage(
     this PaymentOffer subject)
 {
     return(new ESInv.Messages.PaymentOffer(subject.ExchangeRateIncludingMargin, subject.PaymentValue.ToMessage()));
 }