Subversion Repositories SmartDukaan

Rev

Rev 22411 | Rev 23037 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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