-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14-payment.js
More file actions
90 lines (77 loc) · 4.09 KB
/
Copy path14-payment.js
File metadata and controls
90 lines (77 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { keyInYNStrict } from "readline-sync";
import { accountingPage } from "./01-start.js";
import readlineSync from "readline-sync";
export default function recordsPage() {
console.clear();
console.log(
"========================================================================================"
);
console.log(`
█████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗████████╗██╗███╗ ██╗ ██████╗
██╔══██╗██╔════╝██╔════╝██╔═══██╗██║ ██║████╗ ██║╚══██╔══╝██║████╗ ██║██╔════╝
███████║██║ ██║ ██║ ██║██║ ██║██╔██╗ ██║ ██║ ██║██╔██╗ ██║██║ ███╗
██╔══██║██║ ██║ ██║ ██║██║ ██║██║╚██╗██║ ██║ ██║██║╚██╗██║██║ ██║
██║ ██║╚██████╗╚██████╗╚██████╔╝╚██████╔╝██║ ╚████║ ██║ ██║██║ ╚████║╚██████╔╝
╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ `);
console.log(
" Payment "
);
console.log(
"========================================================================================"
);
class Payment {
constructor(amount, method, accountBalance) {
this.amount = amount; // Ödeme tutarı
this.method = method; // Ödeme yöntemi (örneğin, kredi kartı, PayPal vb.)
this.accountBalance = accountBalance; // Hesap bakiyesi (kredi kartı, PayPal, banka)
}
// Ödeme durumu kontrolü
checkPaymentStatus() {
if (this.amount <= this.accountBalance) {
return `Payment of ${this.amount} € using ${this.method} was successful.`;
} else {
return `Payment of ${this.amount} € using ${this.method} failed due to insufficient balance.`;
}
}
}
const account = {
creditCard: 1200,
paypal: 1500,
bank: 750,
};
console.log(`1-Credit Card`);
console.log(`2-Paypal`);
console.log(`3-Bank`);
let paymentOption = readlineSync.question(`Select payment option (1-3): `);
paymentOption = parseInt(paymentOption); // Kullanıcının girdiği değeri sayıya çeviriyoruz
// paymentOption değerine göre doğru bakiyeyi seçiyoruz
let selectedMethod;
let selectedBalance;
if (paymentOption === 1) {
selectedMethod = "Credit Card";
selectedBalance = account.creditCard;
} else if (paymentOption === 2) {
selectedMethod = "Paypal";
selectedBalance = account.paypal;
} else if (paymentOption === 3) {
selectedMethod = "Bank";
selectedBalance = account.bank;
} else {
console.log("Invalid option. Please select a valid payment option.");
return; // Hatalı giriş varsa fonksiyonu sonlandırıyoruz
}
// Örnek Kullanımlar
const payment1 = new Payment(1500, selectedMethod, selectedBalance);
console.log(payment1.checkPaymentStatus()); // Ödeme başarılı veya başarısız
const payment2 = new Payment(2000, selectedMethod, selectedBalance);
console.log(payment2.checkPaymentStatus()); // Ödeme başarısız
const payment3 = new Payment(1000, selectedMethod, selectedBalance);
console.log(payment3.checkPaymentStatus()); // Durum başarılı
//-----------------------------------------------------------
const continueApp = keyInYNStrict("Do you want to return to the main menu?");
if (continueApp) {
accountingPage(); // Ana menüye dönüyoruz
} else {
console.log("Exiting the application...");
}
}