| 21464 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21468 |
kshitij.so |
3 |
import java.util.ArrayList;
|
| 24260 |
amit.gupta |
4 |
import java.util.Arrays;
|
| 23585 |
tejbeer |
5 |
import java.util.Collection;
|
|
|
6 |
import java.util.Collections;
|
|
|
7 |
import java.util.HashMap;
|
|
|
8 |
import java.util.HashSet;
|
|
|
9 |
import java.util.LinkedHashSet;
|
| 21468 |
kshitij.so |
10 |
import java.util.List;
|
|
|
11 |
import java.util.Map;
|
| 23585 |
tejbeer |
12 |
import java.util.Optional;
|
|
|
13 |
import java.util.Set;
|
|
|
14 |
import java.util.stream.Collector;
|
|
|
15 |
import java.util.stream.Collectors;
|
| 21464 |
kshitij.so |
16 |
|
| 23585 |
tejbeer |
17 |
import javax.annotation.PostConstruct;
|
| 21464 |
kshitij.so |
18 |
import javax.servlet.http.HttpServletRequest;
|
| 23585 |
tejbeer |
19 |
import javax.swing.SortOrder;
|
|
|
20 |
|
| 21505 |
kshitij.so |
21 |
import org.apache.thrift.TException;
|
|
|
22 |
import org.apache.thrift.transport.TTransportException;
|
| 23585 |
tejbeer |
23 |
import org.slf4j.Logger;
|
|
|
24 |
import org.slf4j.LoggerFactory;
|
| 21505 |
kshitij.so |
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23585 |
tejbeer |
26 |
import org.springframework.beans.factory.annotation.Value;
|
| 21464 |
kshitij.so |
27 |
import org.springframework.http.MediaType;
|
|
|
28 |
import org.springframework.http.ResponseEntity;
|
|
|
29 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
30 |
import org.springframework.transaction.annotation.Transactional;
|
| 23585 |
tejbeer |
31 |
import org.springframework.ui.Model;
|
| 21514 |
kshitij.so |
32 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21464 |
kshitij.so |
33 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
34 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
36 |
|
| 23585 |
tejbeer |
37 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
|
|
38 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 21505 |
kshitij.so |
39 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23585 |
tejbeer |
40 |
import com.spice.profitmandi.common.model.CustomPaymentOption;
|
|
|
41 |
import com.spice.profitmandi.common.model.OperatorType;
|
| 21464 |
kshitij.so |
42 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23585 |
tejbeer |
43 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
|
|
44 |
import com.spice.profitmandi.common.model.RechargeRequest;
|
|
|
45 |
import com.spice.profitmandi.common.model.RechargeResponse;
|
| 21468 |
kshitij.so |
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 22931 |
ashik.ali |
47 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23585 |
tejbeer |
48 |
import com.spice.profitmandi.dao.entity.dtr.RechargeCommission;
|
|
|
49 |
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
|
|
|
50 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
51 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 21735 |
ashik.ali |
52 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 23273 |
ashik.ali |
53 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 21735 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 23585 |
tejbeer |
55 |
import com.spice.profitmandi.dao.enumuration.dtr.RechargeType;
|
|
|
56 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
|
|
57 |
import com.spice.profitmandi.dao.repository.dtr.RechargeCommissionRepository;
|
|
|
58 |
import com.spice.profitmandi.dao.repository.dtr.RechargeOperatorRepository;
|
|
|
59 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
60 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 21735 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
62 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 23115 |
ashik.ali |
63 |
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
|
| 23585 |
tejbeer |
64 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
65 |
import com.spice.profitmandi.service.recharge.RechargeService;
|
| 21735 |
ashik.ali |
66 |
import com.spice.profitmandi.thrift.clients.PaymentClient;
|
| 21464 |
kshitij.so |
67 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
| 21514 |
kshitij.so |
68 |
import com.spice.profitmandi.web.req.CreateRechargeRequest;
|
| 21505 |
kshitij.so |
69 |
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
|
| 21514 |
kshitij.so |
70 |
import com.spice.profitmandi.web.res.CreateRechargeResponse;
|
| 21534 |
kshitij.so |
71 |
import com.spice.profitmandi.web.res.MyRechargesResponse;
|
| 21517 |
kshitij.so |
72 |
import com.spice.profitmandi.web.res.RechargeResultPojo;
|
| 23585 |
tejbeer |
73 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
74 |
|
| 21468 |
kshitij.so |
75 |
import in.shop2020.model.v1.order.DenominationType;
|
| 21464 |
kshitij.so |
76 |
import in.shop2020.model.v1.order.DeviceNumberInfo;
|
| 21514 |
kshitij.so |
77 |
import in.shop2020.model.v1.order.OrderType;
|
| 21468 |
kshitij.so |
78 |
import in.shop2020.model.v1.order.RechargeDenomination;
|
| 21514 |
kshitij.so |
79 |
import in.shop2020.model.v1.order.RechargeOrder;
|
|
|
80 |
import in.shop2020.model.v1.order.RechargeOrderStatus;
|
|
|
81 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 23585 |
tejbeer |
82 |
|
| 21514 |
kshitij.so |
83 |
import in.shop2020.payments.Payment;
|
|
|
84 |
import in.shop2020.payments.PaymentException;
|
|
|
85 |
import in.shop2020.payments.PaymentStatus;
|
| 21464 |
kshitij.so |
86 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
87 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
88 |
import io.swagger.annotations.ApiOperation;
|
|
|
89 |
|
|
|
90 |
@Controller
|
| 22040 |
amit.gupta |
91 |
@Transactional(rollbackFor=Throwable.class)
|
| 21464 |
kshitij.so |
92 |
public class RechargeController {
|
|
|
93 |
|
| 23585 |
tejbeer |
94 |
private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
|
| 21514 |
kshitij.so |
95 |
private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
|
| 24260 |
amit.gupta |
96 |
|
| 24276 |
amit.gupta |
97 |
private List<String> blockedRecharge = Arrays.asList();
|
| 23101 |
amit.gupta |
98 |
private static final String X_REAL_IP = "X-Real-IP";
|
| 23585 |
tejbeer |
99 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
100 |
private String oxigenRechargeTransactionUrl;
|
|
|
101 |
|
|
|
102 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
103 |
private String oxigenRechargeEnquiryUrl;
|
|
|
104 |
|
|
|
105 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
106 |
private String oxigenRechargeAuthKey;
|
|
|
107 |
|
|
|
108 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
109 |
private String oxigenRechargeValidationUrl;
|
|
|
110 |
|
|
|
111 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
112 |
private String oxigenRechargeValidationAuthKey;
|
|
|
113 |
|
|
|
114 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
115 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
116 |
|
|
|
117 |
@Value("${think.walnut.digital.recharge.transaction.mobile.username}")
|
|
|
118 |
private String thinkWalnutDigitalRechargeTransactionMobileUserName;
|
|
|
119 |
|
|
|
120 |
@Value("${think.walnut.digital.recharge.transaction.mobile.password}")
|
|
|
121 |
private String thinkWalnutDigitalRechargeTransactionMobilePassword;
|
|
|
122 |
|
|
|
123 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
124 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
125 |
|
|
|
126 |
@Value("${think.walnut.digital.recharge.transaction.dth.username}")
|
|
|
127 |
private String thinkWalnutDigitalRechargeTransactionDthUserName;
|
|
|
128 |
|
|
|
129 |
@Value("${think.walnut.digital.recharge.transaction.dth.password}")
|
|
|
130 |
private String thinkWalnutDigitalRechargeTransactionDthPassword;
|
|
|
131 |
|
|
|
132 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
133 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
134 |
|
|
|
135 |
@Value("${think.walnut.digital.recharge.enquiry.username}")
|
|
|
136 |
private String thinkWalnutDigitalRechargeEnquiryUserName;
|
|
|
137 |
|
|
|
138 |
@Value("${think.walnut.digital.recharge.enquiry.password}")
|
|
|
139 |
private String thinkWalnutDigitalRechargeEnquiryPassword;
|
|
|
140 |
|
|
|
141 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
142 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
143 |
|
| 21505 |
kshitij.so |
144 |
@Autowired
|
| 23585 |
tejbeer |
145 |
UserWalletRepository userWalletRepository;
|
|
|
146 |
|
|
|
147 |
@Autowired
|
|
|
148 |
private GenericRepository genericRepository;
|
|
|
149 |
|
|
|
150 |
@Autowired
|
|
|
151 |
private RechargeCommissionRepository rechargeCommissionRepository;
|
|
|
152 |
|
|
|
153 |
@Autowired
|
| 22931 |
ashik.ali |
154 |
private UserAccountRepository userAccountRepository;
|
| 23585 |
tejbeer |
155 |
|
|
|
156 |
@Autowired
|
|
|
157 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 21514 |
kshitij.so |
158 |
|
|
|
159 |
@Autowired
|
| 23585 |
tejbeer |
160 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
161 |
|
|
|
162 |
@Autowired
|
| 22931 |
ashik.ali |
163 |
private UserRepository userRepository;
|
|
|
164 |
|
|
|
165 |
@Autowired
|
| 23585 |
tejbeer |
166 |
private RechargeOperatorRepository rechargeOperatorRepository;
|
|
|
167 |
|
|
|
168 |
@Autowired
|
|
|
169 |
private RechargeService rechargeService;
|
|
|
170 |
|
|
|
171 |
@Autowired
|
| 23115 |
ashik.ali |
172 |
private PendingRechargeCommissionRepository pendingRechargeCommissionRepository;
|
|
|
173 |
|
|
|
174 |
@Autowired
|
| 22931 |
ashik.ali |
175 |
private ResponseSender<?> responseSender;
|
| 23585 |
tejbeer |
176 |
|
|
|
177 |
private RechargeCredential rechargeTransactionMobileCredential;
|
|
|
178 |
private RechargeCredential rechargeTransactionDthCredential;
|
|
|
179 |
private RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential;
|
| 21514 |
kshitij.so |
180 |
|
| 21464 |
kshitij.so |
181 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
182 |
@ApiImplicitParams({
|
|
|
183 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
184 |
required = true, dataType = "string", paramType = "header")
|
|
|
185 |
})
|
|
|
186 |
@ApiOperation(value = "")
|
|
|
187 |
public ResponseEntity<?> getServiceProvider(HttpServletRequest request, @RequestParam(value="deviceNumber") String deviceNumber, @RequestParam(value="rechargeType") String rechargeType){
|
|
|
188 |
DeviceNumberInfo deviceInfo = null;
|
|
|
189 |
TransactionClient tcl;
|
|
|
190 |
try {
|
|
|
191 |
tcl = new TransactionClient();
|
| 23585 |
tejbeer |
192 |
//deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
|
| 21464 |
kshitij.so |
193 |
} catch (Exception e) {
|
|
|
194 |
log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " + rechargeType, e);
|
|
|
195 |
}
|
| 22931 |
ashik.ali |
196 |
return responseSender.ok(deviceInfo);
|
| 21464 |
kshitij.so |
197 |
}
|
| 21505 |
kshitij.so |
198 |
|
| 21468 |
kshitij.so |
199 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
200 |
@ApiImplicitParams({
|
|
|
201 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
202 |
required = true, dataType = "string", paramType = "header")
|
|
|
203 |
})
|
|
|
204 |
@ApiOperation(value = "")
|
|
|
205 |
public ResponseEntity<?> getAllDenominations(HttpServletRequest request, @RequestParam(value="operatorId") long operatorId, @RequestParam(value="circleCode") String circleCode, @RequestParam(value="denominationType") String denominationType){
|
|
|
206 |
List<RechargeDenomination> rechargeDenominations = new ArrayList<RechargeDenomination>();
|
|
|
207 |
TransactionClient tcl;
|
|
|
208 |
try {
|
|
|
209 |
tcl = new TransactionClient();
|
|
|
210 |
rechargeDenominations = tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
|
|
|
211 |
} catch (Exception e) {
|
|
|
212 |
log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " + circleCode + " and DenominationType : " + denominationType, e);
|
|
|
213 |
}
|
| 22931 |
ashik.ali |
214 |
return responseSender.ok(rechargeDenominations);
|
| 21468 |
kshitij.so |
215 |
}
|
| 21505 |
kshitij.so |
216 |
|
| 23585 |
tejbeer |
217 |
@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21468 |
kshitij.so |
218 |
@ApiImplicitParams({
|
|
|
219 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
220 |
required = true, dataType = "string", paramType = "header")
|
|
|
221 |
})
|
| 23585 |
tejbeer |
222 |
|
| 21468 |
kshitij.so |
223 |
@ApiOperation(value = "")
|
| 23585 |
tejbeer |
224 |
public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request,@RequestParam(name = ProfitMandiConstants.OPERATOR_TYPE) OperatorType operatorType){
|
|
|
225 |
Map<Integer, String> mobileProviderMap = new HashMap<>();
|
|
|
226 |
List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(operatorType);
|
|
|
227 |
// List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE);
|
|
|
228 |
for(RechargeOperator rechargeOperator : rechargeOperators) {
|
|
|
229 |
mobileProviderMap.put(rechargeOperator.getId(), rechargeOperator.getName());
|
|
|
230 |
}
|
| 22931 |
ashik.ali |
231 |
return responseSender.ok(mobileProviderMap);
|
| 21468 |
kshitij.so |
232 |
}
|
| 21505 |
kshitij.so |
233 |
|
| 21468 |
kshitij.so |
234 |
@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
235 |
@ApiImplicitParams({
|
|
|
236 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
237 |
required = true, dataType = "string", paramType = "header")
|
|
|
238 |
})
|
|
|
239 |
@ApiOperation(value = "")
|
|
|
240 |
public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
|
| 23585 |
tejbeer |
241 |
Map<Integer, String> dthProviderMap = new HashMap<>();
|
|
|
242 |
List<RechargeOperator> dthOperators = rechargeOperatorRepository.selectAllByRechargeType(RechargeType.DTH);
|
|
|
243 |
for(RechargeOperator dthOperator : dthOperators) {
|
|
|
244 |
dthProviderMap.put(dthOperator.getId(), dthOperator.getName());
|
|
|
245 |
}
|
| 22931 |
ashik.ali |
246 |
return responseSender.ok(dthProviderMap);
|
| 23585 |
tejbeer |
247 |
|
|
|
248 |
|
| 21468 |
kshitij.so |
249 |
}
|
|
|
250 |
|
| 21505 |
kshitij.so |
251 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
252 |
@ApiImplicitParams({
|
|
|
253 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
254 |
required = true, dataType = "string", paramType = "header")
|
|
|
255 |
})
|
|
|
256 |
@ApiOperation(value = "")
|
| 22931 |
ashik.ali |
257 |
public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
|
|
|
258 |
throws ProfitMandiBusinessException{
|
| 23115 |
ashik.ali |
259 |
int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 23273 |
ashik.ali |
260 |
UserAccount userAccount = null;
|
| 21505 |
kshitij.so |
261 |
UserWallet wallet = null;
|
|
|
262 |
if (rechargeAmount <=0){
|
| 22931 |
ashik.ali |
263 |
return responseSender.badRequest(null);
|
| 21505 |
kshitij.so |
264 |
}
|
| 21514 |
kshitij.so |
265 |
|
| 23273 |
ashik.ali |
266 |
userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 22931 |
ashik.ali |
267 |
|
| 21505 |
kshitij.so |
268 |
try {
|
|
|
269 |
TransactionClient tc = new TransactionClient();
|
| 23585 |
tejbeer |
270 |
//wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccountKey()));
|
| 21505 |
kshitij.so |
271 |
} catch (NumberFormatException | TException e) {
|
| 22931 |
ashik.ali |
272 |
return responseSender.internalServerError(e);
|
| 21505 |
kshitij.so |
273 |
}
|
| 21514 |
kshitij.so |
274 |
|
| 21505 |
kshitij.so |
275 |
ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
|
| 23585 |
tejbeer |
276 |
//crr.setWalletAmount(wallet.getAmount());
|
| 21505 |
kshitij.so |
277 |
crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
|
|
|
278 |
crr.setCanProceed(true);
|
|
|
279 |
if (crr.getWalletAmountLeft() < 0){
|
|
|
280 |
crr.setCanProceed(false);
|
|
|
281 |
crr.setReason("You don't have sufficient wallet balance");
|
|
|
282 |
}
|
| 22931 |
ashik.ali |
283 |
return responseSender.ok(crr);
|
| 21505 |
kshitij.so |
284 |
}
|
| 23115 |
ashik.ali |
285 |
|
|
|
286 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_PENDING_COMMISSION, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
287 |
@ApiImplicitParams({
|
|
|
288 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
289 |
required = true, dataType = "string", paramType = "header")
|
|
|
290 |
})
|
|
|
291 |
@ApiOperation(value = "")
|
|
|
292 |
public ResponseEntity<?> getPendingRechargeCommission(HttpServletRequest request)
|
|
|
293 |
throws ProfitMandiBusinessException{
|
|
|
294 |
int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
295 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
296 |
return responseSender.ok(pendingRechargeCommissionRepository.selectByRetailerId(retailerId));
|
|
|
297 |
}
|
| 23585 |
tejbeer |
298 |
|
|
|
299 |
private RechargeRequest convertRechargeRequest (CreateRechargeRequest createRechargeRequest ){
|
|
|
300 |
RechargeRequest rr= new RechargeRequest();
|
|
|
301 |
rr.setAmount(createRechargeRequest.getRechargeAmount());
|
|
|
302 |
rr.setOperatorId((int) createRechargeRequest.getOperatorId());
|
|
|
303 |
rr.setOperatorType(createRechargeRequest.getPlan());
|
|
|
304 |
rr.setReferenceNumber(createRechargeRequest.getNumber());
|
|
|
305 |
rr.setRechargeType(createRechargeRequest.getRechargeType());
|
|
|
306 |
|
|
|
307 |
Set<CustomPaymentOption> pp = new LinkedHashSet<>();
|
|
|
308 |
CustomPaymentOption cpo = new CustomPaymentOption();
|
|
|
309 |
cpo.setPaymentOption("cash");
|
|
|
310 |
cpo.setPaymentOptionId(1);
|
|
|
311 |
cpo.setAmount(createRechargeRequest.getRechargeAmount());
|
|
|
312 |
pp.add(cpo);
|
|
|
313 |
rr.setPaymentOptions(pp);
|
|
|
314 |
return rr;
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
@PostConstruct
|
|
|
318 |
private void setRechargeCredentials() {
|
|
|
319 |
rechargeTransactionMobileCredential = new RechargeCredential();
|
|
|
320 |
rechargeTransactionMobileCredential.setRechargeUrl(thinkWalnutDigitalRechargeTransactionMobileUrl);
|
|
|
321 |
rechargeTransactionMobileCredential.setRechargeUserName(thinkWalnutDigitalRechargeTransactionMobileUserName);
|
|
|
322 |
rechargeTransactionMobileCredential.setRechargePassword(thinkWalnutDigitalRechargeTransactionMobilePassword);
|
|
|
323 |
rechargeTransactionMobileCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
324 |
|
|
|
325 |
rechargeTransactionDthCredential = new RechargeCredential();
|
|
|
326 |
rechargeTransactionDthCredential.setRechargeUrl(thinkWalnutDigitalRechargeTransactionDthUrl);
|
|
|
327 |
rechargeTransactionDthCredential.setRechargeUserName(thinkWalnutDigitalRechargeTransactionDthUserName);
|
|
|
328 |
rechargeTransactionDthCredential.setRechargePassword(thinkWalnutDigitalRechargeTransactionDthPassword);
|
|
|
329 |
rechargeTransactionDthCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
330 |
}
|
|
|
331 |
|
| 23587 |
tejbeer |
332 |
@RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
333 |
@ApiImplicitParams({
|
|
|
334 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
335 |
required = true, dataType = "string", paramType = "header")
|
|
|
336 |
})
|
| 23585 |
tejbeer |
337 |
|
| 22931 |
ashik.ali |
338 |
public ResponseEntity<?> createRecharge(HttpServletRequest request, @RequestBody CreateRechargeRequest createRechargeRequest)
|
|
|
339 |
throws ProfitMandiBusinessException{
|
| 23585 |
tejbeer |
340 |
int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
341 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 21514 |
kshitij.so |
342 |
String ipAddress = remoteAddr(request);
|
| 23585 |
tejbeer |
343 |
|
|
|
344 |
CreateRechargeResponse crr = new CreateRechargeResponse();
|
|
|
345 |
|
|
|
346 |
UserAccount userAccount = null;
|
|
|
347 |
UserWallet wallet = null;
|
|
|
348 |
wallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
349 |
|
| 21514 |
kshitij.so |
350 |
if (createRechargeRequest.getRechargeAmount() <=0){
|
|
|
351 |
crr.setReason("Illegal recharge amount");
|
|
|
352 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
353 |
return responseSender.badRequest(crr);
|
| 21514 |
kshitij.so |
354 |
}
|
|
|
355 |
|
|
|
356 |
if (wallet.getAmount() < createRechargeRequest.getRechargeAmount()){
|
|
|
357 |
crr.setReason("You don't have sufficient wallet balance.");
|
|
|
358 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
359 |
return responseSender.badRequest(crr);
|
| 21514 |
kshitij.so |
360 |
}
|
|
|
361 |
|
|
|
362 |
User user = null;
|
|
|
363 |
try {
|
|
|
364 |
user = userRepository.selectById(userId);
|
|
|
365 |
} catch (ProfitMandiBusinessException e) {
|
|
|
366 |
log.error("Unable to get user",e);
|
|
|
367 |
crr.setReason("We are experiencing some problem right now.");
|
|
|
368 |
crr.setResult(false);
|
| 22931 |
ashik.ali |
369 |
return responseSender.internalServerError(e);
|
| 21514 |
kshitij.so |
370 |
}
|
|
|
371 |
|
| 23585 |
tejbeer |
372 |
|
|
|
373 |
RechargeRequest rechargeRequest = convertRechargeRequest(createRechargeRequest);
|
| 24260 |
amit.gupta |
374 |
if(blockedRecharge.contains(user.getEmailId())) {
|
|
|
375 |
throw new ProfitMandiBusinessException("Recharge Provider", createRechargeRequest.getOperatorId(), "We are experiencing some problem right now.");
|
|
|
376 |
}
|
| 23585 |
tejbeer |
377 |
RechargeResponse rechargeResponse = rechargeService.doRecharge(oxigenRechargeTransactionUrl, oxigenRechargeAuthKey, oxigenRechargeValidationUrl,
|
|
|
378 |
oxigenRechargeValidationAuthKey, rechargeTransactionMobileCredential, rechargeTransactionDthCredential, retailerId, rechargeRequest);
|
|
|
379 |
|
|
|
380 |
crr.setResult(rechargeResponse.getStatus().equals(RechargeStatus.SUCCESS));
|
|
|
381 |
crr.setRequestId(rechargeResponse.getRequestId());
|
|
|
382 |
|
|
|
383 |
if(RechargeType.valueOf(rechargeRequest.getRechargeType()) == RechargeType.MOBILE) {
|
|
|
384 |
return responseSender.ok(crr);
|
|
|
385 |
}else {
|
|
|
386 |
return responseSender.ok(crr);
|
| 21514 |
kshitij.so |
387 |
}
|
| 23585 |
tejbeer |
388 |
}
|
|
|
389 |
|
|
|
390 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_SUMMARY , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
391 |
@ApiImplicitParams({
|
|
|
392 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
393 |
required = true, dataType = "string", paramType = "header")
|
|
|
394 |
})
|
| 23592 |
tejbeer |
395 |
public ResponseEntity<?>rechargeSummary (HttpServletRequest request , @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit)
|
| 23585 |
tejbeer |
396 |
throws ProfitMandiBusinessException{
|
|
|
397 |
int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
398 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| 23592 |
tejbeer |
399 |
//RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
400 |
List<RechargeTransaction> rechargeTransactions =rechargeTransactionRepository.selectAllByRetailerId(retailerId, offset, limit);
|
| 23585 |
tejbeer |
401 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
402 |
String operatorName=rechargeOperatorRepository.selectById(rechargeTransaction.getOperatorId()).getName();
|
|
|
403 |
rechargeTransaction.setOperatorName(operatorName);
|
| 21514 |
kshitij.so |
404 |
}
|
| 23592 |
tejbeer |
405 |
|
| 23585 |
tejbeer |
406 |
return responseSender.ok(rechargeTransactions);
|
| 23592 |
tejbeer |
407 |
|
| 23585 |
tejbeer |
408 |
|
| 21505 |
kshitij.so |
409 |
}
|
| 23585 |
tejbeer |
410 |
|
|
|
411 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_COMMISSIONS , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
412 |
@ApiImplicitParams({
|
|
|
413 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
414 |
required = true, dataType = "string", paramType = "header")
|
|
|
415 |
})
|
|
|
416 |
public ResponseEntity<?>rechargeCommissions (HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "60") int limit)
|
|
|
417 |
throws ProfitMandiBusinessException{
|
|
|
418 |
List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
|
|
|
419 |
for (RechargeCommission rechargeCommission : rechargeCommissions) {
|
|
|
420 |
String operatorName=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getName();
|
|
|
421 |
RechargeType rechargeType=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getRechargeType();
|
|
|
422 |
OperatorType operatorType=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getOperatorType();
|
|
|
423 |
rechargeCommission.setOperatorName(operatorName);
|
|
|
424 |
rechargeCommission.setRechargeType(rechargeType);
|
|
|
425 |
rechargeCommission.setOperatorType(operatorType);
|
|
|
426 |
}
|
|
|
427 |
Map<Integer,RechargeCommission> commissionMap = rechargeCommissions.stream().collect(Collectors.groupingBy(RechargeCommission::getOperatorId, Collectors.collectingAndThen(
|
|
|
428 |
Collectors.reducing((RechargeCommission d1,RechargeCommission d2) -> d1.getAmount() > d2.getAmount() ? d1 : d2),
|
|
|
429 |
Optional::get)));
|
|
|
430 |
|
|
|
431 |
return responseSender.ok(commissionMap.values());
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
@PostConstruct
|
|
|
435 |
private void setRechargeEnquiryCredentials() {
|
|
|
436 |
thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
437 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
438 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeEnquiryUserName);
|
|
|
439 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargeEnquiryPassword);
|
|
|
440 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
441 |
}
|
| 23587 |
tejbeer |
442 |
|
|
|
443 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_RESULT , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
444 |
@ApiImplicitParams({
|
|
|
445 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
446 |
required = true, dataType = "string", paramType = "header")
|
|
|
447 |
})
|
|
|
448 |
|
|
|
449 |
|
| 23585 |
tejbeer |
450 |
public ResponseEntity<?> rechargeResult(HttpServletRequest request, @RequestParam(value="requestId") String requestId ) throws ProfitMandiBusinessException{
|
| 21517 |
kshitij.so |
451 |
RechargeOrder rechargeOrder = null;
|
|
|
452 |
RechargeResultPojo rrp = null;
|
| 23585 |
tejbeer |
453 |
|
|
|
454 |
|
|
|
455 |
//RechargeResponse rr = new RechargeResponse();
|
|
|
456 |
//String requestId = rr.getRequestId();
|
|
|
457 |
int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
458 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
459 |
|
|
|
460 |
RechargeResponse rechargeResponse = rechargeService.checkStatus(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey, thinkWalnutDigitalRechargeEnquiryCredential,retailerId , requestId);
|
|
|
461 |
return responseSender.ok(rechargeResponse);
|
|
|
462 |
|
|
|
463 |
/* try {
|
| 21517 |
kshitij.so |
464 |
tc = new TransactionClient();
|
| 23585 |
tejbeer |
465 |
//rechargeOrder = tc.getClient().getRechargeOrder(rechargeOrderId);
|
| 21517 |
kshitij.so |
466 |
} catch (TransactionServiceException | TException e) {
|
|
|
467 |
// return with internal server error
|
|
|
468 |
e.printStackTrace();
|
|
|
469 |
rrp = new RechargeResultPojo();
|
|
|
470 |
rrp.setIsError(true);
|
|
|
471 |
rrp.setDetailDisplayMessage("We are experiencing some problem right now.");
|
| 22931 |
ashik.ali |
472 |
return responseSender.internalServerError(e);
|
| 21517 |
kshitij.so |
473 |
}
|
|
|
474 |
if (rechargeOrder == null){
|
|
|
475 |
rrp = new RechargeResultPojo();
|
|
|
476 |
rrp.setIsError(true);
|
|
|
477 |
rrp.setDetailDisplayMessage("Recharge order doesnot exist in our system.");
|
| 22931 |
ashik.ali |
478 |
return responseSender.badRequest(rrp);
|
| 21517 |
kshitij.so |
479 |
}
|
|
|
480 |
String[] os = Utils.getOrderStatus(rechargeOrder.getStatus());
|
|
|
481 |
rrp = new RechargeResultPojo();
|
|
|
482 |
rrp.setRechargeDeviceNumber(rechargeOrder.getDeviceNumber());
|
|
|
483 |
rrp.setRechargeDisplayId(rechargeOrder.getDisplayId());
|
|
|
484 |
rrp.setTotalAmount(rechargeOrder.getTotalAmount() + "");
|
|
|
485 |
rrp.setRechargeProvider(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
486 |
rrp.setIsError(Boolean.parseBoolean(os[0]));
|
|
|
487 |
rrp.setRechargeStatus(os[1]);
|
|
|
488 |
rrp.setDetailDisplayMessage(os[2]);
|
| 21523 |
kshitij.so |
489 |
if (rechargeOrder.getStatus().equals(RechargeOrderStatus.RECHARGE_UNKNOWN)){
|
| 21517 |
kshitij.so |
490 |
rrp.setPoll(true);
|
| 23585 |
tejbeer |
491 |
}*/
|
|
|
492 |
|
| 21517 |
kshitij.so |
493 |
}
|
| 21514 |
kshitij.so |
494 |
|
| 21517 |
kshitij.so |
495 |
@RequestMapping(value = ProfitMandiConstants.URL_POLL_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
496 |
@ApiImplicitParams({
|
|
|
497 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
498 |
required = true, dataType = "string", paramType = "header")
|
|
|
499 |
})
|
| 21519 |
kshitij.so |
500 |
public ResponseEntity<?> pollRechargeResult(HttpServletRequest request, @RequestParam(value="rechargeOrderId") long rechargeOrderId, @RequestParam(value="finalCall") boolean finalCall){
|
| 21517 |
kshitij.so |
501 |
TransactionClient transactionServiceClient = null;
|
|
|
502 |
RechargeOrder t_rechargeOrder = null;
|
|
|
503 |
RechargeResultPojo rrp = null;
|
|
|
504 |
try{
|
|
|
505 |
transactionServiceClient = new TransactionClient();
|
|
|
506 |
t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
|
|
|
507 |
}
|
|
|
508 |
catch(Exception e){
|
|
|
509 |
rrp = new RechargeResultPojo();
|
|
|
510 |
rrp.setRechargeStatus("");
|
| 22931 |
ashik.ali |
511 |
return responseSender.internalServerError(e);
|
| 21517 |
kshitij.so |
512 |
}
|
|
|
513 |
if (t_rechargeOrder == null){
|
|
|
514 |
rrp = new RechargeResultPojo();
|
|
|
515 |
rrp.setRechargeStatus("");
|
| 22931 |
ashik.ali |
516 |
return responseSender.badRequest(new RechargeResultPojo());
|
| 21517 |
kshitij.so |
517 |
}
|
|
|
518 |
rrp = new RechargeResultPojo();
|
| 22411 |
amit.gupta |
519 |
String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
|
|
|
520 |
rrp.setIsError(Boolean.parseBoolean(os[0]));
|
|
|
521 |
rrp.setRechargeStatus(os[1]);
|
|
|
522 |
rrp.setDetailDisplayMessage(os[2]);
|
| 22931 |
ashik.ali |
523 |
return responseSender.ok(rrp);
|
| 21517 |
kshitij.so |
524 |
}
|
| 21534 |
kshitij.so |
525 |
|
|
|
526 |
@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
527 |
@ApiImplicitParams({
|
|
|
528 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
529 |
required = true, dataType = "string", paramType = "header")
|
|
|
530 |
})
|
| 22931 |
ashik.ali |
531 |
public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
|
| 21534 |
kshitij.so |
532 |
TransactionClient tc=null;
|
|
|
533 |
int userId = (int)request.getAttribute("userId");
|
| 23273 |
ashik.ali |
534 |
UserAccount userAccount;
|
| 21534 |
kshitij.so |
535 |
List<RechargeOrder> rechargeOrders = null;
|
| 22931 |
ashik.ali |
536 |
|
| 23273 |
ashik.ali |
537 |
userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 22931 |
ashik.ali |
538 |
|
| 21534 |
kshitij.so |
539 |
try {
|
|
|
540 |
tc = new TransactionClient();
|
| 23273 |
ashik.ali |
541 |
rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccountKey()), offset, limit);
|
| 21534 |
kshitij.so |
542 |
} catch (Exception e) {
|
|
|
543 |
log.error("Unable to get recharge order list",e);
|
| 22931 |
ashik.ali |
544 |
return responseSender.internalServerError(e);
|
| 21534 |
kshitij.so |
545 |
}
|
|
|
546 |
List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
|
|
|
547 |
for (RechargeOrder rechargeOrder : rechargeOrders){
|
|
|
548 |
MyRechargesResponse rp = new MyRechargesResponse();
|
| 23585 |
tejbeer |
549 |
/* if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
|
| 21534 |
kshitij.so |
550 |
rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
551 |
rp.setOperatorType("MOBILE");
|
|
|
552 |
}
|
|
|
553 |
if(rechargeOrder.getRechargeType() == RechargeType.DTH){
|
|
|
554 |
rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
|
|
|
555 |
rp.setOperatorType("DTH");
|
| 23585 |
tejbeer |
556 |
}*/
|
| 21534 |
kshitij.so |
557 |
rp.setOrderId(rechargeOrder.getId());
|
|
|
558 |
rp.setOperatorId(rechargeOrder.getOperatorId());
|
|
|
559 |
rp.setDate(rechargeOrder.getCreationTimestamp());
|
|
|
560 |
rp.setNumber(rechargeOrder.getDeviceNumber());
|
|
|
561 |
rp.setAmount(rechargeOrder.getTotalAmount());
|
|
|
562 |
rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
|
|
|
563 |
rp.setDisplayOrderId(rechargeOrder.getDisplayId());
|
|
|
564 |
myRechargesList.add(rp);
|
|
|
565 |
}
|
| 22931 |
ashik.ali |
566 |
return responseSender.ok(myRechargesList);
|
| 21534 |
kshitij.so |
567 |
}
|
| 21517 |
kshitij.so |
568 |
|
| 21534 |
kshitij.so |
569 |
|
| 21514 |
kshitij.so |
570 |
private String remoteAddr(HttpServletRequest request) {
|
|
|
571 |
String remoteAddr = "";
|
|
|
572 |
String x;
|
| 23101 |
amit.gupta |
573 |
x = request.getHeader(X_REAL_IP);
|
|
|
574 |
log.info("Value of X_REAL_IP is [{}]", x);
|
| 21514 |
kshitij.so |
575 |
if (x != null && !x.isEmpty()) {
|
|
|
576 |
remoteAddr = x;
|
|
|
577 |
int idx = remoteAddr.lastIndexOf(',');
|
|
|
578 |
if (idx > -1) {
|
|
|
579 |
remoteAddr = remoteAddr.substring(idx + 1).trim();
|
|
|
580 |
}
|
|
|
581 |
} else {
|
|
|
582 |
remoteAddr = request.getRemoteAddr();
|
| 23100 |
amit.gupta |
583 |
log.info("Value of remoteAddr is [{}]", remoteAddr);
|
| 21514 |
kshitij.so |
584 |
}
|
|
|
585 |
return remoteAddr;
|
|
|
586 |
}
|
|
|
587 |
|
| 23585 |
tejbeer |
588 |
/*private String validateRecharge(RechargeType rechargeType, String number, long operatorId, String ipAddress){
|
| 21514 |
kshitij.so |
589 |
TransactionClient tcl;
|
|
|
590 |
try {
|
|
|
591 |
tcl = new TransactionClient();
|
| 23585 |
tejbeer |
592 |
// String result = tcl.getClient().validateRecharge(rechargeType, number, operatorId, ipAddress);
|
|
|
593 |
//log.info("validateRecharge Called" + number + " and rechargeType : " + rechargeType + ", IP:" + ipAddress + ", Operator:" + operatorId + ", Result:" + result);
|
|
|
594 |
//return result;
|
| 21514 |
kshitij.so |
595 |
} catch (Exception e) {
|
|
|
596 |
log.error("Unable to get service provider for Device number " + number + " and rechargeType : " + rechargeType, e);
|
|
|
597 |
}
|
|
|
598 |
return "Oops! There seems to be a problem. Please try after some time";
|
| 23585 |
tejbeer |
599 |
}*/
|
| 21514 |
kshitij.so |
600 |
|
|
|
601 |
|
| 21464 |
kshitij.so |
602 |
}
|