-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPayment.java
More file actions
67 lines (59 loc) · 2.69 KB
/
Copy pathPayment.java
File metadata and controls
67 lines (59 loc) · 2.69 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
package model;
import java.time.LocalDateTime;
public abstract class Payment {
private String transactionId;
private double amount;
private LocalDateTime date;
private String paymentDate;
private String bookingId;
private String status;
private String username;
private String paymentType;
public Payment(String transactionId, double amount, String bookingId, String username, String paymentType) {
this.transactionId = transactionId;
this.amount = amount;
this.date = LocalDateTime.now();
this.paymentDate = date.toLocalDate().toString();
this.bookingId = bookingId;
this.status = "PENDING";
this.username = username;
this.paymentType = paymentType;
}
// Getters and Setters
public String getTransactionId() { return transactionId; }
public double getAmount() { return amount; }
public LocalDateTime getDate() { return date; }
public String getPaymentDate() { return paymentDate; }
public String getBookingId() { return bookingId; }
public String getStatus() { return status; }
public String getUsername() { return username; }
public String getPaymentType() { return paymentType; }
public void setStatus(String status) { this.status = status; }
public static double calculateFees(String sessionType, String extras, String paymentType) {
double sessionFee = switch (sessionType != null ? sessionType.toLowerCase() : "") {
case "wedding" -> 500.0;
case "portrait" -> 200.0;
case "event" -> 300.0;
default -> 100.0;
};
double extraFee = (extras != null && !extras.isEmpty()) ? extras.split(",").length * 50.0 : 0.0;
double tax = (sessionFee + extraFee) * 0.1;
double total = sessionFee + extraFee + tax;
return "Cash".equalsIgnoreCase(paymentType) ? total * 0.95 : total;
}
public String getFeeBreakdown(String sessionType, String extras) {
double sessionFee = switch (sessionType != null ? sessionType.toLowerCase() : "") {
case "wedding" -> 500.0;
case "portrait" -> 200.0;
case "event" -> 300.0;
default -> 100.0;
};
double extraFee = (extras != null && !extras.isEmpty()) ? extras.split(",").length * 50.0 : 0.0;
double tax = (sessionFee + extraFee) * 0.1;
return String.format("Session: $%.2f, Extras: $%.2f, Tax: $%.2f", sessionFee, extraFee, tax);
}
public double getTotal(String sessionType, String extras) {
return calculateFees(sessionType, extras, paymentType);
}
public abstract boolean processPayment();
}