| 428 |
ashish |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import org.apache.thrift.TException;
|
|
|
7 |
|
| 555 |
chandransh |
8 |
import in.shop2020.model.v1.order.Order;
|
| 428 |
ashish |
9 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
10 |
import in.shop2020.payments.PaymentException;
|
| 693 |
rajveer |
11 |
import in.shop2020.payments.PaymentStatus;
|
| 428 |
ashish |
12 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
|
|
13 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
14 |
import in.shop2020.utils.Logger;
|
|
|
15 |
|
| 693 |
rajveer |
16 |
|
| 517 |
rajveer |
17 |
public class PayResponseController extends BaseController{
|
| 693 |
rajveer |
18 |
private static final long serialVersionUID = 1L;
|
|
|
19 |
|
| 428 |
ashish |
20 |
public static String AMOUNT = "amount";
|
|
|
21 |
public static String TRACKID = "trackid";
|
|
|
22 |
public static String TRACKID_CANCELLED = "trackId";
|
|
|
23 |
public static String RESULT = "result";
|
|
|
24 |
public static String AUTH = "auth";
|
|
|
25 |
public static String TRANID = "tranid";
|
|
|
26 |
public static String PAYMENTID = "paymentId";
|
|
|
27 |
public static String REF = "ref";
|
|
|
28 |
public static String POSTDATE = "postdate";
|
|
|
29 |
public static String CANCELED = "CANCELED";
|
|
|
30 |
public static String APPROVED = "APPROVED";
|
|
|
31 |
public static String CAPTURED = "CAPTURED";
|
|
|
32 |
|
|
|
33 |
PaymentServiceClient pclient = null;
|
|
|
34 |
TransactionServiceClient tsc = null;
|
|
|
35 |
|
|
|
36 |
String amount;
|
|
|
37 |
String trackId;
|
|
|
38 |
String result;
|
|
|
39 |
String postdate;
|
|
|
40 |
String auth;
|
|
|
41 |
String ref;
|
|
|
42 |
String tranId;
|
|
|
43 |
String paymentId;
|
| 693 |
rajveer |
44 |
String sessionId;
|
|
|
45 |
|
| 428 |
ashish |
46 |
String message = "Unable to process the payment. PLease try Again.";
|
|
|
47 |
|
| 517 |
rajveer |
48 |
public PayResponseController(){
|
| 428 |
ashish |
49 |
super();
|
|
|
50 |
try {
|
|
|
51 |
pclient = new PaymentServiceClient();
|
|
|
52 |
tsc = new TransactionServiceClient();
|
|
|
53 |
} catch (Exception e) {
|
|
|
54 |
Logger.log("Could not initialize the paymentservice client", this);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
| 693 |
rajveer |
58 |
public String index() throws IOException, SecurityException{
|
| 428 |
ashish |
59 |
amount = this.request.getParameter(AMOUNT);
|
|
|
60 |
paymentId = this.request.getParameter(PAYMENTID);
|
|
|
61 |
tranId = this.request.getParameter(TRANID);
|
|
|
62 |
result = this.request.getParameter(RESULT);
|
|
|
63 |
if (result.equalsIgnoreCase(CANCELED)){
|
|
|
64 |
trackId = this.request.getParameter(TRACKID_CANCELLED);
|
|
|
65 |
}else{
|
|
|
66 |
trackId = this.request.getParameter(TRACKID);
|
|
|
67 |
}
|
|
|
68 |
auth = this.request.getParameter(AUTH);
|
|
|
69 |
ref = this.request.getParameter(REF);
|
|
|
70 |
postdate = this.request.getParameter(POSTDATE);
|
| 693 |
rajveer |
71 |
sessionId = this.request.getSession().getId();
|
|
|
72 |
|
| 428 |
ashish |
73 |
//update the payment info object
|
|
|
74 |
try {
|
| 693 |
rajveer |
75 |
if(result.trim().equals(CAPTURED)){
|
|
|
76 |
String message = "Payment successful";
|
|
|
77 |
pclient.getClient().updatePaymentDetails(Long.parseLong(trackId), paymentId, sessionId, result, message, tranId, auth, ref, null, PaymentStatus.SUCCESS, null);
|
|
|
78 |
return "index";
|
|
|
79 |
}else{
|
|
|
80 |
String message = "Unable to process the payment.";
|
|
|
81 |
addActionError("Previous payment failed. Try again.");
|
|
|
82 |
pclient.getClient().updatePaymentDetails(Long.parseLong(trackId), paymentId, sessionId, result, message, tranId, auth, ref, null, PaymentStatus.FAILED, null);
|
|
|
83 |
return "failure";
|
|
|
84 |
}
|
| 428 |
ashish |
85 |
|
|
|
86 |
} catch (NumberFormatException e) {
|
|
|
87 |
Logger.log(e.toString(), this);
|
|
|
88 |
} catch (PaymentException e) {
|
|
|
89 |
|
|
|
90 |
Logger.log(e.toString(), this);
|
|
|
91 |
} catch (TException e) {
|
|
|
92 |
|
|
|
93 |
Logger.log(e.toString(), this);
|
|
|
94 |
}
|
| 693 |
rajveer |
95 |
return "index";
|
| 428 |
ashish |
96 |
}
|
|
|
97 |
|
| 693 |
rajveer |
98 |
public List<Order> getOrders() throws TransactionServiceException, TException{
|
|
|
99 |
//FIXME
|
|
|
100 |
return tsc.getClient().getOrdersForTransaction(1);
|
| 428 |
ashish |
101 |
|
| 485 |
rajveer |
102 |
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public String getMessage(){
|
|
|
106 |
return this.message;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
}
|