Subversion Repositories SmartDukaan

Rev

Rev 24276 | Rev 24893 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.swing.SortOrder;

import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.spice.profitmandi.common.enumuration.RechargeStatus;
import com.spice.profitmandi.common.enumuration.SchemeType;
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.CustomPaymentOption;
import com.spice.profitmandi.common.model.OperatorType;
import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.model.RechargeCredential;
import com.spice.profitmandi.common.model.RechargeRequest;
import com.spice.profitmandi.common.model.RechargeResponse;
import com.spice.profitmandi.common.util.Utils;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.entity.dtr.RechargeCommission;
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
import com.spice.profitmandi.dao.entity.dtr.User;
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
import com.spice.profitmandi.dao.enumuration.dtr.RechargeType;
import com.spice.profitmandi.dao.repository.GenericRepository;
import com.spice.profitmandi.dao.repository.dtr.RechargeCommissionRepository;
import com.spice.profitmandi.dao.repository.dtr.RechargeOperatorRepository;
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
import com.spice.profitmandi.dao.repository.transaction.PendingRechargeCommissionRepository;
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
import com.spice.profitmandi.service.recharge.RechargeService;
import com.spice.profitmandi.thrift.clients.PaymentClient;
import com.spice.profitmandi.thrift.clients.TransactionClient;
import com.spice.profitmandi.web.req.CreateRechargeRequest;
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
import com.spice.profitmandi.web.res.CreateRechargeResponse;
import com.spice.profitmandi.web.res.MyRechargesResponse;
import com.spice.profitmandi.web.res.RechargeResultPojo;
import com.spice.profitmandi.dao.entity.transaction.UserWallet;

import in.shop2020.model.v1.order.DenominationType;
import in.shop2020.model.v1.order.DeviceNumberInfo;
import in.shop2020.model.v1.order.OrderType;
import in.shop2020.model.v1.order.RechargeDenomination;
import in.shop2020.model.v1.order.RechargeOrder;
import in.shop2020.model.v1.order.RechargeOrderStatus;
import in.shop2020.model.v1.order.TransactionServiceException;

import in.shop2020.payments.Payment;
import in.shop2020.payments.PaymentException;
import in.shop2020.payments.PaymentStatus;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
@Transactional(rollbackFor=Throwable.class)
public class RechargeController {

        private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
        private static final String HEADER_X_FORWARDED_FOR = "X-FORWARDED-FOR";
        
        private List<String> blockedRecharge = Arrays.asList();
        private static final String X_REAL_IP = "X-Real-IP";
        @Value("${oxigen.recharge.transaction.url}")
        private String oxigenRechargeTransactionUrl;
        
        @Value("${oxigen.recharge.enquiry.url}")
        private String oxigenRechargeEnquiryUrl;
        
        @Value("${oxigen.recharge.auth.key}")
        private String oxigenRechargeAuthKey;
        
        @Value("${oxigen.recharge.validation.url}")
        private String oxigenRechargeValidationUrl;
        
        @Value("${oxigen.recharge.validation.auth.key}")
        private String oxigenRechargeValidationAuthKey;
        
        @Value("${think.walnut.digital.recharge.transaction.mobile.url}")
        private String thinkWalnutDigitalRechargeTransactionMobileUrl;
        
        @Value("${think.walnut.digital.recharge.transaction.mobile.username}")
        private String thinkWalnutDigitalRechargeTransactionMobileUserName;
        
        @Value("${think.walnut.digital.recharge.transaction.mobile.password}")
        private String thinkWalnutDigitalRechargeTransactionMobilePassword;
        
        @Value("${think.walnut.digital.recharge.transaction.dth.url}")
        private String thinkWalnutDigitalRechargeTransactionDthUrl;
        
        @Value("${think.walnut.digital.recharge.transaction.dth.username}")
        private String thinkWalnutDigitalRechargeTransactionDthUserName;
        
        @Value("${think.walnut.digital.recharge.transaction.dth.password}")
        private String thinkWalnutDigitalRechargeTransactionDthPassword;
        
        @Value("${think.walnut.digital.recharge.enquiry.url}")
        private String thinkWalnutDigitalRechargeEnquiryUrl;
        
        @Value("${think.walnut.digital.recharge.enquiry.username}")
        private String thinkWalnutDigitalRechargeEnquiryUserName;
        
        @Value("${think.walnut.digital.recharge.enquiry.password}")
        private String thinkWalnutDigitalRechargeEnquiryPassword;
        
        @Value("${think.walnut.digital.recharge.auth.key}")
        private String thinkWalnutDigitalRechargeAuthKey;
        
        @Autowired
        UserWalletRepository userWalletRepository;
        
        @Autowired
        private GenericRepository genericRepository;
        
        @Autowired
        private RechargeCommissionRepository rechargeCommissionRepository;
        
        @Autowired
        private UserAccountRepository userAccountRepository;
        
        @Autowired
        private RechargeTransactionRepository rechargeTransactionRepository;

        @Autowired
        private RechargeProviderRepository rechargeProviderRepository;
        
        @Autowired
        private UserRepository userRepository;
        
        @Autowired
        private RechargeOperatorRepository rechargeOperatorRepository;
        
        @Autowired
        private RechargeService rechargeService;
        
        @Autowired
        private PendingRechargeCommissionRepository pendingRechargeCommissionRepository;
        
        @Autowired
        private ResponseSender<?> responseSender;
        
        private RechargeCredential rechargeTransactionMobileCredential;
        private RechargeCredential rechargeTransactionDthCredential;
        private RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential;

        @RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> getServiceProvider(HttpServletRequest request, @RequestParam(value="deviceNumber") String deviceNumber, @RequestParam(value="rechargeType") String rechargeType){
                DeviceNumberInfo deviceInfo = null;
                TransactionClient tcl;
                try {
                        tcl = new TransactionClient();
                        //deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
                } catch (Exception e) {
                        log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  rechargeType, e);
                }
                return responseSender.ok(deviceInfo);
        }

        @RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> getAllDenominations(HttpServletRequest request, @RequestParam(value="operatorId") long operatorId, @RequestParam(value="circleCode") String circleCode, @RequestParam(value="denominationType") String denominationType){
                List<RechargeDenomination> rechargeDenominations = new ArrayList<RechargeDenomination>();
                TransactionClient tcl;
                try {
                        tcl = new TransactionClient();
                        rechargeDenominations =  tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
                } catch (Exception e) {
                        log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
                }
                return responseSender.ok(rechargeDenominations);
        }

        @RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        
        @ApiOperation(value = "")
        public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request,@RequestParam(name = ProfitMandiConstants.OPERATOR_TYPE) OperatorType operatorType){
                Map<Integer, String> mobileProviderMap = new HashMap<>();
                List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(operatorType);
        //      List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE);
                for(RechargeOperator rechargeOperator : rechargeOperators) {
                mobileProviderMap.put(rechargeOperator.getId(), rechargeOperator.getName());
            }
                return responseSender.ok(mobileProviderMap);
        }

        @RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
                Map<Integer, String> dthProviderMap = new HashMap<>();
                List<RechargeOperator> dthOperators = rechargeOperatorRepository.selectAllByRechargeType(RechargeType.DTH);
                for(RechargeOperator dthOperator : dthOperators) {
                        dthProviderMap.put(dthOperator.getId(), dthOperator.getName());
                }
                return responseSender.ok(dthProviderMap);
                
                
        }

        @RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount)
                throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
                UserAccount userAccount = null;
                UserWallet wallet = null;
                if (rechargeAmount <=0){
                        return responseSender.badRequest(null);
                }

                userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
                
                try {
                        TransactionClient tc = new TransactionClient();
                        //wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccountKey()));
                } catch (NumberFormatException | TException e) {
                        return responseSender.internalServerError(e);           
                }

                ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
                //crr.setWalletAmount(wallet.getAmount());
                crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
                crr.setCanProceed(true);
                if (crr.getWalletAmountLeft() < 0){
                        crr.setCanProceed(false);
                        crr.setReason("You don't have sufficient wallet balance");
                }
                return responseSender.ok(crr);
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_PENDING_COMMISSION, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        @ApiOperation(value = "")
        public ResponseEntity<?> getPendingRechargeCommission(HttpServletRequest request)
                throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
                int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
                return responseSender.ok(pendingRechargeCommissionRepository.selectByRetailerId(retailerId));
        }
        
        private RechargeRequest convertRechargeRequest (CreateRechargeRequest createRechargeRequest ){
                RechargeRequest rr= new RechargeRequest();
                rr.setAmount(createRechargeRequest.getRechargeAmount());
                rr.setOperatorId((int) createRechargeRequest.getOperatorId());
                rr.setOperatorType(createRechargeRequest.getPlan());
                rr.setReferenceNumber(createRechargeRequest.getNumber());
                rr.setRechargeType(createRechargeRequest.getRechargeType());
                
                Set<CustomPaymentOption> pp = new LinkedHashSet<>();
                CustomPaymentOption cpo = new CustomPaymentOption();
                cpo.setPaymentOption("cash");
                cpo.setPaymentOptionId(1);
                cpo.setAmount(createRechargeRequest.getRechargeAmount());
                pp.add(cpo);
                rr.setPaymentOptions(pp);
            return rr;
        }
        
        @PostConstruct  
        private void setRechargeCredentials() {
                rechargeTransactionMobileCredential = new RechargeCredential();
                rechargeTransactionMobileCredential.setRechargeUrl(thinkWalnutDigitalRechargeTransactionMobileUrl);
                rechargeTransactionMobileCredential.setRechargeUserName(thinkWalnutDigitalRechargeTransactionMobileUserName);
                rechargeTransactionMobileCredential.setRechargePassword(thinkWalnutDigitalRechargeTransactionMobilePassword);
                rechargeTransactionMobileCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
                
                rechargeTransactionDthCredential = new RechargeCredential();
                rechargeTransactionDthCredential.setRechargeUrl(thinkWalnutDigitalRechargeTransactionDthUrl);
                rechargeTransactionDthCredential.setRechargeUserName(thinkWalnutDigitalRechargeTransactionDthUserName);
                rechargeTransactionDthCredential.setRechargePassword(thinkWalnutDigitalRechargeTransactionDthPassword);
                rechargeTransactionDthCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        
        public ResponseEntity<?> createRecharge(HttpServletRequest request, @RequestBody CreateRechargeRequest createRechargeRequest)
                throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
                int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
                String ipAddress  = remoteAddr(request);
                
            CreateRechargeResponse crr =  new CreateRechargeResponse();
            
            UserAccount userAccount = null;
            UserWallet wallet = null;
                wallet = userWalletRepository.selectByRetailerId(retailerId);
                
                if (createRechargeRequest.getRechargeAmount() <=0){
                        crr.setReason("Illegal recharge amount");
                        crr.setResult(false);
                        return responseSender.badRequest(crr);
                }

                if (wallet.getAmount() < createRechargeRequest.getRechargeAmount()){
                        crr.setReason("You don't have sufficient wallet balance.");
                        crr.setResult(false);
                        return responseSender.badRequest(crr);
                }

                User user = null;
                try {
                        user = userRepository.selectById(userId);
                } catch (ProfitMandiBusinessException e) {
                        log.error("Unable to get user",e);
                        crr.setReason("We are experiencing some problem right now.");
                        crr.setResult(false);
                        return responseSender.internalServerError(e);
                }

                
                RechargeRequest rechargeRequest = convertRechargeRequest(createRechargeRequest);
                if(blockedRecharge.contains(user.getEmailId())) {
                        throw new ProfitMandiBusinessException("Recharge Provider", createRechargeRequest.getOperatorId(), "We are experiencing some problem right now.");
                }
                RechargeResponse rechargeResponse = rechargeService.doRecharge(oxigenRechargeTransactionUrl, oxigenRechargeAuthKey, oxigenRechargeValidationUrl,
                                oxigenRechargeValidationAuthKey, rechargeTransactionMobileCredential, rechargeTransactionDthCredential, retailerId, rechargeRequest);
                
                crr.setResult(rechargeResponse.getStatus().equals(RechargeStatus.SUCCESS));
                crr.setRequestId(rechargeResponse.getRequestId());
            
                if(RechargeType.valueOf(rechargeRequest.getRechargeType()) == RechargeType.MOBILE) {
                 return responseSender.ok(crr);
                }else {
                         return responseSender.ok(crr);
                }
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_SUMMARY , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        public ResponseEntity<?>rechargeSummary (HttpServletRequest request , @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit)
                throws ProfitMandiBusinessException{
                int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
                int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
                //RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
                List<RechargeTransaction> rechargeTransactions =rechargeTransactionRepository.selectAllByRetailerId(retailerId, offset, limit);
                for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
                         String operatorName=rechargeOperatorRepository.selectById(rechargeTransaction.getOperatorId()).getName();
                        rechargeTransaction.setOperatorName(operatorName);
                }
                
                        return responseSender.ok(rechargeTransactions);
                
                        
        }
                
        @RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_COMMISSIONS , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        public ResponseEntity<?>rechargeCommissions (HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "60") int limit)
                throws ProfitMandiBusinessException{
                List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
                for (RechargeCommission rechargeCommission : rechargeCommissions) {
                         String operatorName=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getName();
                         RechargeType rechargeType=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getRechargeType();
                         OperatorType operatorType=rechargeOperatorRepository.selectById(rechargeCommission.getOperatorId()).getOperatorType();
                         rechargeCommission.setOperatorName(operatorName);
                         rechargeCommission.setRechargeType(rechargeType);
                         rechargeCommission.setOperatorType(operatorType);
                }
                Map<Integer,RechargeCommission> commissionMap = rechargeCommissions.stream().collect(Collectors.groupingBy(RechargeCommission::getOperatorId, Collectors.collectingAndThen(
                                Collectors.reducing((RechargeCommission d1,RechargeCommission d2) -> d1.getAmount() > d2.getAmount() ? d1 : d2),
                                               Optional::get)));
                
                return responseSender.ok(commissionMap.values());
        }
        
        @PostConstruct  
        private void setRechargeEnquiryCredentials() {
                thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
                thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
                thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeEnquiryUserName);
                thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargeEnquiryPassword);
                thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_RESULT , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        

        public ResponseEntity<?> rechargeResult(HttpServletRequest request, @RequestParam(value="requestId") String requestId ) throws ProfitMandiBusinessException{
                RechargeOrder rechargeOrder = null;
                RechargeResultPojo rrp = null;
                
                
                //RechargeResponse rr =  new RechargeResponse();
                //String requestId = rr.getRequestId();
                int userId = (int)request.getAttribute(ProfitMandiConstants.USER_ID);
            int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
          
                RechargeResponse rechargeResponse = rechargeService.checkStatus(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey, thinkWalnutDigitalRechargeEnquiryCredential,retailerId , requestId);
                return responseSender.ok(rechargeResponse);
        }

        @RequestMapping(value = ProfitMandiConstants.URL_POLL_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        public ResponseEntity<?> pollRechargeResult(HttpServletRequest request, @RequestParam(value="rechargeOrderId") long rechargeOrderId, @RequestParam(value="finalCall") boolean finalCall){
                TransactionClient transactionServiceClient = null;
                RechargeOrder t_rechargeOrder = null;
                RechargeResultPojo rrp = null;
                try{
                        transactionServiceClient = new TransactionClient();
                        t_rechargeOrder = transactionServiceClient.getClient().getRcgOrderStatus(rechargeOrderId, finalCall);
                }
                catch(Exception e){
                        rrp = new RechargeResultPojo();
                        rrp.setRechargeStatus("");
                        return responseSender.internalServerError(e);
                }
                if (t_rechargeOrder == null){
                        rrp = new RechargeResultPojo();
                        rrp.setRechargeStatus("");
                        return responseSender.badRequest(new RechargeResultPojo());
                }
                rrp = new RechargeResultPojo();
                String[] os = Utils.getOrderStatus(t_rechargeOrder.getStatus());
                rrp.setIsError(Boolean.parseBoolean(os[0]));
                rrp.setRechargeStatus(os[1]);
                rrp.setDetailDisplayMessage(os[2]);
                return responseSender.ok(rrp);
        }
        
        @RequestMapping(value = ProfitMandiConstants.URL_MY_RECHARGES , method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
                                required = true, dataType = "string", paramType = "header")
        })
        public ResponseEntity<?> myRecharges(HttpServletRequest request, @RequestParam(value="offset") int offset, @RequestParam(value="limit") int limit) throws ProfitMandiBusinessException{
                TransactionClient tc=null;
                int userId = (int)request.getAttribute("userId");
                UserAccount userAccount;
                List<RechargeOrder> rechargeOrders = null;
                
                userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
                
                try {
                        tc = new TransactionClient();
                        rechargeOrders = tc.getClient().getPaginatedRechargeOrders(Long.valueOf(userAccount.getAccountKey()), offset, limit);
                } catch (Exception e) {
                        log.error("Unable to get recharge order list",e);
                        return responseSender.internalServerError(e);
                }
                List<MyRechargesResponse> myRechargesList = new ArrayList<MyRechargesResponse>();
                for (RechargeOrder rechargeOrder : rechargeOrders){
                        MyRechargesResponse rp = new MyRechargesResponse();
                /*      if(rechargeOrder.getRechargeType() == RechargeType.MOBILE){
                        rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
                        rp.setOperatorType("MOBILE");
                }
                if(rechargeOrder.getRechargeType() == RechargeType.DTH){
                        rp.setOperator(Utils.getProvider(rechargeOrder.getOperatorId()));
                        rp.setOperatorType("DTH");
                }*/
                rp.setOrderId(rechargeOrder.getId());
                rp.setOperatorId(rechargeOrder.getOperatorId());
                rp.setDate(rechargeOrder.getCreationTimestamp());
                rp.setNumber(rechargeOrder.getDeviceNumber());
                rp.setAmount(rechargeOrder.getTotalAmount());
                rp.setStatus(Utils.getRechargeDisplayStatus(rechargeOrder.getStatus()));
                rp.setDisplayOrderId(rechargeOrder.getDisplayId());
                myRechargesList.add(rp);
                }
                return responseSender.ok(myRechargesList);
        }

        
        private String remoteAddr(HttpServletRequest request) {
                String remoteAddr = "";
                String x;
                x = request.getHeader(X_REAL_IP);
                log.info("Value of X_REAL_IP is [{}]", x);
                if (x != null && !x.isEmpty()) {
                        remoteAddr = x;
                        int idx = remoteAddr.lastIndexOf(',');
                        if (idx > -1) {
                                remoteAddr = remoteAddr.substring(idx + 1).trim();
                        }
                } else {
                        remoteAddr = request.getRemoteAddr();
                        log.info("Value of remoteAddr is [{}]", remoteAddr);
                }
                return remoteAddr;
        }

        /*private String validateRecharge(RechargeType rechargeType, String number, long operatorId, String ipAddress){
                TransactionClient tcl;
                try {
                        tcl = new TransactionClient();
                //      String result = tcl.getClient().validateRecharge(rechargeType, number, operatorId, ipAddress);
                        //log.info("validateRecharge Called" + number + " and rechargeType : " +  rechargeType + ", IP:" + ipAddress + ", Operator:" + operatorId + ", Result:" + result);
                        //return result;
                } catch (Exception e) {
                        log.error("Unable to get service provider for Device number " + number + " and rechargeType : " +  rechargeType, e);
                }
                return "Oops! There seems to be a problem. Please try after some time";
        }*/


}