forked from johnrogers104/PointOfSaleSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayment.java
62 lines (50 loc) · 1.85 KB
/
Payment.java
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
package ProcessSale;
// Class to make a payment for a sale
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Payment {
// Class variables
String type;
PersistentStorage storage;
Sale finalSale;
// Constructor
public Payment(Sale finalSale, String type) {
this.type = type;
this.finalSale = finalSale;
storage = PersistentStorage.getInstance();
}
// Upload the payment to the database
public boolean finalizePayment() {
// Variables used
DateFormat formatter = new SimpleDateFormat("ddMMyyyy");
String date = formatter.format(finalSale.time);
// Check the type of payment
if (type.equalsIgnoreCase("cash")) {
for (SalesLineItem item: finalSale.cart) {
String id = Integer.toString( (int)(Math.random() * 1000 + 1) );
storage.makePayment(id, "Purch", item.getPrice(), item.quantity, "Cash", date, "null", "null");
}
} else {
try {
Integer.parseInt(type);
for (SalesLineItem item: finalSale.cart) {
String id = Integer.toString( (int)(Math.random() * 1000 + 1) );
storage.makePayment(id, "Purch", item.getPrice(), item.quantity, "Card", date, "null", type);
}
} catch (NumberFormatException e) {
System.out.println("Error: not a credit card number");
return false;
}
}
return true;
}
// Begin a rental with the payment put in and update the database
// May not need to implement
public boolean startRental() {
return finalizePayment();
}
// End the rental and update the database
public boolean endRental() {
return false;
}
}