Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
6111 anupam.sin 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.model.v1.order.RechargeOrder;
6507 anupam.sin 4
import in.shop2020.model.v1.order.RechargeOrderStatus;
6462 rajveer 5
import in.shop2020.model.v1.order.TransactionService.Client;
6111 anupam.sin 6
import in.shop2020.model.v1.order.TransactionServiceException;
6507 anupam.sin 7
import in.shop2020.model.v1.order.UserWallet;
6111 anupam.sin 8
import in.shop2020.payments.Payment;
9
import in.shop2020.payments.PaymentException;
10
import in.shop2020.thrift.clients.PaymentClient;
11
import in.shop2020.thrift.clients.TransactionClient;
6507 anupam.sin 12
 
13
import java.util.ArrayList;
14
import java.util.Arrays;
6111 anupam.sin 15
import java.util.List;
16
 
17
import org.apache.log4j.Logger;
6507 anupam.sin 18
import org.apache.shiro.SecurityUtils;
6111 anupam.sin 19
import org.apache.thrift.TException;
20
import org.apache.thrift.transport.TTransportException;
21
 
22
public class RechargeOrderInfoController extends BaseController {
23
 
24
    /**
25
     * 
26
     */
27
    private static final long serialVersionUID = 1L;
28
 
29
    private static Logger log = Logger.getLogger(Class.class);
6507 anupam.sin 30
    private Long rechargeOrderId = null;
6111 anupam.sin 31
    private RechargeOrder rechargeOrder = null;
6507 anupam.sin 32
    private UserWallet wallet = null;
6111 anupam.sin 33
    private List<Payment> payments = null;
6462 rajveer 34
    private long walletAmount;
6111 anupam.sin 35
 
6507 anupam.sin 36
    private static List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[] 
37
                                                                              {RechargeOrderStatus.RECHARGE_FAILED, 
38
                                                                               RechargeOrderStatus.RECHARGE_FAILED_REFUNDED,
39
                                                                               RechargeOrderStatus.RECHARGE_SUCCESSFUL,
40
                                                                               RechargeOrderStatus.PAYMENT_SUCCESSFUL}));
41
 
6111 anupam.sin 42
    public String index() {
43
        try {
44
            PaymentClient paymentServiceClient = new PaymentClient();
45
            TransactionClient transactionServiceClient = new TransactionClient();
6462 rajveer 46
            Client tclient = transactionServiceClient.getClient();
6507 anupam.sin 47
            rechargeOrder = tclient.getRechargeOrder(rechargeOrderId);
48
            wallet = tclient.getUserWallet(rechargeOrder.getUserId());
49
            setWalletAmount(wallet.getAmount());
50
            payments = paymentServiceClient.getClient().getPaymentForTxnId(rechargeOrder.getTransactionId());
6111 anupam.sin 51
 
52
        } catch (TTransportException e) {
53
            log.error("Unable to create thrift Client", e);
54
        } catch (TransactionServiceException e) {
55
            addActionError("Invalid order id or no order selected.");
56
        } catch (TException e) {
57
            log.error("Unable to get thrift Client", e);
58
        } catch (PaymentException e) {
59
            log.error("Unable to get payments for transctionId : " + rechargeOrder.getTransactionId(), e);
60
        }
61
        return INDEX;
62
    }
6507 anupam.sin 63
 
64
    public String refundRechargeOrder() {
65
        try {
66
            TransactionClient transactionServiceClient = new TransactionClient();
67
            if(!transactionServiceClient.getClient().refundRechargeOrder(rechargeOrderId)) {
68
                return "refund-failed";
69
            }
70
        } catch (Exception e) {
71
            log.error("Unable to refund rechargeOrder : " + rechargeOrderId, e);
72
        }
73
        return index();
74
    }
75
 
76
    public boolean showRefundButton() {
77
        RechargeOrderStatus status = rechargeOrder.getStatus();
6509 anupam.sin 78
        if (refundableRechargeStatusList.contains(status) && wallet.getAmount() > 0 && (rechargeOrder.getWalletAmount() != (rechargeOrder.getTotalAmount() - rechargeOrder.getCouponAmount()))) {
6507 anupam.sin 79
            return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
80
        }
81
        return false;
82
    }
6111 anupam.sin 83
 
6507 anupam.sin 84
    public Long getRechargeOrderId() {
6111 anupam.sin 85
        return rechargeOrderId;
86
    }
87
 
6507 anupam.sin 88
    public void setRechargeOrderId(Long rechargeOrderId) {
6111 anupam.sin 89
        this.rechargeOrderId = rechargeOrderId;
90
    }
6153 anupam.sin 91
 
92
    public String getProviderName(Long operatorId) {
93
        return providersMap.get(operatorId);
94
    }
6111 anupam.sin 95
 
96
    public RechargeOrder getRechargeOrder() {
97
        return rechargeOrder;
98
    }
99
 
100
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
101
        this.rechargeOrder = rechargeOrder;
102
    }
103
 
104
    public List<Payment> getPayments() {
105
        return payments;
106
    }
107
 
108
    public void setPayments(List<Payment> payments) {
109
        this.payments = payments;
110
    }
111
 
6462 rajveer 112
	public void setWalletAmount(long walletAmount) {
113
		this.walletAmount = walletAmount;
114
	}
115
 
116
	public long getWalletAmount() {
117
		return walletAmount;
118
	}
119
 
6507 anupam.sin 120
    public UserWallet getWallet() {
121
        return wallet;
122
    }
123
 
124
    public void setWallet(UserWallet wallet) {
125
        this.wallet = wallet;
126
    }
127
 
6111 anupam.sin 128
}