Subversion Repositories SmartDukaan

Rev

Rev 6462 | Rev 6508 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6462 Rev 6507
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.RechargeOrder;
3
import in.shop2020.model.v1.order.RechargeOrder;
-
 
4
import in.shop2020.model.v1.order.RechargeOrderStatus;
4
import in.shop2020.model.v1.order.TransactionService.Client;
5
import in.shop2020.model.v1.order.TransactionService.Client;
5
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.order.TransactionServiceException;
-
 
7
import in.shop2020.model.v1.order.UserWallet;
6
import in.shop2020.payments.Payment;
8
import in.shop2020.payments.Payment;
7
import in.shop2020.payments.PaymentException;
9
import in.shop2020.payments.PaymentException;
8
import in.shop2020.thrift.clients.PaymentClient;
10
import in.shop2020.thrift.clients.PaymentClient;
9
import in.shop2020.thrift.clients.TransactionClient;
11
import in.shop2020.thrift.clients.TransactionClient;
-
 
12
 
-
 
13
import java.util.ArrayList;
-
 
14
import java.util.Arrays;
10
import java.util.List;
15
import java.util.List;
11
 
16
 
12
import org.apache.log4j.Logger;
17
import org.apache.log4j.Logger;
-
 
18
import org.apache.shiro.SecurityUtils;
13
import org.apache.thrift.TException;
19
import org.apache.thrift.TException;
14
import org.apache.thrift.transport.TTransportException;
20
import org.apache.thrift.transport.TTransportException;
15
 
21
 
16
public class RechargeOrderInfoController extends BaseController {
22
public class RechargeOrderInfoController extends BaseController {
17
    
23
    
Line 19... Line 25...
19
     * 
25
     * 
20
     */
26
     */
21
    private static final long serialVersionUID = 1L;
27
    private static final long serialVersionUID = 1L;
22
    
28
    
23
    private static Logger log = Logger.getLogger(Class.class);
29
    private static Logger log = Logger.getLogger(Class.class);
24
    private String rechargeOrderId = "";
30
    private Long rechargeOrderId = null;
25
    private RechargeOrder rechargeOrder = null;
31
    private RechargeOrder rechargeOrder = null;
-
 
32
    private UserWallet wallet = null;
26
    private List<Payment> payments = null;
33
    private List<Payment> payments = null;
27
    private long walletAmount;
34
    private long walletAmount;
28
    
35
    
-
 
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
    
29
    public String index() {
42
    public String index() {
30
        try {
43
        try {
31
            PaymentClient paymentServiceClient = new PaymentClient();
44
            PaymentClient paymentServiceClient = new PaymentClient();
32
            TransactionClient transactionServiceClient = new TransactionClient();
45
            TransactionClient transactionServiceClient = new TransactionClient();
33
            Client tclient = transactionServiceClient.getClient();
46
            Client tclient = transactionServiceClient.getClient();
34
            rechargeOrder = tclient.getRechargeOrder(Long.parseLong(rechargeOrderId));
47
            rechargeOrder = tclient.getRechargeOrder(rechargeOrderId);
35
            setWalletAmount(tclient.getUserWallet(rechargeOrder.getUserId()).getAmount());
48
            wallet = tclient.getUserWallet(rechargeOrder.getUserId());
36
            
-
 
37
            payments = paymentServiceClient.getClient()
49
            setWalletAmount(wallet.getAmount());
38
            .getPaymentForTxnId(rechargeOrder.getTransactionId());
50
            payments = paymentServiceClient.getClient().getPaymentForTxnId(rechargeOrder.getTransactionId());
39
 
51
 
40
        } catch (TTransportException e) {
52
        } catch (TTransportException e) {
41
            log.error("Unable to create thrift Client", e);
53
            log.error("Unable to create thrift Client", e);
42
        } catch (TransactionServiceException e) {
54
        } catch (TransactionServiceException e) {
43
            addActionError("Invalid order id or no order selected.");
55
            addActionError("Invalid order id or no order selected.");
Line 46... Line 58...
46
        } catch (PaymentException e) {
58
        } catch (PaymentException e) {
47
            log.error("Unable to get payments for transctionId : " + rechargeOrder.getTransactionId(), e);
59
            log.error("Unable to get payments for transctionId : " + rechargeOrder.getTransactionId(), e);
48
        }
60
        }
49
        return INDEX;
61
        return INDEX;
50
    }
62
    }
-
 
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();
-
 
78
        if (refundableRechargeStatusList.contains(status) && wallet.getAmount() > 0) {
-
 
79
            return (SecurityUtils.getSubject().hasRole("Outbound") && SecurityUtils.getSubject().hasRole("TeamLead"));
-
 
80
        }
-
 
81
        return false;
-
 
82
    }
51
 
83
 
52
    public String getRechargeOrderId() {
84
    public Long getRechargeOrderId() {
53
        return rechargeOrderId;
85
        return rechargeOrderId;
54
    }
86
    }
55
 
87
 
56
    public void setRechargeOrderId(String rechargeOrderId) {
88
    public void setRechargeOrderId(Long rechargeOrderId) {
57
        this.rechargeOrderId = rechargeOrderId;
89
        this.rechargeOrderId = rechargeOrderId;
58
    }
90
    }
59
    
91
    
60
    public String getProviderName(Long operatorId) {
92
    public String getProviderName(Long operatorId) {
61
        return providersMap.get(operatorId);
93
        return providersMap.get(operatorId);
Line 83... Line 115...
83
 
115
 
84
	public long getWalletAmount() {
116
	public long getWalletAmount() {
85
		return walletAmount;
117
		return walletAmount;
86
	}
118
	}
87
 
119
 
-
 
120
    public UserWallet getWallet() {
-
 
121
        return wallet;
-
 
122
    }
-
 
123
 
-
 
124
    public void setWallet(UserWallet wallet) {
-
 
125
        this.wallet = wallet;
-
 
126
    }
-
 
127
 
88
}
128
}