Example #1
0
        public static SubscriptionPayment Buy(
            PayerId payerId,
            SubscriptionPeriod period,
            string countryCode,
            MoneyValue priceOffer,
            PriceList priceList)
        {
            var priceInPriceList = priceList.GetPrice(countryCode, period, PriceListItemCategory.New);

            CheckRule(new PriceOfferMustMatchPriceInPriceListRule(priceOffer, priceInPriceList));

            var subscriptionPayment = new SubscriptionPayment();

            var subscriptionPaymentCreated = new SubscriptionPaymentCreatedDomainEvent(
                Guid.NewGuid(),
                payerId.Value,
                period.Code,
                countryCode,
                SubscriptionPaymentStatus.WaitingForPayment.Code,
                priceOffer.Value,
                priceOffer.Currency);

            subscriptionPayment.Apply(subscriptionPaymentCreated);
            subscriptionPayment.AddDomainEvent(subscriptionPaymentCreated);

            return(subscriptionPayment);
        }
Example #2
0
 private void When(SubscriptionPaymentCreatedDomainEvent @event)
 {
     this.Id                    = @event.SubscriptionPaymentId;
     _payerId                   = new PayerId(@event.PayerId);
     _subscriptionPeriod        = SubscriptionPeriod.Of(@event.SubscriptionPeriodCode);
     _countryCode               = @event.CountryCode;
     _subscriptionPaymentStatus = SubscriptionPaymentStatus.Of(@event.Status);
     _value = MoneyValue.Of(@event.Value, @event.Currency);
 }
Example #3
0
        private async Task When(SubscriptionPaymentCreatedDomainEvent subscriptionPaymentCreated)
        {
            string period = SubscriptionPeriod.GetName(subscriptionPaymentCreated.SubscriptionPeriodCode);

            await _connection.ExecuteScalarAsync(
                "INSERT INTO payments.SubscriptionPayments " +
                "([PaymentId], [PayerId], [Type], [Status], [Period], [Date], " +
                "[SubscriptionId], [MoneyValue], [MoneyCurrency]) " +
                "VALUES (@SubscriptionPaymentId, @PayerId, @Type, @Status, @Period, " +
                "@OccurredOn, NULL, @Value, @Currency)",
                new
            {
                subscriptionPaymentCreated.SubscriptionPaymentId,
                subscriptionPaymentCreated.PayerId,
                Type = "Initial Payment",
                subscriptionPaymentCreated.Status,
                period,
                subscriptionPaymentCreated.OccurredOn,
                subscriptionPaymentCreated.Value,
                subscriptionPaymentCreated.Currency
            });
        }