fix issues in core
This commit is contained in:
@@ -17,7 +17,7 @@ export interface MoneyProps {
|
||||
}
|
||||
|
||||
export class Money implements IValueObject<MoneyProps> {
|
||||
private static readonly PLATFORM_FEE_PERCENTAGE = 0.10;
|
||||
static readonly DEFAULT_PLATFORM_FEE_PERCENTAGE = 0.10;
|
||||
|
||||
readonly amount: number;
|
||||
readonly currency: Currency;
|
||||
@@ -37,20 +37,24 @@ export class Money implements IValueObject<MoneyProps> {
|
||||
return new Money(amount, currency);
|
||||
}
|
||||
|
||||
// TODO i dont think platform fee must be coupled
|
||||
/**
|
||||
* Calculate platform fee (10%)
|
||||
* Calculate a fee amount for a given percentage.
|
||||
* Defaults to the current platform fee percentage.
|
||||
*/
|
||||
calculatePlatformFee(): Money {
|
||||
const feeAmount = this.amount * Money.PLATFORM_FEE_PERCENTAGE;
|
||||
calculatePlatformFee(platformFeePercentage: number = Money.DEFAULT_PLATFORM_FEE_PERCENTAGE): Money {
|
||||
if (!Number.isFinite(platformFeePercentage) || platformFeePercentage < 0) {
|
||||
throw new RacingDomainValidationError('Platform fee percentage must be a non-negative finite number');
|
||||
}
|
||||
const feeAmount = this.amount * platformFeePercentage;
|
||||
return new Money(feeAmount, this.currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate net amount after platform fee
|
||||
* Calculate net amount after subtracting a fee.
|
||||
* Defaults to subtracting the current platform fee percentage.
|
||||
*/
|
||||
calculateNetAmount(): Money {
|
||||
const platformFee = this.calculatePlatformFee();
|
||||
calculateNetAmount(platformFeePercentage: number = Money.DEFAULT_PLATFORM_FEE_PERCENTAGE): Money {
|
||||
const platformFee = this.calculatePlatformFee(platformFeePercentage);
|
||||
return new Money(this.amount - platformFee.amount, this.currency);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user