public static SubscriptionRenewalPayment Buy( PayerId payerId, SubscriptionId subscriptionId, SubscriptionPeriod period, string countryCode, MoneyValue priceOffer, PriceList priceList) { var priceInPriceList = priceList.GetPrice(countryCode, period, PriceListItemCategory.Renewal); CheckRule(new PriceOfferMustMatchPriceInPriceListRule(priceOffer, priceInPriceList)); var subscriptionRenewalPayment = new SubscriptionRenewalPayment(); var subscriptionRenewalPaymentCreated = new SubscriptionRenewalPaymentCreatedDomainEvent( Guid.NewGuid(), payerId.Value, subscriptionId.Value, period.Code, countryCode, SubscriptionRenewalPaymentStatus.WaitingForPayment.Code, priceOffer.Value, priceOffer.Currency); subscriptionRenewalPayment.Apply(subscriptionRenewalPaymentCreated); subscriptionRenewalPayment.AddDomainEvent(subscriptionRenewalPaymentCreated); return(subscriptionRenewalPayment); }
private void When(SubscriptionRenewalPaymentCreatedDomainEvent @event) { this.Id = @event.SubscriptionRenewalPaymentId; _payerId = new PayerId(@event.PayerId); _subscriptionId = new SubscriptionId(@event.SubscriptionId); _subscriptionPeriod = SubscriptionPeriod.Of(@event.SubscriptionPeriodCode); _countryCode = @event.CountryCode; _subscriptionRenewalPaymentStatus = SubscriptionRenewalPaymentStatus.Of(@event.Status); _value = MoneyValue.Of(@event.Value, @event.Currency); }
private async Task When(SubscriptionRenewalPaymentCreatedDomainEvent subscriptionRenewalPaymentCreated) { string period = SubscriptionPeriod.GetName(subscriptionRenewalPaymentCreated.SubscriptionPeriodCode); await _connection.ExecuteScalarAsync( "INSERT INTO payments.SubscriptionPayments " + "([PaymentId], [PayerId], [Type], [Status], [Period], [Date], " + "[SubscriptionId], [MoneyValue], [MoneyCurrency]) " + "VALUES (@SubscriptionRenewalPaymentId, @PayerId, @Type, @Status, @Period, " + "@OccurredOn, @SubscriptionId, @Value, @Currency)", new { subscriptionRenewalPaymentCreated.SubscriptionRenewalPaymentId, subscriptionRenewalPaymentCreated.PayerId, Type = "Renewal Payment", subscriptionRenewalPaymentCreated.Status, period, subscriptionRenewalPaymentCreated.OccurredOn, subscriptionRenewalPaymentCreated.SubscriptionId, subscriptionRenewalPaymentCreated.Value, subscriptionRenewalPaymentCreated.Currency }); }