Subversion Repositories SmartDukaan

Rev

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

Rev 6390 Rev 6432
Line 11... Line 11...
11
import in.shop2020.thrift.clients.TransactionClient;
11
import in.shop2020.thrift.clients.TransactionClient;
12
import in.shop2020.thrift.clients.UserClient;
12
import in.shop2020.thrift.clients.UserClient;
13
import in.shop2020.thrift.clients.config.ConfigClient;
13
import in.shop2020.thrift.clients.config.ConfigClient;
14
import in.shop2020.utils.DataLogger;
14
import in.shop2020.utils.DataLogger;
15
 
15
 
16
import java.io.IOException;
-
 
17
import java.io.StringReader;
16
import java.io.StringReader;
18
import java.security.MessageDigest;
17
import java.security.MessageDigest;
19
import java.security.NoSuchAlgorithmException;
18
import java.security.NoSuchAlgorithmException;
20
import java.util.ArrayList;
19
import java.util.ArrayList;
21
import java.util.List;
20
import java.util.List;
22
import java.util.Map;
21
import java.util.Map;
23
import java.util.TreeMap;
22
import java.util.TreeMap;
24
 
23
 
25
import javax.servlet.http.HttpServletRequest;
24
import javax.servlet.http.HttpServletRequest;
26
import javax.swing.text.Document;
-
 
27
import javax.xml.parsers.DocumentBuilder;
25
import javax.xml.parsers.DocumentBuilder;
28
import javax.xml.parsers.DocumentBuilderFactory;
26
import javax.xml.parsers.DocumentBuilderFactory;
29
import javax.xml.parsers.ParserConfigurationException;
-
 
30
 
27
 
31
import org.apache.log4j.Logger;
28
import org.apache.log4j.Logger;
32
import org.apache.thrift.TException;
29
import org.apache.thrift.TException;
33
import org.w3c.dom.*;
30
import org.w3c.dom.*;
34
import org.xml.sax.InputSource;
31
import org.xml.sax.InputSource;
35
import org.xml.sax.SAXException;
-
 
36
 
32
 
37
@SuppressWarnings("serial")
33
@SuppressWarnings("serial")
38
public class InnovitiPayResponseController extends BaseController{
34
public class InnovitiPayResponseController extends BaseController{
39
 
35
 
40
	private static Logger log = Logger.getLogger(Class.class);
36
	private static Logger log = Logger.getLogger(Class.class);
Line 103... Line 99...
103
 
99
 
104
		String authCode = paymentParams.get("authCode");
100
		String authCode = paymentParams.get("authCode");
105
		String txnRefNo = paymentParams.get("txnRefNo");
101
		String txnRefNo = paymentParams.get("txnRefNo");
106
		String txnDate = paymentParams.get("txnDate");
102
		String txnDate = paymentParams.get("txnDate");
107
		String txnTime = paymentParams.get("txnTime");
103
		String txnTime = paymentParams.get("txnTime");
-
 
104
		String hash = paymentParams.get("checkSum");
108
		
105
		
109
		List<Attribute> attributes = new ArrayList<Attribute>();
106
		List<Attribute> attributes = new ArrayList<Attribute>();
110
		attributes.add(new Attribute(TXN_REF_NO, txnRefNo));
107
		attributes.add(new Attribute(TXN_REF_NO, txnRefNo));
111
		attributes.add(new Attribute(AUTH_CODE, authCode));
108
		attributes.add(new Attribute(AUTH_CODE, authCode));
112
		
109
		
Line 119... Line 116...
119
			log.error("Payment exception. It is serious, check merchant payment id + " + merchantPaymentId, e1);
116
			log.error("Payment exception. It is serious, check merchant payment id + " + merchantPaymentId, e1);
120
		} catch (TException e1) {
117
		} catch (TException e1) {
121
			log.error("Thrift exception. Check payment id "+ merchantPaymentId, e1);
118
			log.error("Thrift exception. Check payment id "+ merchantPaymentId, e1);
122
		}
119
		}
123
 
120
 
124
//		if(!validatePaymentParams(amount, payment, hash)){
121
		if(!validatePaymentParams(merchantPaymentId, gatewayPaymentId, gatewayTxnStatus, gatewayTxnStatusDescription, hash)){
125
//			this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
122
			this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
126
//			return "index";
123
			return "index";
127
//		}
124
		}
128
 
125
 
129
		if(gatewayTxnStatus.equalsIgnoreCase("00")){
126
		if(gatewayTxnStatus.equalsIgnoreCase("00")){
130
			//Update payment status as authorized if payment is authorized.
127
			//Update payment status as authorized if payment is authorized.
131
			try {
128
			try {
132
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
129
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
133
						"", gatewayTxnStatus, gatewayTxnStatusDescription, "", "", "", "", PaymentStatus.AUTHORIZED, "", attributes);
130
						"", gatewayTxnStatus, gatewayTxnStatusDescription, "", authCode, txnRefNo, "", PaymentStatus.AUTHORIZED, txnDate + " " + txnTime, attributes);
134
			} catch (PaymentException e) {
131
			} catch (PaymentException e) {
135
				log.error("Unable to mark the payment as authorized", e);
132
				log.error("Unable to mark the payment as authorized", e);
136
			} catch (TException e) {
133
			} catch (TException e) {
137
			    log.error("Unable to mark the payment as authorized", e);
134
			    log.error("Unable to mark the payment as authorized", e);
138
			}
135
			}
Line 143... Line 140...
143
 
140
 
144
			
141
			
145
		}else{
142
		}else{
146
			try {
143
			try {
147
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
144
				paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, gatewayPaymentId,
148
						"", gatewayTxnStatus, "Payment Failed at PG", "", "", "", "", PaymentStatus.FAILED, "", attributes);
145
						"", gatewayTxnStatus, gatewayTxnStatusDescription, "", authCode, txnRefNo, "", PaymentStatus.FAILED, txnDate + " " + txnTime, attributes);
149
			} catch (PaymentException e) {
146
			} catch (PaymentException e) {
150
			    log.error("Unable to mark the payment as failed", e);
147
			    log.error("Unable to mark the payment as failed", e);
151
			} catch (TException e) {
148
			} catch (TException e) {
152
			    log.error("Unable to mark the payment as failed", e);
149
			    log.error("Unable to mark the payment as failed", e);
153
			}
150
			}
Line 161... Line 158...
161
 
158
 
162
		log.info("User will be redirected to: " + this.redirectUrl);
159
		log.info("User will be redirected to: " + this.redirectUrl);
163
		return "index";
160
		return "index";
164
	}
161
	}
165
 
162
 
166
	private boolean validatePaymentParams(double returnedAmount, Payment payment, String hash){
163
	private boolean validatePaymentParams(long merchantPaymentId, String gatewayPaymentId, String gatewayTxnStatus,	String gatewayTxnStatusDescription, String hash) {
167
		if(!(payment != null && Math.abs(payment.getAmount() - returnedAmount) <= 0.50 && hash.equals(getSecureHash()))){
164
		if(!hash.equals(getSecureHash(merchantPaymentId, gatewayPaymentId, gatewayTxnStatus, gatewayTxnStatusDescription))){
168
			// We did not request this payment or the authorised amount is different.
165
			// We did not request this payment or the authorised amount is different.
169
			log.error("Checks and balance failed on returned data");
166
			log.error("Checks and balance failed on returned data");
170
			return false;
167
			return false;
171
		}
168
		}
172
		return true;
169
		return true;
173
	}
170
	}
174
 
171
 
175
 
172
 
176
	public String getSecureHash(){
173
	public String getSecureHash(long merchantPaymentId, String gatewayPaymentId, String gatewayTxnStatus, String gatewayTxnStatusDescription){
177
		try{
174
		try{
178
			String pass = salt + "|" + paymentParams.get("status") + "|||||||||||" + paymentParams.get("email") + "|" +  paymentParams.get("firstname") + "|" + paymentParams.get("productinfo") + "|" + paymentParams.get("amount") + "|" + paymentParams.get("txnid") + "|" + accountKey;
175
			String pass =  merchantPaymentId + "|" + accountKey + "|"  + gatewayPaymentId + "|" + gatewayTxnStatus + "|" + gatewayTxnStatusDescription +  "|" + salt;
179
			System.out.println(pass);
176
			System.out.println(pass);
180
			MessageDigest md = MessageDigest.getInstance("SHA-512");
177
			MessageDigest md = MessageDigest.getInstance("MD5");
181
			md.update(pass.getBytes(), 0, pass.getBytes().length);
178
			md.update(pass.getBytes(), 0, pass.getBytes().length);
182
			byte[] mdbytes = md.digest();
179
			byte[] mdbytes = md.digest();
183
			//	convert the byte to hex format method
180
			//	convert the byte to hex format method
184
			StringBuffer sb = new StringBuffer();
181
			StringBuffer sb = new StringBuffer();
185
			for (int i = 0; i < mdbytes.length; i++) {
182
			for (int i = 0; i < mdbytes.length; i++) {
Line 222... Line 219...
222
			name = element.getElementsByTagName("resmsg");
219
			name = element.getElementsByTagName("resmsg");
223
			line = (Element) name.item(0);
220
			line = (Element) name.item(0);
224
			System.out.println("resmsg: " + getCharacterDataFromElement(line));
221
			System.out.println("resmsg: " + getCharacterDataFromElement(line));
225
			paymentParams.put("resmsg", getCharacterDataFromElement(line));
222
			paymentParams.put("resmsg", getCharacterDataFromElement(line));
226
			
223
			
-
 
224
			name = element.getElementsByTagName("checkSum");
-
 
225
	    	line = (Element) name.item(0);
-
 
226
			System.out.println("checkSum: " + getCharacterDataFromElement(line));
-
 
227
			paymentParams.put("checkSum", getCharacterDataFromElement(line));
227
			
228
			
228
			nodes = element.getElementsByTagName("respDet");
229
			nodes = element.getElementsByTagName("respDet");
229
	    	element = (Element) nodes.item(0);
230
	    	element = (Element) nodes.item(0);
230
	    
231
	    
231
	    	name = element.getElementsByTagName("txnRefNo");
232
	    	name = element.getElementsByTagName("txnRefNo");
Line 256... Line 257...
256
			
257
			
257
			name = element.getElementsByTagName("txnTime");
258
			name = element.getElementsByTagName("txnTime");
258
	    	line = (Element) name.item(0);
259
	    	line = (Element) name.item(0);
259
			System.out.println("txnTime: " + getCharacterDataFromElement(line));
260
			System.out.println("txnTime: " + getCharacterDataFromElement(line));
260
			paymentParams.put("txnTime", getCharacterDataFromElement(line));
261
			paymentParams.put("txnTime", getCharacterDataFromElement(line));
-
 
262
			
261
		}catch (Exception e) {
263
		}catch (Exception e) {
262
			// TODO: handle exception
264
			// TODO: handle exception
263
			//  throws ParserConfigurationException, SAXException, IOException
265
			//  throws ParserConfigurationException, SAXException, IOException
264
		}
266
		}
265
	}
267
	}