Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
6058 anupam.sin 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.config.ConfigException;
4
import in.shop2020.model.v1.order.RechargeOrder;
5
import in.shop2020.model.v1.order.RechargeOrderStatus;
6
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.payments.Payment;
8
import in.shop2020.payments.PaymentException;
9
import in.shop2020.payments.PaymentStatus;
10
import in.shop2020.serving.utils.ebs.Base64;
11
import in.shop2020.serving.utils.ebs.RC4;
12
import in.shop2020.thrift.clients.PaymentClient;
13
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.thrift.clients.config.ConfigClient;
16
 
17
import java.io.BufferedReader;
18
import java.io.ByteArrayInputStream;
19
import java.io.IOException;
20
import java.io.InputStreamReader;
21
import java.util.Map;
22
import java.util.StringTokenizer;
23
import java.util.TreeMap;
24
 
25
import javax.servlet.http.HttpServletRequest;
26
 
27
import org.apache.log4j.Logger;
28
import org.apache.thrift.TException;
29
 
30
public class WalletOnlyPaymentController {
31
    private static Logger log = Logger.getLogger(Class.class);
32
 
33
    private static final String FLAG_KEY = "IsFlagged";
34
    private static final String TXN_KEY = "TransactionID";
35
    private static final String AUTH_TXN_ID = "AuthTxnId";
36
 
37
    private static String successUrl;
38
    private static String errorUrl;
39
    private static String rechargeResultUri;
40
    private RechargeOrder rechargeOrder = null;
41
 
42
    /**
43
     * The secret key used to decode RC4 encoded data.
44
     */
45
    private static String accountKey;
46
 
47
    private String redirectUrl;
48
 
49
    static{
50
        try {
51
            successUrl = ConfigClient.getClient().get("ebs_success_url");
52
            errorUrl = ConfigClient.getClient().get("ebs_error_url");
6090 anupam.sin 53
            rechargeResultUri = ConfigClient.getClient().get("recharge_success_url");
6058 anupam.sin 54
            accountKey = ConfigClient.getClient().get("ebs_secret_key");
55
        } catch (ConfigException e) {
56
            log.error("Unable to get success and error usr info from config server.");
57
        }
58
    }
59
 
60
    private Map<String, String> paymentParams = new TreeMap<String, String>();
61
 
62
    private String rechargeOrderId;
63
 
64
    private HttpServletRequest request;
65
 
66
    public String index() {
67
        StringBuffer data1 = new StringBuffer(rechargeOrderId);
68
        log.info("Received rechargeORder Id : " + data1.toString());
6070 anupam.sin 69
        //byte[] result = decodeRecvdData(data1);
6058 anupam.sin 70
 
71
        //String recvString = parseRecvdData(result);
72
        //updatePaymentParams(recvString);
73
 
74
        PaymentClient paymentServiceClient = null;
75
        TransactionClient transactionServiceClient = null;
76
        UserClient userServiceClient = null;
77
        try {
78
            paymentServiceClient = new PaymentClient();
79
            transactionServiceClient = new TransactionClient();
80
            userServiceClient = new UserClient();
81
        } catch (Exception e) {
82
            log.error("Unable to initialize one of the clients", e);
83
        }
84
 
85
 
86
        //long merchantPaymentId = Long.parseLong(paymentParams.get("MerchantRefNo"));
87
        //String gatewayPaymentId = paymentParams.get("PaymentID");
88
        //double amount = Double.parseDouble(paymentParams.get("Amount"));
89
//        String isFlagged = paymentParams.get(FLAG_KEY);
90
//        String gatewayTxnStatus = paymentParams.get("ResponseCode");
91
//        String description = paymentParams.get("ResponseMessage");
92
//        String authTxnId = paymentParams.get(TXN_KEY);
93
 
94
        Payment payment = null;
95
        Long txnId = null;
96
        try {
97
            //payment = paymentServiceClient.getClient().getPayment(merchantPaymentId);
98
            //txnId = payment.getMerchantTxnId();
99
            /**
100
             * CREATE PAYMENT
101
             */
102
            rechargeOrder = transactionServiceClient.getClient().getRechargeOrder(Long.parseLong(rechargeOrderId));
6223 anupam.sin 103
            Long merchantPaymentId = paymentServiceClient.getClient().createPayment(rechargeOrder.getUserId(), rechargeOrder.getTotalAmount(), 8, rechargeOrder.getTransactionId(), true);
6058 anupam.sin 104
            //Update payment status as authorized
105
            paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, "",
6137 anupam.sin 106
                    "", "0", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
6058 anupam.sin 107
            transactionServiceClient.getClient().updateRechargeOrderStatus(rechargeOrder.getId(),  RechargeOrderStatus.PAYMENT_SUCCESSFUL);
108
            this.redirectUrl = rechargeResultUri + "?paymentId=" + merchantPaymentId;
109
        } catch (PaymentException e) {
110
            log.error("Unable to mark the payment as authorized", e);
111
        } catch (TException e) {
112
            log.error("Unable to mark the payment as authorized", e);
113
        } catch (TransactionServiceException e) {
114
            // TODO Auto-generated catch block
115
            log.error("Unable to recharge");
116
        }
117
 
118
            //DataLogger.logData(EventType.PAYMENT_FAILURE, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), Long.toString(merchantPaymentId), gatewayPaymentId,
119
            //        gatewayTxnStatus, description);
120
        log.info("User will be redirected to: " + this.redirectUrl);
121
        return "index";
122
    }
123
 
124
    public String getRedirectUrl(){
125
        return this.redirectUrl;
126
    }
127
 
128
    public void setServletRequest(HttpServletRequest request) {
129
        this.request = request;
130
    }
131
 
132
    public Map<String, String> getPaymentParams() {
133
        return paymentParams;
134
    }
135
 
136
 
137
    public static String getRechargeResultUri() {
138
        return rechargeResultUri;
139
    }
140
 
141
    public String getRechargeOrderId() {
142
        return rechargeOrderId;
143
    }
144
 
145
    public void setRechargeOrderId(String rechargeOrderId) {
146
        this.rechargeOrderId = rechargeOrderId;
147
    }
148
 
149
}