Subversion Repositories SmartDukaan

Rev

Rev 6509 | Rev 7049 | 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.PAYMENT_SUCCESSFUL}));
40
 
6111 anupam.sin 41
    public String index() {
42
        try {
43
            PaymentClient paymentServiceClient = new PaymentClient();
44
            TransactionClient transactionServiceClient = new TransactionClient();
6462 rajveer 45
            Client tclient = transactionServiceClient.getClient();
6507 anupam.sin 46
            rechargeOrder = tclient.getRechargeOrder(rechargeOrderId);
47
            wallet = tclient.getUserWallet(rechargeOrder.getUserId());
48
            setWalletAmount(wallet.getAmount());
49
            payments = paymentServiceClient.getClient().getPaymentForTxnId(rechargeOrder.getTransactionId());
6111 anupam.sin 50
 
51
        } catch (TTransportException e) {
52
            log.error("Unable to create thrift Client", e);
53
        } catch (TransactionServiceException e) {
54
            addActionError("Invalid order id or no order selected.");
55
        } catch (TException e) {
56
            log.error("Unable to get thrift Client", e);
57
        } catch (PaymentException e) {
58
            log.error("Unable to get payments for transctionId : " + rechargeOrder.getTransactionId(), e);
59
        }
60
        return INDEX;
61
    }
6507 anupam.sin 62
 
63
    public String refundRechargeOrder() {
64
        try {
65
            TransactionClient transactionServiceClient = new TransactionClient();
66
            if(!transactionServiceClient.getClient().refundRechargeOrder(rechargeOrderId)) {
67
                return "refund-failed";
68
            }
69
        } catch (Exception e) {
70
            log.error("Unable to refund rechargeOrder : " + rechargeOrderId, e);
71
        }
72
        return index();
73
    }
74
 
75
    public boolean showRefundButton() {
76
        RechargeOrderStatus status = rechargeOrder.getStatus();
6509 anupam.sin 77
        if (refundableRechargeStatusList.contains(status) && wallet.getAmount() > 0 && (rechargeOrder.getWalletAmount() != (rechargeOrder.getTotalAmount() - rechargeOrder.getCouponAmount()))) {
6507 anupam.sin 78
            return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
79
        }
80
        return false;
81
    }
6111 anupam.sin 82
 
6507 anupam.sin 83
    public Long getRechargeOrderId() {
6111 anupam.sin 84
        return rechargeOrderId;
85
    }
86
 
6507 anupam.sin 87
    public void setRechargeOrderId(Long rechargeOrderId) {
6111 anupam.sin 88
        this.rechargeOrderId = rechargeOrderId;
89
    }
6153 anupam.sin 90
 
91
    public String getProviderName(Long operatorId) {
92
        return providersMap.get(operatorId);
93
    }
6111 anupam.sin 94
 
95
    public RechargeOrder getRechargeOrder() {
96
        return rechargeOrder;
97
    }
98
 
99
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
100
        this.rechargeOrder = rechargeOrder;
101
    }
102
 
103
    public List<Payment> getPayments() {
104
        return payments;
105
    }
106
 
107
    public void setPayments(List<Payment> payments) {
108
        this.payments = payments;
109
    }
110
 
6462 rajveer 111
	public void setWalletAmount(long walletAmount) {
112
		this.walletAmount = walletAmount;
113
	}
114
 
115
	public long getWalletAmount() {
116
		return walletAmount;
117
	}
118
 
6507 anupam.sin 119
    public UserWallet getWallet() {
120
        return wallet;
121
    }
122
 
123
    public void setWallet(UserWallet wallet) {
124
        this.wallet = wallet;
125
    }
126
 
6111 anupam.sin 127
}