-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardPayment.java
More file actions
32 lines (27 loc) · 935 Bytes
/
CardPayment.java
File metadata and controls
32 lines (27 loc) · 935 Bytes
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
package cafeteria;
class CardPayment implements Payment {
private String cardType;
private String transactionID;
public CardPayment(String cardType) {
this.cardType = cardType;
}
@Override
public boolean processPayment(Order order, double amountPaid) throws Exception {
if (amountPaid < 0) {
throw new Exception("Amount cannot be negative.");
}
if (amountPaid >= order.getTotalAmount()) {
transactionID = "TXN" + System.currentTimeMillis(); // Generate unique transaction ID
System.out.println("Payment successful through card. Transaction ID: " + transactionID);
return true;
} else {
throw new Exception("Insufficient card balance. Try again.");
}
}
public String getCardType() {
return cardType;
}
public String getTransactionID() {
return transactionID;
}
}