Subversion Repositories SmartDukaan

Rev

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

Rev 4617 Rev 4641
Line 11... Line 11...
11
import in.shop2020.payments.PaymentException;
11
import in.shop2020.payments.PaymentException;
12
import in.shop2020.payments.PaymentStatus;
12
import in.shop2020.payments.PaymentStatus;
13
import in.shop2020.thrift.clients.TransactionClient;
13
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.config.ConfigClient;
14
import in.shop2020.thrift.clients.config.ConfigClient;
15
 
15
 
-
 
16
import java.io.File;
-
 
17
import java.io.FileNotFoundException;
-
 
18
import java.io.FileOutputStream;
-
 
19
import java.io.IOException;
-
 
20
import java.io.InputStream;
-
 
21
import java.io.OutputStream;
16
import java.util.ArrayList;
22
import java.util.ArrayList;
17
import java.util.HashMap;
23
import java.util.HashMap;
18
import java.util.List;
24
import java.util.List;
19
import java.util.Map;
25
import java.util.Map;
20
import java.util.Random;
26
import java.util.Random;
Line 29... Line 35...
29
public class HdfcPaymentHandler implements IPaymentHandler {
35
public class HdfcPaymentHandler implements IPaymentHandler {
30
	private static final int CAPTURE_STATUS_FOR_CONNECTION_ISSUE = -1;
36
	private static final int CAPTURE_STATUS_FOR_CONNECTION_ISSUE = -1;
31
 
37
 
32
    private static Logger log = Logger.getLogger(HdfcPaymentHandler.class);
38
    private static Logger log = Logger.getLogger(HdfcPaymentHandler.class);
33
	
39
	
34
	private static String resourceFilePath;
-
 
35
	private static String aliasName;
40
	private static String aliasName;
36
	private static String responseURL;
41
	private static String responseURL;
37
	private static String errorURL;
42
	private static String errorURL;
38
	private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
43
	private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
39
	private static final String replacement = " ";
44
	private static final String replacement = " ";
40
	private static final int MAX_UDF_LENGTH = 30;
45
	private static final int MAX_UDF_LENGTH = 30;
41
	private static final String currencyCode = "356";
46
	private static final String currencyCode = "356";
-
 
47
	private static String resourceDirPath = "/tmp/resource";
-
 
48
	private static final String resourceFileName = "resource.cgn";
42
	
49
	
43
	private enum ActionType{
50
	private enum ActionType{
44
		PURCHASE("1"),
51
		PURCHASE("1"),
45
		AUTH ("4"),
52
		AUTH ("4"),
46
		CAPTURE("5");
53
		CAPTURE("5");
Line 57... Line 64...
57
		// TODO Auto-generated constructor stub
64
		// TODO Auto-generated constructor stub
58
	}
65
	}
59
	
66
	
60
	static{
67
	static{
61
		try {
68
		try {
62
			resourceFilePath = Class.class.getResource(ConfigClient.getClient().get("payment_resource_file_path")).getPath();
69
			InputStream inputStream = Class.class.getResourceAsStream(ConfigClient.getClient().get("payment_resource_file_path") + resourceFileName);
-
 
70
			File resourceDir = new File(resourceDirPath);
-
 
71
			if(!resourceDir.exists()){
-
 
72
				resourceDir.mkdir();
-
 
73
			}
-
 
74
			
-
 
75
			OutputStream outStream = new FileOutputStream(resourceDirPath + File.separator + resourceFileName);
-
 
76
			byte buf[]=new byte[1024];
-
 
77
			int len;
-
 
78
			while((len=inputStream.read(buf))>0)
-
 
79
				outStream.write(buf,0,len);
-
 
80
			outStream.close();
-
 
81
			inputStream.close();
-
 
82
			
63
	        aliasName  = ConfigClient.getClient().get("payment_alias_name");
83
	        aliasName  = ConfigClient.getClient().get("payment_alias_name");
64
			responseURL = ConfigClient.getClient().get("payment_response_url");
84
			responseURL = ConfigClient.getClient().get("payment_response_url");
65
			errorURL = ConfigClient.getClient().get("payment_error_url");
85
			errorURL = ConfigClient.getClient().get("payment_error_url");
66
		} catch (ConfigException e) {
86
		} catch (ConfigException e) {
67
			log.error("Unable to get data from config server.");
87
			log.error("Unable to get data from config server.");
-
 
88
		} catch (FileNotFoundException e) {
-
 
89
			// TODO Auto-generated catch block
-
 
90
			e.printStackTrace();
-
 
91
		} catch (IOException e) {
-
 
92
			// TODO Auto-generated catch block
-
 
93
			e.printStackTrace();
68
		}
94
		}
69
	}
95
	}
70
	
96
	
71
	public static Map<String, String> capturePayment(Payment payment){
97
	public static Map<String, String> capturePayment(Payment payment){
72
		String amount = "" + payment.getAmount();
98
		String amount = "" + payment.getAmount();
Line 78... Line 104...
78
	    resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
104
	    resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
79
        resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
105
        resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
80
        resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
106
        resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
81
	    
107
	    
82
		e24TranPipe pipe = new e24TranPipe();
108
		e24TranPipe pipe = new e24TranPipe();
83
		pipe.setResourcePath(resourceFilePath);
109
		pipe.setResourcePath(resourceDirPath);
84
		pipe.setAlias(aliasName);
110
		pipe.setAlias(aliasName);
85
		pipe.setAction(ActionType.CAPTURE.value());
111
		pipe.setAction(ActionType.CAPTURE.value());
86
		pipe.setAmt(amount);
112
		pipe.setAmt(amount);
87
		pipe.setTrackId("" + payment.getId());
113
		pipe.setTrackId("" + payment.getId());
88
		pipe.setMember("SAHOLIC");
114
		pipe.setMember("SAHOLIC");
Line 278... Line 304...
278
	
304
	
279
	private static void initializePayment(e24PaymentPipe pipe, long merchantPaymentId, double amounta) throws ShoppingCartException, TException{
305
	private static void initializePayment(e24PaymentPipe pipe, long merchantPaymentId, double amounta) throws ShoppingCartException, TException{
280
		String amount = (new Double(amounta)).toString();
306
		String amount = (new Double(amounta)).toString();
281
		
307
		
282
		//Following is the code which initilize e24PaymentPipe with proper value
308
		//Following is the code which initilize e24PaymentPipe with proper value
283
		pipe.setResourcePath(resourceFilePath);	//mandatory 
309
		pipe.setResourcePath(resourceDirPath);	//mandatory 
284
		String as = pipe.getResourcePath();
310
		String as = pipe.getResourcePath();
285
		log.info("Resource= " +as);
311
		log.info("Resource= " +as);
286
		
312
		
287
		pipe.setAlias(aliasName);			//mandatory 
313
		pipe.setAlias(aliasName);			//mandatory 
288
		String ab=pipe.getAlias();
314
		String ab=pipe.getAlias();