| 21464 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21468 |
kshitij.so |
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
| 21464 |
kshitij.so |
6 |
|
|
|
7 |
import javax.servlet.http.HttpServletRequest;
|
|
|
8 |
|
| 21505 |
kshitij.so |
9 |
import org.apache.thrift.TException;
|
|
|
10 |
import org.apache.thrift.transport.TTransportException;
|
| 21464 |
kshitij.so |
11 |
import org.slf4j.Logger;
|
|
|
12 |
import org.slf4j.LoggerFactory;
|
| 21505 |
kshitij.so |
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21464 |
kshitij.so |
14 |
import org.springframework.http.MediaType;
|
|
|
15 |
import org.springframework.http.ResponseEntity;
|
|
|
16 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
17 |
import org.springframework.transaction.annotation.Transactional;
|
| 21514 |
kshitij.so |
18 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21464 |
kshitij.so |
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
22 |
|
| 21505 |
kshitij.so |
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21464 |
kshitij.so |
24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21468 |
kshitij.so |
25 |
import com.spice.profitmandi.common.util.Utils;
|
| 22931 |
ashik.ali |
26 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21735 |
ashik.ali |
27 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
28 |
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
|
|
|
29 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
30 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
31 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
32 |
import com.spice.profitmandi.thrift.clients.PaymentClient;
|
| 21464 |
kshitij.so |
33 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
| 21514 |
kshitij.so |
34 |
import com.spice.profitmandi.web.req.CreateRechargeRequest;
|
| 21505 |
kshitij.so |
35 |
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
|
| 21514 |
kshitij.so |
36 |
import com.spice.profitmandi.web.res.CreateRechargeResponse;
|
| 21534 |
kshitij.so |
37 |
import com.spice.profitmandi.web.res.MyRechargesResponse;
|
| 21517 |
kshitij.so |
38 |
import com.spice.profitmandi.web.res.RechargeResultPojo;
|
| 21464 |
kshitij.so |
39 |
|
| 21468 |
kshitij.so |
40 |
import in.shop2020.model.v1.order.DenominationType;
|
| 21464 |
kshitij.so |
41 |
import in.shop2020.model.v1.order.DeviceNumberInfo;
|
| 21514 |
kshitij.so |
42 |
import in.shop2020.model.v1.order.OrderType;
|
| 21468 |
kshitij.so |
43 |
import in.shop2020.model.v1.order.RechargeDenomination;
|
| 21514 |
kshitij.so |
44 |
import in.shop2020.model.v1.order.RechargeOrder;
|
|
|
45 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
| 21464 |
kshitij.so |
46 |
import in.shop2020.model.v1.order.RechargeType;
|
| 21514 |
kshitij.so |
47 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 21505 |
kshitij.so |
48 |
import in.shop2020.model.v1.order.UserWallet;
|
| 21514 |
kshitij.so |
49 |
import in.shop2020.payments.Payment;
|
|
|
50 |
import in.shop2020.payments.PaymentException;
|
|
|
51 |
import in.shop2020.payments.PaymentStatus;
|
| 21464 |
kshitij.so |
52 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
53 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
54 |
import io.swagger.annotations.ApiOperation;
|
|
|
55 |
|
|
|
56 |
@Controller
|
| 22040 |
amit.gupta |
57 |
@Transactional(rollbackFor=Throwable.class)
|
| 21464 |
kshitij.so |
58 |
public class RechargeController {
|
|
|
59 |
|
|
|
60 |
private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
|
| 21514 |
kshitij.so |
61 |
private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
|
| 23101 |
amit.gupta |
62 |
private static final String X_REAL_IP = "X-Real-IP";
|
| 21464 |
kshitij.so |
63 |
|
| 21505 |
kshitij.so |
64 |
@Autowired
|
| 22931 |
ashik.ali |
65 |
private UserAccountRepository userAccountRepository;
|
| 21514 |
kshitij.so |
66 |
|
|
|
67 |
@Autowired
|
| 22931 |
ashik.ali |
68 |
private UserRepository userRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private ResponseSender<?> responseSender;
|
| 21514 |
kshitij.so |
72 |
|
| 21464 |
kshitij.so |
73 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
74 |
@ApiImplicitParams({
|
|
|
75 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
76 |
required = true, dataType = "string", paramType = "header")
|
|
|
77 |
})
|
|
|
78 |
@ApiOperation(value = "")
|
|
|
79 |
public ResponseEntity<?> getServiceProvider(HttpServletRequest request, @RequestParam(value="deviceNumber") String deviceNumber, @RequestParam(value="rechargeType") String rechargeType){
|
|
|
80 |
DeviceNumberInfo deviceInfo = null;
|
|
|
81 |
TransactionClient tcl;
|
|
|
82 |
try {
|
|
|
83 |
tcl = new TransactionClient();
|
|
|
84 |
deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
|
|
|
85 |
} catch (Exception e) {
|
|
|
86 |
log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " + rechargeType, e);
|
|
|
87 |
}
|
| 22931 |
ashik.ali |
88 |
return responseSender.ok(deviceInfo);
|
| 21464 |
kshitij.so |
89 |
}
|
| 21505 |
kshitij.so |
90 |
|
| 21468 |
kshitij.so |
91 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
92 |
@ApiImplicitParams({
|
|
|
93 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
94 |
required = true, dataType = "string", paramType = "header")
|
|
|
95 |
})
|
|
|
96 |
@ApiOperation(value = "")
|
|
|
97 |
public ResponseEntity<?> getAllDenominations(HttpServletRequest request, @RequestParam(value="operatorId") long operatorId, @RequestParam(value="circleCode") String circleCode, @RequestParam(value="denominationType") String denominationType){
|
|
|
98 |
List<RechargeDenomination> rechargeDenominations = new ArrayList<RechargeDenomination>();
|
|
|
99 |
TransactionClient tcl;
|
|
|
100 |
try {
|
|
|
101 |
tcl = new TransactionClient();
|
|
|
102 |
rechargeDenominations = tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
|
|
|
103 |
} catch (Exception e) {
|
|
|
104 |
log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " + circleCode + " and DenominationType : " + denominationType, e);
|
|
|
105 |
}
|
| 22931 |
ashik.ali |
106 |
return responseSender.ok(rechargeDenominations);
|
| 21468 |
kshitij.so |
107 |
}
|
| 21505 |
kshitij.so |
108 |
|
| 21468 |
kshitij.so |
109 |
@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
110 |
@ApiImplicitParams({
|
|
|
111 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
112 |
required = true, dataType = "string", paramType = "header")
|
|
|
113 |
})
|
|
|
114 |
@ApiOperation(value = "")
|
|
|
115 |
public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
|
|
|
116 |
Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
|
| 22931 |
ashik.ali |
117 |
return responseSender.ok(mobileProviderMap);
|
| 21468 |
kshitij.so |
118 |
}
|
| 21505 |
kshitij.so |
119 |
|
| 21468 |
kshitij.so |
120 |
@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
121 |
@ApiImplicitParams({
|
|
|
122 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
123 |
required = true, dataType = "string", paramType = "header")
|
|
|
124 |
})
|
|
|
125 |
@ApiOperation(value = "")
|
|
|
126 |
public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
|
|
|
127 |
Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
|
| 22931 |
ashik.ali |
128 |
return responseSender.ok(dthProviderMap);
|
| 21468 |
kshitij.so |
129 |
}
|
|
|
130 |
|
| 21505 |
kshitij.so |
131 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
132 |
@ApiImplicitParams({
|
|
|
133 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
134 |
required = true, dataType = "string", paramType = "header")
|
|
|
135 |
})
|
|
|
136 |
@ApiOperation(value = "")
|
| 22931 |
ashik.ali |
137 |
public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
|
|
|
138 |
throws ProfitMandiBusinessException{
|
| 21505 |
kshitij.so |
139 |
int userId = (int)request.getAttribute("userId");
|
|
|
140 |
UserAccounts userAccount = null;
|
|
|
141 |
UserWallet wallet = null;
|
|
|
142 |
if (rechargeAmount <=0){
|
| 22931 |
ashik.ali |
143 |
return responseSender.badRequest(null);
|
| 21505 |
kshitij.so |
144 |
}
|
| 21514 |
kshitij.so |
145 |
|
| 22931 |
ashik.ali |
146 |
userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
|
|
|
147 |
|
| 21505 |
kshitij.so |
148 |
try {
|
|
|
149 |
TransactionClient tc = new TransactionClient();
|
|
|
150 |
wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
|
|
|
151 |
} catch (NumberFormatException | TException e) {
|
| 22931 |
ashik.ali |
152 |
return responseSender.internalServerError(e);
|
| 21505 |
kshitij.so |
153 |
}
|
| 21514 |
kshitij.so |
154 |
|
| 21505 |
kshitij.so |
155 |
ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
|
|
|
156 |
crr.setWalletAmount(wallet.getAmount());
|
|
|
157 |
crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
|
|
|
158 |
crr.setCanProceed(true);
|
|
|
159 |
if (crr.getWalletAmountLeft() < 0){
|
|
|
160 |
crr.setCanProceed(false);
|
|
|
161 |
crr.setReason("You don't have sufficient wallet balance");
|
|
|
162 |
}
|
| 22931 |
ashik.ali |
163 |
return responseSender.ok(crr);
|
| 21505 |
kshitij.so |
164 |
}
|
| 21514 |
kshitij.so |
165 |
|
| 21505 |
kshitij.so |
166 |
@RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
167 |
@ApiImplicitParams({
|
|
|
168 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
169 |
required = true, dataType = "string", paramType = "header")
|
|
|
170 |
})
|
| 22931 |
ashik.ali |
171 |
public ResponseEntity<?> createRecharge(HttpServletRequest request, @RequestBody CreateRechargeRequest createRechargeRequest)
|
|
|
172 |
throws ProfitMandiBusinessException{
|
| 21514 |
kshitij.so |
173 |
String ipAddress = remoteAddr(request);
|
|
|
174 |
String errorMessage = validateRecharge(RechargeType.valueOf(createRechargeRequest.getRechargeType()), createRechargeRequest.getNumber(), createRechargeRequest.getOperatorId(), ipAddress);
|
|
|
175 |
CreateRechargeResponse crr = new CreateRechargeResponse();
|
|
|
176 |
if(!errorMessage.equals("SUCCESS")){
|
|
|
177 |
crr.setReason(errorMessage);
|
|
|
178 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
179 |
return responseSender.badRequest(crr);
|
| 21514 |
kshitij.so |
180 |
}
|
|
|
181 |
int userId = (int)request.getAttribute("userId");
|
|
|
182 |
UserAccounts userAccount = null;
|
|
|
183 |
UserWallet wallet = null;
|
|
|
184 |
if (createRechargeRequest.getRechargeAmount() <=0){
|
|
|
185 |
crr.setReason("Illegal recharge amount");
|
|
|
186 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
187 |
return responseSender.badRequest(crr);
|
| 21514 |
kshitij.so |
188 |
}
|
|
|
189 |
|
| 22931 |
ashik.ali |
190 |
userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
|
|
|
191 |
|
| 21514 |
kshitij.so |
192 |
try {
|
|
|
193 |
TransactionClient tc = new TransactionClient();
|
|
|
194 |
wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
|
|
|
195 |
} catch (NumberFormatException | TException e) {
|
|
|
196 |
log.error("Unable to get user wallet ",e);
|
|
|
197 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
198 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
199 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
200 |
}
|
|
|
201 |
|
|
|
202 |
if (wallet.getAmount() < createRechargeRequest.getRechargeAmount()){
|
|
|
203 |
crr.setReason("You don't have sufficient wallet balance.");
|
|
|
204 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
205 |
return responseSender.badRequest(crr);
|
| 21514 |
kshitij.so |
206 |
}
|
|
|
207 |
|
|
|
208 |
User user = null;
|
|
|
209 |
try {
|
|
|
210 |
user = userRepository.selectById(userId);
|
|
|
211 |
} catch (ProfitMandiBusinessException e) {
|
|
|
212 |
log.error("Unable to get user",e);
|
|
|
213 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
214 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
215 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
216 |
}
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
RechargeOrder t_rechargeOrder = new RechargeOrder();
|
|
|
220 |
t_rechargeOrder.setTotalAmount(createRechargeRequest.getRechargeAmount());
|
|
|
221 |
t_rechargeOrder.setUserEmailId(user.getEmailId());
|
| 21519 |
kshitij.so |
222 |
t_rechargeOrder.setUserId(Long.valueOf(userAccount.getAccount_key()));
|
| 21514 |
kshitij.so |
223 |
t_rechargeOrder.setDeviceNumber(createRechargeRequest.getNumber());
|
|
|
224 |
t_rechargeOrder.setPlan(createRechargeRequest.getPlan()==null?"":createRechargeRequest.getPlan());
|
|
|
225 |
t_rechargeOrder.setOperatorId(createRechargeRequest.getOperatorId());
|
|
|
226 |
t_rechargeOrder.setRechargeType(RechargeType.valueOf(createRechargeRequest.getRechargeType()));
|
|
|
227 |
t_rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
|
|
|
228 |
t_rechargeOrder.setOrderType(OrderType.B2C);
|
|
|
229 |
t_rechargeOrder.setWalletAmount(createRechargeRequest.getRechargeAmount());
|
|
|
230 |
t_rechargeOrder.setCouponAmount(0);
|
|
|
231 |
t_rechargeOrder.setCouponCode("");
|
|
|
232 |
t_rechargeOrder.setIpAddress(ipAddress);
|
|
|
233 |
TransactionClient tc = null;
|
|
|
234 |
RechargeOrder rechargeOrder;
|
|
|
235 |
try {
|
|
|
236 |
tc = new TransactionClient();
|
|
|
237 |
rechargeOrder = tc.getClient().createRechargeOrder(t_rechargeOrder);
|
|
|
238 |
} catch (TransactionServiceException | TException e) {
|
|
|
239 |
log.error("Unable to create recharge order",e);
|
|
|
240 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
241 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
242 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
243 |
}
|
|
|
244 |
|
|
|
245 |
log.info("Recharge Order:" + rechargeOrder);
|
|
|
246 |
PaymentClient paymentServiceClient = null;
|
|
|
247 |
try {
|
|
|
248 |
paymentServiceClient = new PaymentClient();
|
|
|
249 |
} catch (TTransportException e) {
|
|
|
250 |
log.error("Unable to create payment client",e);
|
|
|
251 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
252 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
253 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
254 |
}
|
|
|
255 |
try {
|
|
|
256 |
RechargeOrder d_rechargeOrder = tc.getClient().getRechargeOrder(rechargeOrder.getId());
|
|
|
257 |
List<Payment> payments = paymentServiceClient.getClient().getPaymentForRechargeTxnId(d_rechargeOrder.getTransactionId());
|
|
|
258 |
if(payments.size() > 0) {
|
|
|
259 |
throw new PaymentException(d_rechargeOrder.getId(), "Payment already exists for recharge");
|
|
|
260 |
}
|
|
|
261 |
Long merchantPaymentId = 0l;
|
|
|
262 |
if (d_rechargeOrder.getWalletAmount() + d_rechargeOrder.getCouponAmount() != d_rechargeOrder.getTotalAmount()) {
|
|
|
263 |
log.error("Wallet amount : " + d_rechargeOrder.getWalletAmount() + ", coupon amount : " + d_rechargeOrder.getCouponAmount() + " and total amount : " + d_rechargeOrder.getTotalAmount());
|
|
|
264 |
merchantPaymentId = paymentServiceClient.getClient().createPayment(d_rechargeOrder.getUserId(), d_rechargeOrder.getTotalAmount(), 8, d_rechargeOrder.getTransactionId(), true);
|
|
|
265 |
paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, "","", "0", "", "", "", "", "", PaymentStatus.FAILED, "", null);
|
|
|
266 |
tc.getClient().updateRechargeOrderStatus(d_rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_FAILED);
|
|
|
267 |
} else {
|
|
|
268 |
merchantPaymentId = paymentServiceClient.getClient().createPayment(d_rechargeOrder.getUserId(), d_rechargeOrder.getTotalAmount(), 8, d_rechargeOrder.getTransactionId(), true);
|
|
|
269 |
//Update payment status as authorized
|
|
|
270 |
paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, "","", "0", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
|
|
|
271 |
tc.getClient().updateRechargeOrderStatus(d_rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_SUCCESSFUL);
|
|
|
272 |
}
|
|
|
273 |
crr.setRechargeOrderId(d_rechargeOrder.getId());
|
|
|
274 |
crr.setResult(true);
|
|
|
275 |
} catch (Exception e) {
|
|
|
276 |
log.error("Unable to mark the payment as authorized", e);
|
|
|
277 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
278 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
279 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
280 |
}
|
| 23037 |
ashik.ali |
281 |
return responseSender.ok(crr);
|
| 21505 |
kshitij.so |
282 |
}
|
| 21514 |
kshitij.so |
283 |
|
| 21517 |
kshitij.so |
284 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_RESULT , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
285 |
@ApiImplicitParams({
|
|
|
286 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
287 |
required = true, dataType = "string", paramType = "header")
|
|
|
288 |
})
|
|
|
289 |
public ResponseEntity<?> rechargeResult(HttpServletRequest request, @RequestParam(value="rechargeOrderId") long rechargeOrderId){
|
|
|
290 |
TransactionClient tc=null;
|
|
|
291 |
RechargeOrder rechargeOrder = null;
|
|
|
292 |
RechargeResultPojo rrp = null;
|
|
|
293 |
try {
|
|
|
294 |
tc = new TransactionClient();
|
|
|
295 |
rechargeOrder = tc.getClient().getRechargeOrder(rechargeOrderId);
|
|
|
296 |
} catch (TransactionServiceException | TException e) {
|
|
|
297 |
// return with internal server error
|
|
|
298 |
e.printStackTrace();
|
|
|
299 |
rrp = new RechargeResultPojo();
|
|
|
300 |
rrp.setIsError(true);
|
|
|
301 |
rrp.setDetailDisplayMessage("We are experiencing some problem right now.");
|
| 22931 |
ashik.ali |
302 |
return responseSender.internalServerError(e);
|
| 21517 |
kshitij.so |
303 |
}
|
|
|
304 |
if (rechargeOrder == null){
|
|
|
305 |
rrp = new RechargeResultPojo();
|
|
|
306 |
rrp.setIsError(true);
|
|
|
307 |
rrp.setDetailDisplayMessage("Recharge order doesnot exist in our system.");
|
| 22931 |
ashik.ali |
308 |
return responseSender.badRequest(rrp);
|
| 21517 |
kshitij.so |
309 |
}
|
|
|
310 |
String[] os = Utils.getOrderStatus(rechargeOrder.getStatus());
|
|
|
311 |
rrp = new RechargeResultPojo();
|
|
|
312 |
rrp.setRechargeDeviceNumber(rechargeOrder.getDeviceNumber());
|
|
|
313 |
rrp.setRechargeDisplayId(rechargeOrder.getDisplayId());
|
|
|
314 |
rrp.setTotalAmount(rechargeOrder.getTotalAmount() + "");
|
|
|
315 |
rrp.setRechargeProvider(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
316 |
rrp.setIsError(Boolean.parseBoolean(os[0]));
|
|
|
317 |
rrp.setRechargeStatus(os[1]);
|
|
|
318 |
rrp.setDetailDisplayMessage(os[2]);
|
| 21523 |
kshitij.so |
319 |
if (rechargeOrder.getStatus().equals(RechargeOrderStatus.RECHARGE_UNKNOWN)){
|
| 21517 |
kshitij.so |
320 |
rrp.setPoll(true);
|
|
|
321 |
}
|
| 23098 |
amit.gupta |
322 |
return responseSender.ok(rrp);
|
| 21517 |
kshitij.so |
323 |
}
|
| 21514 |
kshitij.so |
324 |
|
| 21517 |
kshitij.so |
325 |
@RequestMapping(value = ProfitMandiConstants.URL_POLL_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
326 |
@ApiImplicitParams({
|
|
|
327 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
328 |
required = true, dataType = "string", paramType = "header")
|
|
|
329 |
})
|
| 21519 |
kshitij.so |
330 |
public ResponseEntity<?> pollRechargeResult(HttpServletRequest request, @RequestParam(value="rechargeOrderId") long rechargeOrderId, @RequestParam(value="finalCall") boolean finalCall){
|
| 21517 |
kshitij.so |
331 |
TransactionClient transactionServiceClient = null;
|
|
|
332 |
RechargeOrder t_rechargeOrder = null;
|
|
|
333 |
RechargeResultPojo rrp = null;
|
|
|
334 |
try{
|
|
|
335 |
transactionServiceClient = new TransactionClient();
|
|
|
336 |
t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
|
|
|
337 |
}
|
|
|
338 |
catch(Exception e){
|
|
|
339 |
rrp = new RechargeResultPojo();
|
|
|
340 |
rrp.setRechargeStatus("");
|
| 22931 |
ashik.ali |
341 |
return responseSender.internalServerError(e);
|
| 21517 |
kshitij.so |
342 |
}
|
|
|
343 |
if (t_rechargeOrder == null){
|
|
|
344 |
rrp = new RechargeResultPojo();
|
|
|
345 |
rrp.setRechargeStatus("");
|
| 22931 |
ashik.ali |
346 |
return responseSender.badRequest(new RechargeResultPojo());
|
| 21517 |
kshitij.so |
347 |
}
|
|
|
348 |
rrp = new RechargeResultPojo();
|
| 22411 |
amit.gupta |
349 |
String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
|
|
|
350 |
rrp.setIsError(Boolean.parseBoolean(os[0]));
|
|
|
351 |
rrp.setRechargeStatus(os[1]);
|
|
|
352 |
rrp.setDetailDisplayMessage(os[2]);
|
| 22931 |
ashik.ali |
353 |
return responseSender.ok(rrp);
|
| 21517 |
kshitij.so |
354 |
}
|
| 21534 |
kshitij.so |
355 |
|
|
|
356 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
357 |
@ApiImplicitParams({
|
|
|
358 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
359 |
required = true, dataType = "string", paramType = "header")
|
|
|
360 |
})
|
| 22931 |
ashik.ali |
361 |
public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
|
| 21534 |
kshitij.so |
362 |
TransactionClient tc=null;
|
|
|
363 |
int userId = (int)request.getAttribute("userId");
|
|
|
364 |
UserAccounts userAccount;
|
|
|
365 |
List<RechargeOrder> rechargeOrders = null;
|
| 22931 |
ashik.ali |
366 |
|
|
|
367 |
userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
|
|
|
368 |
|
| 21534 |
kshitij.so |
369 |
try {
|
|
|
370 |
tc = new TransactionClient();
|
|
|
371 |
rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccount_key()), offset, limit);
|
|
|
372 |
} catch (Exception e) {
|
|
|
373 |
log.error("Unable to get recharge order list",e);
|
| 22931 |
ashik.ali |
374 |
return responseSender.internalServerError(e);
|
| 21534 |
kshitij.so |
375 |
}
|
|
|
376 |
List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
|
|
|
377 |
for (RechargeOrder rechargeOrder : rechargeOrders){
|
|
|
378 |
MyRechargesResponse rp = new MyRechargesResponse();
|
|
|
379 |
if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
|
|
|
380 |
rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
381 |
rp.setOperatorType("MOBILE");
|
|
|
382 |
}
|
|
|
383 |
if(rechargeOrder.getRechargeType() == RechargeType.DTH){
|
|
|
384 |
rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
385 |
rp.setOperatorType("DTH");
|
|
|
386 |
}
|
|
|
387 |
rp.setOrderId(rechargeOrder.getId());
|
|
|
388 |
rp.setOperatorId(rechargeOrder.getOperatorId());
|
|
|
389 |
rp.setDate(rechargeOrder.getCreationTimestamp());
|
|
|
390 |
rp.setNumber(rechargeOrder.getDeviceNumber());
|
|
|
391 |
rp.setAmount(rechargeOrder.getTotalAmount());
|
|
|
392 |
rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
|
|
|
393 |
rp.setDisplayOrderId(rechargeOrder.getDisplayId());
|
|
|
394 |
myRechargesList.add(rp);
|
|
|
395 |
}
|
| 22931 |
ashik.ali |
396 |
return responseSender.ok(myRechargesList);
|
| 21534 |
kshitij.so |
397 |
}
|
| 21517 |
kshitij.so |
398 |
|
| 21534 |
kshitij.so |
399 |
|
| 21514 |
kshitij.so |
400 |
private String remoteAddr(HttpServletRequest request) {
|
|
|
401 |
String remoteAddr = "";
|
|
|
402 |
String x;
|
| 23101 |
amit.gupta |
403 |
x = request.getHeader(X_REAL_IP);
|
|
|
404 |
log.info("Value of X_REAL_IP is [{}]", x);
|
| 21514 |
kshitij.so |
405 |
if (x != null && !x.isEmpty()) {
|
|
|
406 |
remoteAddr = x;
|
|
|
407 |
int idx = remoteAddr.lastIndexOf(',');
|
|
|
408 |
if (idx > -1) {
|
|
|
409 |
remoteAddr = remoteAddr.substring(idx + 1).trim();
|
|
|
410 |
}
|
|
|
411 |
} else {
|
|
|
412 |
remoteAddr = request.getRemoteAddr();
|
| 23100 |
amit.gupta |
413 |
log.info("Value of remoteAddr is [{}]", remoteAddr);
|
| 21514 |
kshitij.so |
414 |
}
|
|
|
415 |
return remoteAddr;
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
private String validateRecharge(RechargeType rechargeType, String number, long operatorId, String ipAddress){
|
|
|
419 |
TransactionClient tcl;
|
|
|
420 |
try {
|
|
|
421 |
tcl = new TransactionClient();
|
|
|
422 |
String result = tcl.getClient().validateRecharge(rechargeType, number, operatorId, ipAddress);
|
|
|
423 |
log.info("validateRecharge Called" + number + " and rechargeType : " + rechargeType + ", IP:" + ipAddress + ", Operator:" + operatorId + ", Result:" + result);
|
|
|
424 |
return result;
|
|
|
425 |
} catch (Exception e) {
|
|
|
426 |
log.error("Unable to get service provider for Device number " + number + " and rechargeType : " + rechargeType, e);
|
|
|
427 |
}
|
|
|
428 |
return "Oops! There seems to be a problem. Please try after some time";
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
|
| 21464 |
kshitij.so |
432 |
}
|
| 21505 |
kshitij.so |
433 |
|
|
|
434 |
|
|
|
435 |
|