Subversion Repositories SmartDukaan

Rev

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

Rev 1959 Rev 2118
Line 39... Line 39...
39
	public static final String DATE_TIME = "dateTime";
39
	public static final String DATE_TIME = "dateTime";
40
	public static final String MODE = "mode";
40
	public static final String MODE = "mode";
41
	public static final String REF_NO = "referenceNo";
41
	public static final String REF_NO = "referenceNo";
42
	public static final String TXN_TYPE = "transactionType";
42
	public static final String TXN_TYPE = "transactionType";
43
	
43
	
-
 
44
	private enum Errors{
-
 
45
		CONN_FAILURE("-1", "Unable to initialize connection to EBS API server"),
-
 
46
		CAPTURE_FAILURE("-2", "Error while capturing EBS payment");
-
 
47
		
-
 
48
		private String code;
-
 
49
		private String message;
-
 
50
		
-
 
51
		Errors(String code, String message){
-
 
52
			this.code = code;
-
 
53
			this.message = message;
-
 
54
		}
-
 
55
	}
44
	
56
	
45
    private static String accountId;
57
    private static String accountId;
46
    private static String secretKey;
58
    private static String secretKey;
47
    
59
    
48
	static{
60
	static{
Line 52... Line 64...
52
		} catch (ConfigException e) {
64
		} catch (ConfigException e) {
53
			log.error("Unable to get EBS payment configuration.");
65
			log.error("Unable to get EBS payment configuration.");
54
		}
66
		}
55
	}
67
	}
56
	
68
	
57
	private int gatewayId=2;
69
	private static int gatewayId=2;
58
	private long paymentId;
70
	private long paymentId;
59
	
71
	
60
	@Override
72
	@Override
61
	public long createPayment(long currentCartId, long userId, long txnId){
73
	public long createPayment(long currentCartId, long userId, long txnId){
62
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId);
74
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId);
Line 84... Line 96...
84
	 *         information in case of error and txn information in case of
96
	 *         information in case of error and txn information in case of
85
	 *         success. In case there is an error in processing, the returned
97
	 *         success. In case there is an error in processing, the returned
86
	 *         result map will be empty.
98
	 *         result map will be empty.
87
	 */
99
	 */
88
	public static Map<String, String> capturePayment(double amount, String paymentId){
100
	public static Map<String, String> capturePayment(double amount, String paymentId){
89
		System.out.println("Capturing amount: Rs " + amount + " for payment Id: " + paymentId);
101
		log.info("Capturing amount: Rs " + amount + " for payment Id: " + paymentId);
90
		URL url = null;
102
		URL url = null;
91
	    URLConnection urlConn = null;
103
	    URLConnection urlConn = null;
92
	    DataOutputStream printout;
104
	    DataOutputStream printout;
93
	    BufferedReader reader;
105
	    BufferedReader reader;
94
	    Map<String, String> resultMap = new HashMap<String, String>();
106
	    Map<String, String> resultMap = new HashMap<String, String>();
95
 
107
 
-
 
108
	    //Prepare resultMap to elicit failure behaviour in case anything goes wrong.
-
 
109
	    resultMap.put(STATUS, "");
-
 
110
	    
96
		/*
111
		/*
97
		 * HDFC Insanity
112
		 * HDFC Insanity
98
		 * 
113
		 * 
99
		 * If we don't set this property, all payments through HDFC will fail if
114
		 * If we don't set this property, all payments through HDFC will fail if
100
		 * the first payment is made through EBS.
115
		 * the first payment is made through EBS.
Line 116... Line 131...
116
			url = new URL("https://secure.ebs.in/api/1_0");
131
			url = new URL("https://secure.ebs.in/api/1_0");
117
		    // URL connection channel.
132
		    // URL connection channel.
118
		    urlConn = url.openConnection();
133
		    urlConn = url.openConnection();
119
		    //urlConn.setRequestMethod("POST");
134
		    //urlConn.setRequestMethod("POST");
120
	    } catch (MalformedURLException e1) {
135
	    } catch (MalformedURLException e1) {
121
			log.error("Unable to initialize connection to EBS API server", e1);
136
			log.error(Errors.CONN_FAILURE.message, e1);
-
 
137
			resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
-
 
138
			resultMap.put(ERROR, Errors.CONN_FAILURE.message);
-
 
139
			return resultMap;
122
		} catch (IOException e) {
140
		} catch (IOException e) {
123
			log.error("Unable to initialize connection to EBS API server", e);
141
			log.error("Unable to initialize connection to EBS API server", e);
-
 
142
			resultMap.put(ERR_CODE, Errors.CONN_FAILURE.code);
-
 
143
			resultMap.put(ERROR, Errors.CONN_FAILURE.message);
124
			e.printStackTrace();
144
			return resultMap;
125
		}
145
		}
126
 
146
 
127
	    // Let the run-time system (RTS) know that we want input.
147
	    // Let the run-time system (RTS) know that we want input.
128
	    urlConn.setDoInput (true);
148
	    urlConn.setDoInput (true);
129
	    // Let the RTS know that we want to do output.
149
	    // Let the RTS know that we want to do output.
Line 149... Line 169...
149
		    // Get response data.
169
		    // Get response data.
150
		    reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
170
		    reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
151
		    resultMap = parseCaptureOutput(reader);
171
		    resultMap = parseCaptureOutput(reader);
152
		    reader.close ();
172
		    reader.close ();
153
	    } catch (IOException e) {
173
	    } catch (IOException e) {
154
			log.error("Error while capturing EBS payment", e);
174
			log.error(Errors.CAPTURE_FAILURE.message, e);
-
 
175
			resultMap.clear();
-
 
176
			resultMap.put(STATUS, "");
-
 
177
			resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
-
 
178
			resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
155
		}
179
		}
156
	    return resultMap;
180
	    return resultMap;
157
	}
181
	}
158
 
182
 
159
	/**
183
	/**