Last active
October 26, 2022 01:08
-
-
Save axel-andrade/66c52d8bb10053e3d9c92ae6cb47b5e1 to your computer and use it in GitHub Desktop.
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
type Order = { | |
id: number; | |
value: number; | |
customer: string; | |
}; | |
type Card = { | |
id: number; | |
ownerName: string; | |
cardNumber: number; | |
expiryDate: Date; | |
securityCode: string; | |
billingAddress: string; | |
}; | |
class CardProcessorApiXYZ { | |
public async executePayment(card: Card, value: number): Promise<void> { | |
// implementation of card processor api XYZ here | |
} | |
} | |
class CreditPayment { | |
private card: Card; | |
private cardProcessorApiXYZ: CardProcessorApiXYZ; | |
private feeValue: number; | |
private order: Order; | |
constructor(card: Card, order: Order) { | |
this.card = card; | |
this.cardProcessorApiXYZ = new CardProcessorApiXYZ(); | |
this.order = order; | |
this.feeValue = 5; | |
} | |
public async executePayment(): Promise<void> { | |
const finalValue = this.getFinalValue(); | |
await this.cardProcessorApiXYZ.executePayment(this.card, finalValue); | |
} | |
public getFinalValue(): number { | |
const order = this.order; | |
const finalValue = order.value + this.getFee(order.value); | |
return finalValue; | |
} | |
private getFee(value: number): number { | |
return (value * this.feeValue) / 100; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment