| Line 11... |
Line 11... |
| 11 |
import java.util.stream.Collectors;
|
11 |
import java.util.stream.Collectors;
|
| 12 |
|
12 |
|
| 13 |
import javax.annotation.PostConstruct;
|
13 |
import javax.annotation.PostConstruct;
|
| 14 |
import javax.servlet.http.HttpServletRequest;
|
14 |
import javax.servlet.http.HttpServletRequest;
|
| 15 |
|
15 |
|
| 16 |
import org.apache.thrift.TException;
|
- |
|
| 17 |
import org.slf4j.Logger;
|
16 |
import org.slf4j.Logger;
|
| 18 |
import org.slf4j.LoggerFactory;
|
17 |
import org.slf4j.LoggerFactory;
|
| 19 |
import org.springframework.beans.factory.annotation.Autowired;
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 20 |
import org.springframework.beans.factory.annotation.Value;
|
19 |
import org.springframework.beans.factory.annotation.Value;
|
| 21 |
import org.springframework.http.MediaType;
|
20 |
import org.springframework.http.MediaType;
|
| Line 33... |
Line 32... |
| 33 |
import com.spice.profitmandi.common.model.OperatorType;
|
32 |
import com.spice.profitmandi.common.model.OperatorType;
|
| 34 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 35 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
34 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 36 |
import com.spice.profitmandi.common.model.RechargeRequest;
|
35 |
import com.spice.profitmandi.common.model.RechargeRequest;
|
| 37 |
import com.spice.profitmandi.common.model.RechargeResponse;
|
36 |
import com.spice.profitmandi.common.model.RechargeResponse;
|
| 38 |
import com.spice.profitmandi.common.util.Utils;
|
- |
|
| 39 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
37 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 40 |
import com.spice.profitmandi.dao.entity.dtr.RechargeCommission;
|
38 |
import com.spice.profitmandi.dao.entity.dtr.RechargeCommission;
|
| 41 |
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
|
39 |
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
|
| 42 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
40 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 43 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
41 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| Line 53... |
Line 51... |
| 53 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
51 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
|
52 |
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
53 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 56 |
import com.spice.profitmandi.service.recharge.RechargeService;
|
54 |
import com.spice.profitmandi.service.recharge.RechargeService;
|
| 57 |
import com.spice.profitmandi.service.wallet.WalletService;
|
55 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 58 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
- |
|
| 59 |
import com.spice.profitmandi.web.req.CreateRechargeRequest;
|
56 |
import com.spice.profitmandi.web.req.CreateRechargeRequest;
|
| 60 |
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
|
57 |
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
|
| 61 |
import com.spice.profitmandi.web.res.CreateRechargeResponse;
|
58 |
import com.spice.profitmandi.web.res.CreateRechargeResponse;
|
| 62 |
import com.spice.profitmandi.web.res.MyRechargesResponse;
|
- |
|
| 63 |
import com.spice.profitmandi.web.res.RechargeResultPojo;
|
59 |
import com.spice.profitmandi.web.res.RechargeResultPojo;
|
| 64 |
|
60 |
|
| 65 |
import in.shop2020.model.v1.order.DenominationType;
|
- |
|
| 66 |
import in.shop2020.model.v1.order.DeviceNumberInfo;
|
- |
|
| 67 |
import in.shop2020.model.v1.order.RechargeDenomination;
|
- |
|
| 68 |
import in.shop2020.model.v1.order.RechargeOrder;
|
- |
|
| 69 |
import io.swagger.annotations.ApiImplicitParam;
|
61 |
import io.swagger.annotations.ApiImplicitParam;
|
| 70 |
import io.swagger.annotations.ApiImplicitParams;
|
62 |
import io.swagger.annotations.ApiImplicitParams;
|
| 71 |
import io.swagger.annotations.ApiOperation;
|
63 |
import io.swagger.annotations.ApiOperation;
|
| 72 |
|
64 |
|
| 73 |
@Controller
|
65 |
@Controller
|
| Line 155... |
Line 147... |
| 155 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
147 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 156 |
@ApiOperation(value = "")
|
148 |
@ApiOperation(value = "")
|
| 157 |
public ResponseEntity<?> getServiceProvider(HttpServletRequest request,
|
149 |
public ResponseEntity<?> getServiceProvider(HttpServletRequest request,
|
| 158 |
@RequestParam(value = "deviceNumber") String deviceNumber,
|
150 |
@RequestParam(value = "deviceNumber") String deviceNumber,
|
| 159 |
@RequestParam(value = "rechargeType") String rechargeType) {
|
151 |
@RequestParam(value = "rechargeType") String rechargeType) {
|
| 160 |
DeviceNumberInfo deviceInfo = null;
|
- |
|
| 161 |
TransactionClient tcl;
|
- |
|
| 162 |
try {
|
- |
|
| 163 |
tcl = new TransactionClient();
|
- |
|
| 164 |
// deviceInfo =
|
- |
|
| 165 |
// tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType),
|
- |
|
| 166 |
// deviceNumber.substring(0,4));
|
- |
|
| 167 |
} catch (Exception e) {
|
- |
|
| 168 |
log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : "
|
- |
|
| 169 |
+ rechargeType, e);
|
- |
|
| 170 |
}
|
- |
|
| 171 |
return responseSender.ok(deviceInfo);
|
152 |
return responseSender.ok(null);
|
| 172 |
}
|
153 |
}
|
| 173 |
|
154 |
|
| 174 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
155 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 175 |
@ApiImplicitParams({
|
156 |
@ApiImplicitParams({
|
| 176 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
157 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 177 |
@ApiOperation(value = "")
|
158 |
@ApiOperation(value = "")
|
| 178 |
public ResponseEntity<?> getAllDenominations(HttpServletRequest request,
|
159 |
public ResponseEntity<?> getAllDenominations(HttpServletRequest request,
|
| 179 |
@RequestParam(value = "operatorId") long operatorId, @RequestParam(value = "circleCode") String circleCode,
|
160 |
@RequestParam(value = "operatorId") long operatorId, @RequestParam(value = "circleCode") String circleCode,
|
| 180 |
@RequestParam(value = "denominationType") String denominationType) {
|
161 |
@RequestParam(value = "denominationType") String denominationType) {
|
| 181 |
List<RechargeDenomination> rechargeDenominations = new ArrayList<RechargeDenomination>();
|
- |
|
| 182 |
TransactionClient tcl;
|
- |
|
| 183 |
try {
|
- |
|
| 184 |
tcl = new TransactionClient();
|
- |
|
| 185 |
rechargeDenominations = tcl.getClient().getRechargeDenominations(operatorId, circleCode,
|
- |
|
| 186 |
DenominationType.valueOf(denominationType));
|
- |
|
| 187 |
} catch (Exception e) {
|
- |
|
| 188 |
log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : "
|
- |
|
| 189 |
+ circleCode + " and DenominationType : " + denominationType, e);
|
- |
|
| 190 |
}
|
- |
|
| 191 |
return responseSender.ok(rechargeDenominations);
|
162 |
return responseSender.ok(new ArrayList<>());
|
| 192 |
}
|
163 |
}
|
| 193 |
|
164 |
|
| 194 |
@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
165 |
@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 195 |
@ApiImplicitParams({
|
166 |
@ApiImplicitParams({
|
| 196 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
167 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| Line 439... |
Line 410... |
| 439 |
@ApiImplicitParams({
|
410 |
@ApiImplicitParams({
|
| 440 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
411 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 441 |
|
412 |
|
| 442 |
public ResponseEntity<?> rechargeResult(HttpServletRequest request,
|
413 |
public ResponseEntity<?> rechargeResult(HttpServletRequest request,
|
| 443 |
@RequestParam(value = "requestId") String requestId) throws ProfitMandiBusinessException {
|
414 |
@RequestParam(value = "requestId") String requestId) throws ProfitMandiBusinessException {
|
| 444 |
RechargeOrder rechargeOrder = null;
|
- |
|
| 445 |
RechargeResultPojo rrp = null;
|
- |
|
| 446 |
|
- |
|
| 447 |
// RechargeResponse rr = new RechargeResponse();
|
- |
|
| 448 |
// String requestId = rr.getRequestId();
|
- |
|
| 449 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
415 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 450 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
416 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 451 |
|
417 |
|
| 452 |
RechargeResponse rechargeResponse = rechargeService.checkStatus(thinkWalnutDigitalRechargeEnquiryCredential,
|
418 |
RechargeResponse rechargeResponse = rechargeService.checkStatus(thinkWalnutDigitalRechargeEnquiryCredential,
|
| 453 |
retailerId, requestId);
|
419 |
retailerId, requestId);
|
| Line 458... |
Line 424... |
| 458 |
@ApiImplicitParams({
|
424 |
@ApiImplicitParams({
|
| 459 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
425 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 460 |
public ResponseEntity<?> pollRechargeResult(HttpServletRequest request,
|
426 |
public ResponseEntity<?> pollRechargeResult(HttpServletRequest request,
|
| 461 |
@RequestParam(value = "rechargeOrderId") long rechargeOrderId,
|
427 |
@RequestParam(value = "rechargeOrderId") long rechargeOrderId,
|
| 462 |
@RequestParam(value = "finalCall") boolean finalCall) {
|
428 |
@RequestParam(value = "finalCall") boolean finalCall) {
|
| 463 |
TransactionClient transactionServiceClient = null;
|
- |
|
| 464 |
RechargeOrder t_rechargeOrder = null;
|
- |
|
| 465 |
RechargeResultPojo rrp = null;
|
429 |
RechargeResultPojo rrp = new RechargeResultPojo();
|
| 466 |
try {
|
430 |
try {
|
| - |
|
431 |
RechargeTransaction rechargeTransaction = rechargeTransactionRepository.selectById((int) rechargeOrderId);
|
| 467 |
transactionServiceClient = new TransactionClient();
|
432 |
RechargeStatus status = rechargeTransaction.getStatus();
|
| - |
|
433 |
if (status == RechargeStatus.SUCCESS) {
|
| - |
|
434 |
rrp.setIsError(false);
|
| - |
|
435 |
rrp.setRechargeStatus("SUCCESS");
|
| - |
|
436 |
rrp.setDetailDisplayMessage("Congratulations! Your device is successfully recharged.");
|
| - |
|
437 |
} else if (status == RechargeStatus.FAILED) {
|
| - |
|
438 |
rrp.setIsError(false);
|
| - |
|
439 |
rrp.setRechargeStatus("RECHARGE FAILED");
|
| - |
|
440 |
rrp.setDetailDisplayMessage("Your Payment was successful but unfortunately the recharge failed. The amount has been refunded to your wallet.");
|
| - |
|
441 |
} else {
|
| - |
|
442 |
rrp.setIsError(false);
|
| - |
|
443 |
rrp.setRechargeStatus("RECHARGE IN PROCESS");
|
| 468 |
t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
|
444 |
rrp.setDetailDisplayMessage("Your Payment is successful. Please wait while we check with the operator.");
|
| - |
|
445 |
}
|
| 469 |
} catch (Exception e) {
|
446 |
} catch (Exception e) {
|
| 470 |
rrp = new RechargeResultPojo();
|
447 |
log.error("Unable to poll recharge status for rechargeOrderId: " + rechargeOrderId, e);
|
| 471 |
rrp.setRechargeStatus("");
|
448 |
rrp.setRechargeStatus("");
|
| 472 |
return responseSender.internalServerError(e);
|
449 |
return responseSender.internalServerError(e);
|
| 473 |
}
|
450 |
}
|
| 474 |
if (t_rechargeOrder == null) {
|
- |
|
| 475 |
rrp = new RechargeResultPojo();
|
- |
|
| 476 |
rrp.setRechargeStatus("");
|
- |
|
| 477 |
return responseSender.badRequest(new RechargeResultPojo());
|
- |
|
| 478 |
}
|
- |
|
| 479 |
rrp = new RechargeResultPojo();
|
- |
|
| 480 |
String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
|
- |
|
| 481 |
rrp.setIsError(Boolean.parseBoolean(os[0]));
|
- |
|
| 482 |
rrp.setRechargeStatus(os[1]);
|
- |
|
| 483 |
rrp.setDetailDisplayMessage(os[2]);
|
- |
|
| 484 |
return responseSender.ok(rrp);
|
451 |
return responseSender.ok(rrp);
|
| 485 |
}
|
452 |
}
|
| 486 |
|
453 |
|
| 487 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
454 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 488 |
@ApiImplicitParams({
|
455 |
@ApiImplicitParams({
|
| 489 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
456 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 490 |
public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value = "offset") int offset,
|
457 |
public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value = "offset") int offset,
|
| 491 |
@RequestParam(value = "limit") int limit) throws ProfitMandiBusinessException {
|
458 |
@RequestParam(value = "limit") int limit) throws ProfitMandiBusinessException {
|
| 492 |
TransactionClient tc = null;
|
- |
|
| 493 |
int userId = (int) request.getAttribute("userId");
|
- |
|
| 494 |
UserAccount userAccount;
|
- |
|
| 495 |
List<RechargeOrder> rechargeOrders = null;
|
- |
|
| 496 |
|
- |
|
| 497 |
userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
- |
|
| 498 |
|
- |
|
| 499 |
try {
|
- |
|
| 500 |
tc = new TransactionClient();
|
- |
|
| 501 |
rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccountKey()),
|
- |
|
| 502 |
offset, limit);
|
- |
|
| 503 |
} catch (Exception e) {
|
- |
|
| 504 |
log.error("Unable to get recharge order list", e);
|
- |
|
| 505 |
return responseSender.internalServerError(e);
|
- |
|
| 506 |
}
|
- |
|
| 507 |
List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
|
- |
|
| 508 |
for (RechargeOrder rechargeOrder : rechargeOrders) {
|
- |
|
| 509 |
MyRechargesResponse rp = new MyRechargesResponse();
|
- |
|
| 510 |
/*
|
- |
|
| 511 |
* if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
|
- |
|
| 512 |
* rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
- |
|
| 513 |
* rp.setOperatorType("MOBILE"); } if(rechargeOrder.getRechargeType() ==
|
- |
|
| 514 |
* RechargeType.DTH){
|
- |
|
| 515 |
* rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
- |
|
| 516 |
* rp.setOperatorType("DTH"); }
|
- |
|
| 517 |
*/
|
- |
|
| 518 |
rp.setOrderId(rechargeOrder.getId());
|
- |
|
| 519 |
rp.setOperatorId(rechargeOrder.getOperatorId());
|
- |
|
| 520 |
rp.setDate(rechargeOrder.getCreationTimestamp());
|
- |
|
| 521 |
rp.setNumber(rechargeOrder.getDeviceNumber());
|
- |
|
| 522 |
rp.setAmount(rechargeOrder.getTotalAmount());
|
- |
|
| 523 |
rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
|
- |
|
| 524 |
rp.setDisplayOrderId(rechargeOrder.getDisplayId());
|
- |
|
| 525 |
myRechargesList.add(rp);
|
- |
|
| 526 |
}
|
- |
|
| 527 |
return responseSender.ok(myRechargesList);
|
459 |
return responseSender.ok(new ArrayList<>());
|
| 528 |
}
|
460 |
}
|
| 529 |
|
461 |
|
| 530 |
private String remoteAddr(HttpServletRequest request) {
|
462 |
private String remoteAddr(HttpServletRequest request) {
|
| 531 |
String remoteAddr = "";
|
463 |
String remoteAddr = "";
|
| 532 |
String x;
|
464 |
String x;
|