Subversion Repositories SmartDukaan

Rev

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