This file contains hidden or 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
| function validateAndFormatCard(number: string, type: string) { | |
| const cardType = creditCardTypes[type]; | |
| if (!cardType) { | |
| throw new Error('Unsupported card type'); | |
| } | |
| const isValid = cardType.validate(number); | |
| const formattedNumber = cardType.format(number); | |
| return { | |
| isValid, | |
| formattedNumber, |
This file contains hidden or 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
| interface CreditCardType { | |
| name: string; | |
| logoUri: string; | |
| validate: (number: string) => boolean; | |
| format: (number: string) => string; | |
| } | |
| const creditCardTypes: Record<string, CreditCardType> = { | |
| visa: { | |
| name: "Visa", |
This file contains hidden or 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
| interface PaymentMethod { | |
| process(amount: number): void; | |
| } | |
| const paymentMethods: Record<string, PaymentMethod> = { | |
| credit: { | |
| process(amount: number) { | |
| console.log(`Processing $${amount} via Credit Card`); | |
| // Credit card processing logic... | |
| } |
This file contains hidden or 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
| function processPayment(amount: number, method: string) { | |
| switch (method) { | |
| case 'credit': | |
| // Process credit card payment | |
| break; | |
| case 'paypal': | |
| // Process PayPal payment | |
| break; | |
| case 'bank_transfer': | |
| // Process bank transfer |