42 lines
996 B
TypeScript
42 lines
996 B
TypeScript
export type CheckoutConfirmationDecision = 'confirmed' | 'cancelled' | 'timeout';
|
|
|
|
const VALID_DECISIONS: CheckoutConfirmationDecision[] = [
|
|
'confirmed',
|
|
'cancelled',
|
|
'timeout',
|
|
];
|
|
|
|
export class CheckoutConfirmation {
|
|
private readonly _value: CheckoutConfirmationDecision;
|
|
|
|
private constructor(value: CheckoutConfirmationDecision) {
|
|
this._value = value;
|
|
}
|
|
|
|
static create(value: CheckoutConfirmationDecision): CheckoutConfirmation {
|
|
if (!VALID_DECISIONS.includes(value)) {
|
|
throw new Error('Invalid checkout confirmation decision');
|
|
}
|
|
return new CheckoutConfirmation(value);
|
|
}
|
|
|
|
get value(): CheckoutConfirmationDecision {
|
|
return this._value;
|
|
}
|
|
|
|
equals(other: CheckoutConfirmation): boolean {
|
|
return this._value === other._value;
|
|
}
|
|
|
|
isConfirmed(): boolean {
|
|
return this._value === 'confirmed';
|
|
}
|
|
|
|
isCancelled(): boolean {
|
|
return this._value === 'cancelled';
|
|
}
|
|
|
|
isTimeout(): boolean {
|
|
return this._value === 'timeout';
|
|
}
|
|
} |