Subversion Repositories SmartDukaan

Rev

Rev 26228 | 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.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

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

import org.apache.thrift.TException;
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.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.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.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.service.wallet.WalletService;
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 in.shop2020.model.v1.order.DenominationType;
import in.shop2020.model.v1.order.DeviceNumberInfo;
import in.shop2020.model.v1.order.RechargeDenomination;
import in.shop2020.model.v1.order.RechargeOrder;
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> UNBLOCKED_RECHARGE_EMAILS = Arrays.asList("pgautam84@gmail.com");
        private static final String X_REAL_IP = "X-Real-IP";

        @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
        WalletService walletService;

        @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 = "")
        @Transactional(readOnly = true)
        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;
                if (rechargeAmount <= 0) {
                        return responseSender.badRequest(null);
                }

                userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);

                long walletAmount = walletService.getWalletAmount(userAccount.getAccountKey());

                ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
                // crr.setWalletAmount(wallet.getAmount());
                crr.setWalletAmountLeft(walletAmount - 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<?> createRechargeDown(HttpServletRequest request,
                        @RequestBody CreateRechargeRequest createRechargeRequest) throws ProfitMandiBusinessException {

                int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
                int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
                User saholicUser = null;
                try {
                        saholicUser = userRepository.selectById(retailerId);
                        if (UNBLOCKED_RECHARGE_EMAILS.contains(saholicUser.getEmailId())) {
                                return createRecharge(request, createRechargeRequest);
                        }
                } catch (ProfitMandiBusinessException e) {
                        log.error("Unable to get user", e);
                }

                CreateRechargeResponse crr = new CreateRechargeResponse();
                String ipAddress = remoteAddr(request);
                log.info("IP Address is {}", ipAddress);

                crr.setResult(true);
                crr.setRequestId("RECHARGE00050");
                return responseSender.ok(crr);

        }

        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;
                long walletAmount = walletService.getWalletAmount(retailerId);

                if (createRechargeRequest.getRechargeAmount() <= 0) {
                        crr.setReason("Illegal recharge amount");
                        crr.setResult(false);
                        return responseSender.badRequest(crr);
                }

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

                User saholicUser = null;
                try {
                        saholicUser = userRepository.selectById(retailerId);
                } 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 (!UNBLOCKED_RECHARGE_EMAILS.contains(saholicUser.getEmailId())) {
                        throw new ProfitMandiBusinessException("Recharge Provider", createRechargeRequest.getOperatorId(),
                                        "We are experiencing some problem right now.");
                }
                RechargeResponse rechargeResponse = rechargeService.doRecharge(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") })
        @Transactional(readOnly = true)
        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") })
        @Transactional(readOnly = true)
        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(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") })
        @Transactional(readOnly = true)
        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"; }
         */

}