Subversion Repositories SmartDukaan

Rev

Rev 22411 | Rev 23037 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22411 Rev 22931
Line 25... Line 25...
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
26
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.model.ProfitMandiResponse;
27
import com.spice.profitmandi.common.model.ProfitMandiResponse;
28
import com.spice.profitmandi.common.model.ResponseStatus;
28
import com.spice.profitmandi.common.model.ResponseStatus;
29
import com.spice.profitmandi.common.util.Utils;
29
import com.spice.profitmandi.common.util.Utils;
-
 
30
import com.spice.profitmandi.common.web.util.ResponseSender;
30
import com.spice.profitmandi.dao.entity.dtr.User;
31
import com.spice.profitmandi.dao.entity.dtr.User;
31
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
32
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
32
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
33
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
33
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
35
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
Line 62... Line 63...
62
 
63
 
63
	private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
64
	private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
64
	private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
65
	private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
65
 
66
 
66
	@Autowired
67
	@Autowired
67
	UserAccountRepository userAccountRepository;
68
	private UserAccountRepository userAccountRepository;
68
 
69
 
69
	@Autowired
70
	@Autowired
70
	UserRepository userRepository;
71
	private UserRepository userRepository;
-
 
72
	
-
 
73
	@Autowired
-
 
74
	private ResponseSender<?> responseSender;
71
 
75
 
72
	@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
76
	@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
73
	@ApiImplicitParams({
77
	@ApiImplicitParams({
74
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
78
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
75
				required = true, dataType = "string", paramType = "header")
79
				required = true, dataType = "string", paramType = "header")
Line 82... Line 86...
82
			tcl = new TransactionClient();
86
			tcl = new TransactionClient();
83
			deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
87
			deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
84
		} catch (Exception e) {
88
		} catch (Exception e) {
85
			log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  rechargeType, e);
89
			log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  rechargeType, e);
86
		}
90
		}
87
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, deviceInfo);
-
 
88
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
91
		return responseSender.ok(deviceInfo);
89
	}
92
	}
90
 
93
 
91
	@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
94
	@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
92
	@ApiImplicitParams({
95
	@ApiImplicitParams({
93
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
96
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
Line 101... Line 104...
101
			tcl = new TransactionClient();
104
			tcl = new TransactionClient();
102
			rechargeDenominations =  tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
105
			rechargeDenominations =  tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
103
		} catch (Exception e) {
106
		} catch (Exception e) {
104
			log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
107
			log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
105
		}
108
		}
106
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rechargeDenominations);
-
 
107
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
109
		return responseSender.ok(rechargeDenominations);
108
	}
110
	}
109
 
111
 
110
	@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
112
	@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
111
	@ApiImplicitParams({
113
	@ApiImplicitParams({
112
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
114
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
113
				required = true, dataType = "string", paramType = "header")
115
				required = true, dataType = "string", paramType = "header")
114
	})
116
	})
115
	@ApiOperation(value = "")
117
	@ApiOperation(value = "")
116
	public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
118
	public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
117
		Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
119
		Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
118
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, mobileProviderMap);
-
 
119
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
120
		return responseSender.ok(mobileProviderMap);
120
	}
121
	}
121
 
122
 
122
	@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
123
	@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
123
	@ApiImplicitParams({
124
	@ApiImplicitParams({
124
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
125
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
125
				required = true, dataType = "string", paramType = "header")
126
				required = true, dataType = "string", paramType = "header")
126
	})
127
	})
127
	@ApiOperation(value = "")
128
	@ApiOperation(value = "")
128
	public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
129
	public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
129
		Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
130
		Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
130
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dthProviderMap);
-
 
131
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
131
		return responseSender.ok(dthProviderMap);
132
	}
132
	}
133
 
133
 
134
	@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
134
	@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
135
	@ApiImplicitParams({
135
	@ApiImplicitParams({
136
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
136
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
137
				required = true, dataType = "string", paramType = "header")
137
				required = true, dataType = "string", paramType = "header")
138
	})
138
	})
139
	@ApiOperation(value = "")
139
	@ApiOperation(value = "")
140
	public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount){
140
	public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
-
 
141
		throws ProfitMandiBusinessException{
141
		int userId = (int)request.getAttribute("userId");
142
		int userId = (int)request.getAttribute("userId");
142
		UserAccounts userAccount = null;
143
		UserAccounts userAccount = null;
143
		UserWallet wallet = null;
144
		UserWallet wallet = null;
144
		if (rechargeAmount <=0){
145
		if (rechargeAmount <=0){
145
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, null);
-
 
146
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
146
			return responseSender.badRequest(null);
147
		}
147
		}
148
 
148
 
149
		try {
-
 
150
			userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
149
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
151
		} catch (ProfitMandiBusinessException e) {
-
 
152
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, null);
-
 
153
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
154
		}
150
		
155
		try {
151
		try {
156
			TransactionClient tc = new TransactionClient();
152
			TransactionClient tc = new TransactionClient();
157
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
153
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
158
		} catch (NumberFormatException | TException e) {
154
		} catch (NumberFormatException | TException e) {
159
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, null);
-
 
160
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
155
			return responseSender.internalServerError(e);		
161
		}
156
		}
162
 
157
 
163
		ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
158
		ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
164
		crr.setWalletAmount(wallet.getAmount());
159
		crr.setWalletAmount(wallet.getAmount());
165
		crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
160
		crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
166
		crr.setCanProceed(true);
161
		crr.setCanProceed(true);
167
		if (crr.getWalletAmountLeft() < 0){
162
		if (crr.getWalletAmountLeft() < 0){
168
			crr.setCanProceed(false);
163
			crr.setCanProceed(false);
169
			crr.setReason("You don't have sufficient wallet balance");
164
			crr.setReason("You don't have sufficient wallet balance");
170
		}
165
		}
171
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, crr);
-
 
172
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
166
		return responseSender.ok(crr);
173
	}
167
	}
174
 
168
 
175
	@RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
169
	@RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
176
	@ApiImplicitParams({
170
	@ApiImplicitParams({
177
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
171
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
178
				required = true, dataType = "string", paramType = "header")
172
				required = true, dataType = "string", paramType = "header")
179
	})
173
	})
180
	public ResponseEntity<?> createRecharge(HttpServletRequest request, @RequestBody CreateRechargeRequest createRechargeRequest){
174
	public ResponseEntity<?> createRecharge(HttpServletRequest request, @RequestBody CreateRechargeRequest createRechargeRequest)
-
 
175
		throws ProfitMandiBusinessException{
181
		String ipAddress  = remoteAddr(request);
176
		String ipAddress  = remoteAddr(request);
182
		String errorMessage = validateRecharge(RechargeType.valueOf(createRechargeRequest.getRechargeType()), createRechargeRequest.getNumber(), createRechargeRequest.getOperatorId(), ipAddress);
177
		String errorMessage = validateRecharge(RechargeType.valueOf(createRechargeRequest.getRechargeType()), createRechargeRequest.getNumber(), createRechargeRequest.getOperatorId(), ipAddress);
183
		CreateRechargeResponse crr =  new CreateRechargeResponse();
178
		CreateRechargeResponse crr =  new CreateRechargeResponse();
184
		if(!errorMessage.equals("SUCCESS")){
179
		if(!errorMessage.equals("SUCCESS")){
185
			crr.setReason(errorMessage);
180
			crr.setReason(errorMessage);
186
			crr.setResult(false);
181
			crr.setResult(false);
187
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, crr);
-
 
188
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
182
			return responseSender.badRequest(crr);
189
		}
183
		}
190
		int userId = (int)request.getAttribute("userId");
184
		int userId = (int)request.getAttribute("userId");
191
		UserAccounts userAccount = null;
185
		UserAccounts userAccount = null;
192
		UserWallet wallet = null;
186
		UserWallet wallet = null;
193
		if (createRechargeRequest.getRechargeAmount() <=0){
187
		if (createRechargeRequest.getRechargeAmount() <=0){
194
			crr.setReason("Illegal recharge amount");
188
			crr.setReason("Illegal recharge amount");
195
			crr.setResult(false);
189
			crr.setResult(false);
196
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, crr);
-
 
197
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
190
			return responseSender.badRequest(crr);
198
		}
191
		}
199
 
192
 
200
		try {
-
 
201
			userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
193
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
202
		} catch (ProfitMandiBusinessException e) {
-
 
203
			log.error("Unable to get user account ",e);
-
 
204
			crr.setReason("We are experiencing some problem right now.");
-
 
205
			crr.setResult(false);
-
 
206
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
207
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
208
		}
194
		
209
		try {
195
		try {
210
			TransactionClient tc = new TransactionClient();
196
			TransactionClient tc = new TransactionClient();
211
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
197
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
212
		} catch (NumberFormatException | TException e) {
198
		} catch (NumberFormatException | TException e) {
213
			log.error("Unable to get user wallet ",e);
199
			log.error("Unable to get user wallet ",e);
214
			crr.setReason("We are experiencing some problem right now.");
200
			crr.setReason("We are experiencing some problem right now.");
215
			crr.setResult(false);
201
			crr.setResult(false);
216
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
217
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
202
			return responseSender.internalServerError(e);
218
		}
203
		}
219
 
204
 
220
		if (wallet.getAmount() < createRechargeRequest.getRechargeAmount()){
205
		if (wallet.getAmount() < createRechargeRequest.getRechargeAmount()){
221
			crr.setReason("You don't have sufficient wallet balance.");
206
			crr.setReason("You don't have sufficient wallet balance.");
222
			crr.setResult(false);
207
			crr.setResult(false);
223
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, crr);
-
 
224
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
208
			return responseSender.badRequest(crr);
225
		}
209
		}
226
 
210
 
227
		User user = null;
211
		User user = null;
228
		try {
212
		try {
229
			user = userRepository.selectById(userId);
213
			user = userRepository.selectById(userId);
230
		} catch (ProfitMandiBusinessException e) {
214
		} catch (ProfitMandiBusinessException e) {
231
			log.error("Unable to get user",e);
215
			log.error("Unable to get user",e);
232
			crr.setReason("We are experiencing some problem right now.");
216
			crr.setReason("We are experiencing some problem right now.");
233
			crr.setResult(false);
217
			crr.setResult(false);
234
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
235
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
218
			return responseSender.internalServerError(e);
236
		}
219
		}
237
 
220
 
238
 
221
 
239
		RechargeOrder t_rechargeOrder = new RechargeOrder();
222
		RechargeOrder t_rechargeOrder = new RechargeOrder();
240
		t_rechargeOrder.setTotalAmount(createRechargeRequest.getRechargeAmount());
223
		t_rechargeOrder.setTotalAmount(createRechargeRequest.getRechargeAmount());
Line 257... Line 240...
257
			rechargeOrder = tc.getClient().createRechargeOrder(t_rechargeOrder);
240
			rechargeOrder = tc.getClient().createRechargeOrder(t_rechargeOrder);
258
		} catch (TransactionServiceException | TException e) {
241
		} catch (TransactionServiceException | TException e) {
259
			log.error("Unable to create recharge order",e);
242
			log.error("Unable to create recharge order",e);
260
			crr.setReason("We are experiencing some problem right now.");
243
			crr.setReason("We are experiencing some problem right now.");
261
			crr.setResult(false);
244
			crr.setResult(false);
262
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
263
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
245
			return responseSender.internalServerError(e);
264
		}
246
		}
265
 
247
 
266
		log.info("Recharge Order:" + rechargeOrder);
248
		log.info("Recharge Order:" + rechargeOrder);
267
		PaymentClient paymentServiceClient = null;
249
		PaymentClient paymentServiceClient = null;
268
		try {
250
		try {
269
			paymentServiceClient = new PaymentClient();
251
			paymentServiceClient = new PaymentClient();
270
		} catch (TTransportException e) {
252
		} catch (TTransportException e) {
271
			log.error("Unable to create payment client",e);
253
			log.error("Unable to create payment client",e);
272
			crr.setReason("We are experiencing some problem right now.");
254
			crr.setReason("We are experiencing some problem right now.");
273
			crr.setResult(false);
255
			crr.setResult(false);
274
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
275
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
256
			return responseSender.internalServerError(e);
276
		}
257
		}
277
		try {
258
		try {
278
			RechargeOrder d_rechargeOrder = tc.getClient().getRechargeOrder(rechargeOrder.getId());
259
			RechargeOrder d_rechargeOrder = tc.getClient().getRechargeOrder(rechargeOrder.getId());
279
			List<Payment> payments = paymentServiceClient.getClient().getPaymentForRechargeTxnId(d_rechargeOrder.getTransactionId());
260
			List<Payment> payments = paymentServiceClient.getClient().getPaymentForRechargeTxnId(d_rechargeOrder.getTransactionId());
280
			if(payments.size() > 0) {
261
			if(payments.size() > 0) {
Line 296... Line 277...
296
			crr.setResult(true);
277
			crr.setResult(true);
297
		} catch (Exception e) {
278
		} catch (Exception e) {
298
			log.error("Unable to mark the payment as authorized", e);
279
			log.error("Unable to mark the payment as authorized", e);
299
			crr.setReason("We are experiencing some problem right now.");
280
			crr.setReason("We are experiencing some problem right now.");
300
			crr.setResult(false);
281
			crr.setResult(false);
301
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, crr);
-
 
302
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
282
			return responseSender.internalServerError(e);
303
		}
283
		}
304
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, crr);
284
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, crr);
305
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
285
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
306
	}
286
	}
307
 
287
 
Line 321... Line 301...
321
			// return with internal server error
301
			// return with internal server error
322
			e.printStackTrace();
302
			e.printStackTrace();
323
			rrp = new RechargeResultPojo();
303
			rrp = new RechargeResultPojo();
324
			rrp.setIsError(true);
304
			rrp.setIsError(true);
325
			rrp.setDetailDisplayMessage("We are experiencing some problem right now.");
305
			rrp.setDetailDisplayMessage("We are experiencing some problem right now.");
326
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, rrp);
-
 
327
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
306
			return responseSender.internalServerError(e);
328
		}
307
		}
329
		if (rechargeOrder == null){
308
		if (rechargeOrder == null){
330
			rrp = new RechargeResultPojo();
309
			rrp = new RechargeResultPojo();
331
			rrp.setIsError(true);
310
			rrp.setIsError(true);
332
			rrp.setDetailDisplayMessage("Recharge order doesnot exist in our system.");
311
			rrp.setDetailDisplayMessage("Recharge order doesnot exist in our system.");
333
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, rrp);
-
 
334
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
312
			return responseSender.badRequest(rrp);
335
		}
313
		}
336
		String[] os = Utils.getOrderStatus(rechargeOrder.getStatus());
314
		String[] os = Utils.getOrderStatus(rechargeOrder.getStatus());
337
		rrp = new RechargeResultPojo();
315
		rrp = new RechargeResultPojo();
338
		rrp.setRechargeDeviceNumber(rechargeOrder.getDeviceNumber());
316
		rrp.setRechargeDeviceNumber(rechargeOrder.getDeviceNumber());
339
		rrp.setRechargeDisplayId(rechargeOrder.getDisplayId());
317
		rrp.setRechargeDisplayId(rechargeOrder.getDisplayId());
Line 343... Line 321...
343
		rrp.setRechargeStatus(os[1]);
321
		rrp.setRechargeStatus(os[1]);
344
		rrp.setDetailDisplayMessage(os[2]);
322
		rrp.setDetailDisplayMessage(os[2]);
345
		if (rechargeOrder.getStatus().equals(RechargeOrderStatus.RECHARGE_UNKNOWN)){
323
		if (rechargeOrder.getStatus().equals(RechargeOrderStatus.RECHARGE_UNKNOWN)){
346
			rrp.setPoll(true);
324
			rrp.setPoll(true);
347
		}
325
		}
348
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rrp);
-
 
349
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
326
		return responseSender.badRequest(rrp);
350
	}
327
	}
351
 
328
 
352
	@RequestMapping(value = ProfitMandiConstants.URL_POLL_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
329
	@RequestMapping(value = ProfitMandiConstants.URL_POLL_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
353
	@ApiImplicitParams({
330
	@ApiImplicitParams({
354
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
331
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
Line 363... Line 340...
363
			t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
340
			t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
364
		}
341
		}
365
		catch(Exception e){
342
		catch(Exception e){
366
			rrp = new RechargeResultPojo();
343
			rrp = new RechargeResultPojo();
367
			rrp.setRechargeStatus("");
344
			rrp.setRechargeStatus("");
368
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, rrp);
-
 
369
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);	
345
			return responseSender.internalServerError(e);
370
		}
346
		}
371
		if (t_rechargeOrder == null){
347
		if (t_rechargeOrder == null){
372
			rrp = new RechargeResultPojo();
348
			rrp = new RechargeResultPojo();
373
			rrp.setRechargeStatus("");
349
			rrp.setRechargeStatus("");
374
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, new RechargeResultPojo());
350
			return responseSender.badRequest(new RechargeResultPojo());
375
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);	
-
 
376
		}
351
		}
377
		rrp = new RechargeResultPojo();
352
		rrp = new RechargeResultPojo();
378
		String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
353
		String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
379
		rrp.setIsError(Boolean.parseBoolean(os[0]));
354
		rrp.setIsError(Boolean.parseBoolean(os[0]));
380
		rrp.setRechargeStatus(os[1]);
355
		rrp.setRechargeStatus(os[1]);
381
		rrp.setDetailDisplayMessage(os[2]);
356
		rrp.setDetailDisplayMessage(os[2]);
382
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rrp);
-
 
383
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
357
		return responseSender.ok(rrp);
384
	}
358
	}
385
	
359
	
386
	@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
360
	@RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
387
	@ApiImplicitParams({
361
	@ApiImplicitParams({
388
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
362
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
389
				required = true, dataType = "string", paramType = "header")
363
				required = true, dataType = "string", paramType = "header")
390
	})
364
	})
391
	public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit){
365
	public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
392
		TransactionClient tc=null;
366
		TransactionClient tc=null;
393
		int userId = (int)request.getAttribute("userId");
367
		int userId = (int)request.getAttribute("userId");
394
		UserAccounts userAccount;
368
		UserAccounts userAccount;
395
		List<RechargeOrder> rechargeOrders = null;
369
		List<RechargeOrder> rechargeOrders = null;
396
		try {
370
		
397
			userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
371
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
398
		} catch (ProfitMandiBusinessException e) {
-
 
399
			log.error("Unable to get user account ",e);
-
 
400
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, new ArrayList<MyRechargesResponse>());
372
		
401
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
402
		}
-
 
403
		try {
373
		try {
404
			tc = new TransactionClient();
374
			tc = new TransactionClient();
405
			rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccount_key()), offset, limit);
375
			rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccount_key()), offset, limit);
406
		} catch (Exception e) {
376
		} catch (Exception e) {
407
			log.error("Unable to get recharge order list",e);
377
			log.error("Unable to get recharge order list",e);
408
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, new ArrayList<MyRechargesResponse>());
378
			return responseSender.internalServerError(e);
409
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
-
 
410
		}
379
		}
411
		List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
380
		List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
412
		for (RechargeOrder rechargeOrder : rechargeOrders){
381
		for (RechargeOrder rechargeOrder : rechargeOrders){
413
			MyRechargesResponse rp = new MyRechargesResponse();
382
			MyRechargesResponse rp = new MyRechargesResponse();
414
			if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
383
			if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
Line 426... Line 395...
426
        	rp.setAmount(rechargeOrder.getTotalAmount());
395
        	rp.setAmount(rechargeOrder.getTotalAmount());
427
        	rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
396
        	rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
428
        	rp.setDisplayOrderId(rechargeOrder.getDisplayId());
397
        	rp.setDisplayOrderId(rechargeOrder.getDisplayId());
429
        	myRechargesList.add(rp);
398
        	myRechargesList.add(rp);
430
		}
399
		}
431
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, myRechargesList);
-
 
432
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
400
		return responseSender.ok(myRechargesList);
433
	}
401
	}
434
 
402
 
435
	
403
	
436
	private String remoteAddr(HttpServletRequest request) {
404
	private String remoteAddr(HttpServletRequest request) {
437
		String remoteAddr = "";
405
		String remoteAddr = "";