private PurchaseInfo(MoneyAmount grossAmount, MoneyAmount netAmount, MoneyAmount vatAmount, VatRate vatRate) { GrossAmount = grossAmount; NetAmount = netAmount; VatAmount = vatAmount; VatRate = vatRate; }
private static void ThrowIfInputNull(VatRate vatRate, MoneyAmount amount) { if (vatRate == null) { throw new ArgumentException(nameof(vatRate)); } if (amount == null) { throw new ArgumentException(nameof(amount)); } }
public static PurchaseInfo CreateWithVatAmount(VatRate vatRate, MoneyAmount vatAmount) { ThrowIfInputNull(vatRate, vatAmount); decimal netAmount = vatAmount.Value / vatRate.Value; decimal grossAmount = netAmount + vatAmount.Value; var netAmountResult = MoneyAmount.Create(netAmount); var grossAmountResult = MoneyAmount.Create(grossAmount); if (netAmountResult.IsFailure || grossAmountResult.IsFailure) { throw new ArgumentException(); } return(new PurchaseInfo(grossAmountResult.Value, netAmountResult.Value, vatAmount, vatRate)); }