Subversion Repositories SmartDukaan

Rev

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

Rev 23115 Rev 23273
Line 23... Line 23...
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.util.Utils;
25
import com.spice.profitmandi.common.util.Utils;
26
import com.spice.profitmandi.common.web.util.ResponseSender;
26
import com.spice.profitmandi.common.web.util.ResponseSender;
27
import com.spice.profitmandi.dao.entity.dtr.User;
27
import com.spice.profitmandi.dao.entity.dtr.User;
28
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
28
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
29
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
29
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
30
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
30
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
31
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
31
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
32
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
32
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
33
import com.spice.profitmandi.thrift.clients.PaymentClient;
33
import com.spice.profitmandi.thrift.clients.PaymentClient;
Line 139... Line 139...
139
	})
139
	})
140
	@ApiOperation(value = "")
140
	@ApiOperation(value = "")
141
	public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
141
	public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
142
		throws ProfitMandiBusinessException{
142
		throws ProfitMandiBusinessException{
143
		int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
143
		int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
144
		UserAccounts userAccount = null;
144
		UserAccount userAccount = null;
145
		UserWallet wallet = null;
145
		UserWallet wallet = null;
146
		if (rechargeAmount <=0){
146
		if (rechargeAmount <=0){
147
			return responseSender.badRequest(null);
147
			return responseSender.badRequest(null);
148
		}
148
		}
149
 
149
 
150
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
150
		userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
151
		
151
		
152
		try {
152
		try {
153
			TransactionClient tc = new TransactionClient();
153
			TransactionClient tc = new TransactionClient();
154
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
154
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccountKey()));
155
		} catch (NumberFormatException | TException e) {
155
		} catch (NumberFormatException | TException e) {
156
			return responseSender.internalServerError(e);		
156
			return responseSender.internalServerError(e);		
157
		}
157
		}
158
 
158
 
159
		ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
159
		ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
Line 194... Line 194...
194
			crr.setReason(errorMessage);
194
			crr.setReason(errorMessage);
195
			crr.setResult(false);
195
			crr.setResult(false);
196
			return responseSender.badRequest(crr);
196
			return responseSender.badRequest(crr);
197
		}
197
		}
198
		int userId = (int)request.getAttribute("userId");
198
		int userId = (int)request.getAttribute("userId");
199
		UserAccounts userAccount = null;
199
		UserAccount userAccount = null;
200
		UserWallet wallet = null;
200
		UserWallet wallet = null;
201
		if (createRechargeRequest.getRechargeAmount() <=0){
201
		if (createRechargeRequest.getRechargeAmount() <=0){
202
			crr.setReason("Illegal recharge amount");
202
			crr.setReason("Illegal recharge amount");
203
			crr.setResult(false);
203
			crr.setResult(false);
204
			return responseSender.badRequest(crr);
204
			return responseSender.badRequest(crr);
205
		}
205
		}
206
 
206
 
207
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
207
		userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
208
		
208
		
209
		try {
209
		try {
210
			TransactionClient tc = new TransactionClient();
210
			TransactionClient tc = new TransactionClient();
211
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
211
			wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccountKey()));
212
		} catch (NumberFormatException | TException e) {
212
		} catch (NumberFormatException | TException e) {
213
			log.error("Unable to get user wallet ",e);
213
			log.error("Unable to get user wallet ",e);
214
			crr.setReason("We are experiencing some problem right now.");
214
			crr.setReason("We are experiencing some problem right now.");
215
			crr.setResult(false);
215
			crr.setResult(false);
216
			return responseSender.internalServerError(e);
216
			return responseSender.internalServerError(e);
Line 234... Line 234...
234
 
234
 
235
 
235
 
236
		RechargeOrder t_rechargeOrder = new RechargeOrder();
236
		RechargeOrder t_rechargeOrder = new RechargeOrder();
237
		t_rechargeOrder.setTotalAmount(createRechargeRequest.getRechargeAmount());
237
		t_rechargeOrder.setTotalAmount(createRechargeRequest.getRechargeAmount());
238
		t_rechargeOrder.setUserEmailId(user.getEmailId());
238
		t_rechargeOrder.setUserEmailId(user.getEmailId());
239
		t_rechargeOrder.setUserId(Long.valueOf(userAccount.getAccount_key()));
239
		t_rechargeOrder.setUserId(Long.valueOf(userAccount.getAccountKey()));
240
		t_rechargeOrder.setDeviceNumber(createRechargeRequest.getNumber());
240
		t_rechargeOrder.setDeviceNumber(createRechargeRequest.getNumber());
241
		t_rechargeOrder.setPlan(createRechargeRequest.getPlan()==null?"":createRechargeRequest.getPlan());
241
		t_rechargeOrder.setPlan(createRechargeRequest.getPlan()==null?"":createRechargeRequest.getPlan());
242
		t_rechargeOrder.setOperatorId(createRechargeRequest.getOperatorId());
242
		t_rechargeOrder.setOperatorId(createRechargeRequest.getOperatorId());
243
		t_rechargeOrder.setRechargeType(RechargeType.valueOf(createRechargeRequest.getRechargeType()));
243
		t_rechargeOrder.setRechargeType(RechargeType.valueOf(createRechargeRequest.getRechargeType()));
244
		t_rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
244
		t_rechargeOrder.setStatus(RechargeOrderStatus.PAYMENT_PENDING);
Line 376... Line 376...
376
				required = true, dataType = "string", paramType = "header")
376
				required = true, dataType = "string", paramType = "header")
377
	})
377
	})
378
	public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
378
	public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
379
		TransactionClient tc=null;
379
		TransactionClient tc=null;
380
		int userId = (int)request.getAttribute("userId");
380
		int userId = (int)request.getAttribute("userId");
381
		UserAccounts userAccount;
381
		UserAccount userAccount;
382
		List<RechargeOrder> rechargeOrders = null;
382
		List<RechargeOrder> rechargeOrders = null;
383
		
383
		
384
		userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
384
		userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
385
		
385
		
386
		try {
386
		try {
387
			tc = new TransactionClient();
387
			tc = new TransactionClient();
388
			rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccount_key()), offset, limit);
388
			rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccountKey()), offset, limit);
389
		} catch (Exception e) {
389
		} catch (Exception e) {
390
			log.error("Unable to get recharge order list",e);
390
			log.error("Unable to get recharge order list",e);
391
			return responseSender.internalServerError(e);
391
			return responseSender.internalServerError(e);
392
		}
392
		}
393
		List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
393
		List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();