Subversion Repositories SmartDukaan

Rev

Rev 7390 | 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;
13440 amit.gupta 8
import in.shop2020.payments.Attribute;
9
import in.shop2020.payments.Constants;
6111 anupam.sin 10
import in.shop2020.payments.Payment;
11
import in.shop2020.payments.PaymentException;
12
import in.shop2020.thrift.clients.PaymentClient;
13
import in.shop2020.thrift.clients.TransactionClient;
13440 amit.gupta 14
import in.shop2020.util.CRMConstants;
6507 anupam.sin 15
 
16
import java.util.ArrayList;
17
import java.util.Arrays;
6111 anupam.sin 18
import java.util.List;
19
 
20
import org.apache.log4j.Logger;
6507 anupam.sin 21
import org.apache.shiro.SecurityUtils;
6111 anupam.sin 22
import org.apache.thrift.TException;
23
import org.apache.thrift.transport.TTransportException;
24
 
25
public class RechargeOrderInfoController extends BaseController {
26
 
27
    /**
28
     * 
29
     */
30
    private static final long serialVersionUID = 1L;
31
 
32
    private static Logger log = Logger.getLogger(Class.class);
6507 anupam.sin 33
    private Long rechargeOrderId = null;
6111 anupam.sin 34
    private RechargeOrder rechargeOrder = null;
7390 manish.sha 35
    //Start:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
6507 anupam.sin 36
    private UserWallet wallet = null;
6111 anupam.sin 37
    private List<Payment> payments = null;
7390 manish.sha 38
    //private long walletAmount;
39
    //End:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
6111 anupam.sin 40
 
6507 anupam.sin 41
    private static List<RechargeOrderStatus> refundableRechargeStatusList = new ArrayList<RechargeOrderStatus>(Arrays.asList(new RechargeOrderStatus[] 
42
                                                                              {RechargeOrderStatus.RECHARGE_FAILED, 
43
                                                                               RechargeOrderStatus.RECHARGE_FAILED_REFUNDED,
44
                                                                               RechargeOrderStatus.PAYMENT_SUCCESSFUL}));
45
 
6111 anupam.sin 46
    public String index() {
47
        try {
48
            PaymentClient paymentServiceClient = new PaymentClient();
49
            TransactionClient transactionServiceClient = new TransactionClient();
6462 rajveer 50
            Client tclient = transactionServiceClient.getClient();
6507 anupam.sin 51
            rechargeOrder = tclient.getRechargeOrder(rechargeOrderId);
52
            wallet = tclient.getUserWallet(rechargeOrder.getUserId());
7390 manish.sha 53
            //Start:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
54
            //setWalletAmount(wallet.getAmount());
55
            //End:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
7049 anupam.sin 56
            payments = paymentServiceClient.getClient().getPaymentForRechargeTxnId(rechargeOrder.getTransactionId());
6111 anupam.sin 57
 
58
        } catch (TTransportException e) {
59
            log.error("Unable to create thrift Client", e);
60
        } catch (TransactionServiceException e) {
61
            addActionError("Invalid order id or no order selected.");
62
        } catch (TException e) {
63
            log.error("Unable to get thrift Client", e);
64
        } catch (PaymentException e) {
65
            log.error("Unable to get payments for transctionId : " + rechargeOrder.getTransactionId(), e);
66
        }
67
        return INDEX;
68
    }
6507 anupam.sin 69
 
70
    public String refundRechargeOrder() {
71
        try {
72
            TransactionClient transactionServiceClient = new TransactionClient();
73
            if(!transactionServiceClient.getClient().refundRechargeOrder(rechargeOrderId)) {
74
                return "refund-failed";
75
            }
76
        } catch (Exception e) {
77
            log.error("Unable to refund rechargeOrder : " + rechargeOrderId, e);
78
        }
79
        return index();
80
    }
81
 
82
    public boolean showRefundButton() {
83
        RechargeOrderStatus status = rechargeOrder.getStatus();
6509 anupam.sin 84
        if (refundableRechargeStatusList.contains(status) && wallet.getAmount() > 0 && (rechargeOrder.getWalletAmount() != (rechargeOrder.getTotalAmount() - rechargeOrder.getCouponAmount()))) {
6507 anupam.sin 85
            return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
86
        }
87
        return false;
88
    }
6111 anupam.sin 89
 
6507 anupam.sin 90
    public Long getRechargeOrderId() {
6111 anupam.sin 91
        return rechargeOrderId;
92
    }
93
 
6507 anupam.sin 94
    public void setRechargeOrderId(Long rechargeOrderId) {
6111 anupam.sin 95
        this.rechargeOrderId = rechargeOrderId;
96
    }
6153 anupam.sin 97
 
98
    public String getProviderName(Long operatorId) {
99
        return providersMap.get(operatorId);
100
    }
6111 anupam.sin 101
 
102
    public RechargeOrder getRechargeOrder() {
103
        return rechargeOrder;
104
    }
105
 
106
    public void setRechargeOrder(RechargeOrder rechargeOrder) {
107
        this.rechargeOrder = rechargeOrder;
108
    }
109
 
110
    public List<Payment> getPayments() {
111
        return payments;
112
    }
113
 
114
    public void setPayments(List<Payment> payments) {
115
        this.payments = payments;
116
    }
7390 manish.sha 117
    //Start:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
118
	//public void setWalletAmount(long walletAmount) {
119
	//	this.walletAmount = walletAmount;
120
	//}
6111 anupam.sin 121
 
7390 manish.sha 122
	//public long getWalletAmount() {
123
	//	return walletAmount;
124
	//}
125
    //End:- Code Commented by Manish Sharma for Hiding wallet amount at Recharge Order Page on June-05-2013
126
 
6507 anupam.sin 127
    public UserWallet getWallet() {
128
        return wallet;
129
    }
130
 
131
    public void setWallet(UserWallet wallet) {
132
        this.wallet = wallet;
133
    }
7390 manish.sha 134
 
13440 amit.gupta 135
    public String getGatewayName(Payment payment){
136
    	return CRMConstants.PAYMENT_GATEWAYS.get(payment.getGatewayId());
137
    }
138
 
139
    public String getPaymentMethod(List<Attribute> paymentAttributes) {
140
        String paymentMethod = null;
141
        if (paymentAttributes == null || paymentAttributes.isEmpty()) {
142
            return "N/A";
143
        }
144
        for (Attribute a : paymentAttributes) {
145
            if ("payMethod".equals(a.getName())) {
146
                paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
147
                break;
148
            }
149
        }
150
        return paymentMethod != null ? paymentMethod : "N/A";
151
    }
152
 
6111 anupam.sin 153
}