forked from kgrzybek/modular-monolith-with-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pricing Strategies for Subscriptions (Strategy Pattern)
- Loading branch information
Showing
13 changed files
with
160 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...yments/Domain/PriceListItems/PricingStrategies/DirectValueFromPriceListPricingStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.SeedWork; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.Subscriptions; | ||
|
||
namespace CompanyName.MyMeetings.Modules.Payments.Domain.PriceListItems.PricingStrategies | ||
{ | ||
public class DirectValueFromPriceListPricingStrategy : IPricingStrategy | ||
{ | ||
private readonly List<PriceListItemData> _items; | ||
|
||
public DirectValueFromPriceListPricingStrategy(List<PriceListItemData> items) | ||
{ | ||
_items = items; | ||
} | ||
|
||
public MoneyValue GetPrice( | ||
string countryCode, | ||
SubscriptionPeriod subscriptionPeriod, | ||
PriceListItemCategory category) | ||
{ | ||
var priceListItem = _items.Single(x => | ||
x.CountryCode == countryCode && x.SubscriptionPeriod == subscriptionPeriod && | ||
x.Category == category); | ||
|
||
return priceListItem.Value; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Modules/Payments/Domain/PriceListItems/PricingStrategies/DirectValuePricingStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.SeedWork; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.Subscriptions; | ||
|
||
namespace CompanyName.MyMeetings.Modules.Payments.Domain.PriceListItems.PricingStrategies | ||
{ | ||
public class DirectValuePricingStrategy : IPricingStrategy | ||
{ | ||
private readonly MoneyValue _directValue; | ||
|
||
public DirectValuePricingStrategy(MoneyValue directValue) | ||
{ | ||
_directValue = directValue; | ||
} | ||
|
||
public MoneyValue GetPrice(string countryCode, SubscriptionPeriod subscriptionPeriod, PriceListItemCategory category) | ||
{ | ||
return _directValue; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ts/Domain/PriceListItems/PricingStrategies/DiscountedValueFromPriceListPricingStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.SeedWork; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.Subscriptions; | ||
|
||
namespace CompanyName.MyMeetings.Modules.Payments.Domain.PriceListItems.PricingStrategies | ||
{ | ||
public class DiscountedValueFromPriceListPricingStrategy : IPricingStrategy | ||
{ | ||
private readonly List<PriceListItemData> _items; | ||
|
||
private readonly MoneyValue _discountValue; | ||
|
||
public DiscountedValueFromPriceListPricingStrategy( | ||
List<PriceListItemData> items, | ||
MoneyValue discountValue) | ||
{ | ||
_items = items; | ||
_discountValue = discountValue; | ||
} | ||
|
||
public MoneyValue GetPrice(string countryCode, SubscriptionPeriod subscriptionPeriod, PriceListItemCategory category) | ||
{ | ||
var priceListItem = _items.Single(x => | ||
x.CountryCode == countryCode && x.SubscriptionPeriod == subscriptionPeriod && | ||
x.Category == category); | ||
|
||
return priceListItem.Value - _discountValue; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Modules/Payments/Domain/PriceListItems/PricingStrategies/IPricingStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.SeedWork; | ||
using CompanyName.MyMeetings.Modules.Payments.Domain.Subscriptions; | ||
|
||
namespace CompanyName.MyMeetings.Modules.Payments.Domain.PriceListItems.PricingStrategies | ||
{ | ||
public interface IPricingStrategy | ||
{ | ||
MoneyValue GetPrice( | ||
string countryCode, | ||
SubscriptionPeriod subscriptionPeriod, | ||
PriceListItemCategory category); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Modules/Payments/Domain/SeedWork/Rules/MoneyMustHaveTheSameCurrencyRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using CompanyName.MyMeetings.BuildingBlocks.Domain; | ||
|
||
namespace CompanyName.MyMeetings.Modules.Payments.Domain.SeedWork.Rules | ||
{ | ||
public class MoneyMustHaveTheSameCurrencyRule : IBusinessRule | ||
{ | ||
private readonly MoneyValue _left; | ||
|
||
private readonly MoneyValue _right; | ||
|
||
public MoneyMustHaveTheSameCurrencyRule(MoneyValue left, MoneyValue right) | ||
{ | ||
_left = left; | ||
_right = right; | ||
} | ||
|
||
public bool IsBroken() => _left.Currency != _right.Currency; | ||
|
||
public string Message => "Currency of money must be the same."; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters