| 7285 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import java.util.Collection;
|
|
|
4 |
|
|
|
5 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
6 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
7 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
8 |
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
import javax.servlet.http.HttpSession;
|
|
|
11 |
|
|
|
12 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
13 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
14 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
16 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
17 |
import org.apache.thrift.transport.TTransportException;
|
|
|
18 |
import org.slf4j.Logger;
|
|
|
19 |
import org.slf4j.LoggerFactory;
|
|
|
20 |
|
|
|
21 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
22 |
|
|
|
23 |
@SuppressWarnings("serial")
|
|
|
24 |
@InterceptorRefs({
|
|
|
25 |
@InterceptorRef("defaultStack"),
|
|
|
26 |
@InterceptorRef("login")
|
|
|
27 |
})
|
|
|
28 |
@Results({
|
|
|
29 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
30 |
})
|
|
|
31 |
public class RechargeTopupController extends ActionSupport implements ServletRequestAware {
|
|
|
32 |
|
|
|
33 |
private static Logger logger = LoggerFactory.getLogger(RechargeTopupController.class);
|
|
|
34 |
|
|
|
35 |
private HttpServletRequest request;
|
|
|
36 |
private HttpSession session;
|
|
|
37 |
|
|
|
38 |
private String errorMsg = "";
|
|
|
39 |
|
|
|
40 |
private long companyId;
|
|
|
41 |
private long amount;
|
|
|
42 |
|
|
|
43 |
public String index() {
|
|
|
44 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), request.getServletPath()))
|
|
|
45 |
return "authfail";
|
|
|
46 |
return "authsuccess";
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public String create() {
|
|
|
50 |
//addActionError("Error while writing COD report to the local file system");
|
|
|
51 |
TransactionClient tsc = null;
|
|
|
52 |
try {
|
|
|
53 |
tsc = new TransactionClient();
|
|
|
54 |
} catch (TTransportException e) {
|
|
|
55 |
logger.error("Unable to establish connection to the transaction service", e);
|
|
|
56 |
addActionError("Unable to establish connection to the transaction service");
|
|
|
57 |
}
|
|
|
58 |
Client txnClient = tsc.getClient();
|
|
|
59 |
|
|
|
60 |
try {
|
|
|
61 |
txnClient.topupCompanyWallet(companyId, amount);
|
|
|
62 |
} catch (Exception e){
|
|
|
63 |
logger.error("Unable to establish connection to the transaction service", e);
|
|
|
64 |
addActionError("Unable to top up company wallet");
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
Collection<String> actionErrors = getActionErrors();
|
|
|
68 |
return "authsuccess";
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public long getWalletBalance(long companyId) throws Exception {
|
|
|
72 |
Client txnClient = (new TransactionClient()).getClient();
|
|
|
73 |
return txnClient.getWalletBalanceForCompany(companyId);
|
|
|
74 |
}
|
| 7363 |
rajveer |
75 |
|
|
|
76 |
public long getSaholicRechargeBalance() throws Exception {
|
|
|
77 |
Client txnClient = (new TransactionClient()).getClient();
|
|
|
78 |
return txnClient.getSaholicRechargeBalance();
|
|
|
79 |
}
|
| 7285 |
rajveer |
80 |
|
| 7363 |
rajveer |
81 |
|
|
|
82 |
|
| 7285 |
rajveer |
83 |
@Override
|
|
|
84 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
85 |
this.request = request;
|
|
|
86 |
this.session = request.getSession();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
public String getErrorMsg(){
|
|
|
91 |
return this.errorMsg;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public void setCompanyId(long companyId) {
|
|
|
95 |
this.companyId = companyId;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public long getCompanyId() {
|
|
|
99 |
return companyId;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public void setAmount(long amount) {
|
|
|
103 |
this.amount = amount;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public long getAmount() {
|
|
|
107 |
return amount;
|
|
|
108 |
}
|
|
|
109 |
}
|