Subversion Repositories SmartDukaan

Rev

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

Rev 2391 Rev 3010
Line 1... Line 1...
1
package in.shop2020.payment.service.handler;
1
package in.shop2020.payment.service.handler;
2
 
2
 
3
import in.shop2020.config.ConfigException;
3
import in.shop2020.config.ConfigException;
-
 
4
import in.shop2020.payment.domain.Payment;
4
import in.shop2020.thrift.clients.config.ConfigClient;
5
import in.shop2020.thrift.clients.config.ConfigClient;
5
 
6
 
6
import java.io.BufferedReader;
7
import java.io.BufferedReader;
7
import java.io.DataOutputStream;
8
import java.io.DataOutputStream;
8
import java.io.IOException;
9
import java.io.IOException;
Line 24... Line 25...
24
import org.apache.log4j.Logger;
25
import org.apache.log4j.Logger;
25
import org.w3c.dom.Element;
26
import org.w3c.dom.Element;
26
import org.w3c.dom.NodeList;
27
import org.w3c.dom.NodeList;
27
import org.xml.sax.InputSource;
28
import org.xml.sax.InputSource;
28
 
29
 
29
public class EbsPaymentHandler {
30
public class EbsPaymentHandler implements IPaymentHandler {
30
	
31
	
31
	private static Logger log = Logger.getLogger(Class.class);
32
	private static Logger log = Logger.getLogger(Class.class);
32
	
33
	
33
	public static final String STATUS = "status";
-
 
34
	public static final String ERR_CODE = "errorCode";
-
 
35
	public static final String ERROR = "error";
-
 
36
	public static final String TXN_ID = "transactionId";
34
	public static final String TXN_ID = "transactionId";
37
	public static final String PAYMENT_ID = "paymentId";
35
	public static final String PAYMENT_ID = "paymentId";
38
	public static final String AMOUNT = "amount";
36
	public static final String AMOUNT = "amount";
39
	public static final String DATE_TIME = "dateTime";
37
	public static final String DATE_TIME = "dateTime";
40
	public static final String MODE = "mode";
38
	public static final String MODE = "mode";
41
	public static final String REF_NO = "referenceNo";
39
	public static final String REF_NO = "referenceNo";
42
	public static final String TXN_TYPE = "transactionType";
40
	public static final String TXN_TYPE = "transactionType";
43
	
41
	
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
	}
-
 
56
	
-
 
57
    private static String accountId;
42
    private static String accountId;
58
    private static String secretKey;
43
    private static String secretKey;
59
    
44
    
60
	static{
45
	static{
61
		try {
46
		try {
Line 79... Line 64...
79
	 * @return A Map. The Map will definitely have status and will have error
64
	 * @return A Map. The Map will definitely have status and will have error
80
	 *         information in case of error and txn information in case of
65
	 *         information in case of error and txn information in case of
81
	 *         success. In case there is an error in processing, the returned
66
	 *         success. In case there is an error in processing, the returned
82
	 *         result map will be empty.
67
	 *         result map will be empty.
83
	 */
68
	 */
84
	public static Map<String, String> capturePayment(double amount, String paymentId){
69
	public static Map<String, String> capturePayment(Payment payment){
-
 
70
	    double amount = payment.getAmount();
-
 
71
	    String paymentId = payment.getGatewayPaymentId();
85
		System.out.println("Capturing amount: Rs " + amount + " for payment Id: " + paymentId);
72
		System.out.println("Capturing amount: Rs " + amount + " for payment Id: " + paymentId);
86
		URL url = null;
73
		URL url = null;
87
	    URLConnection urlConn = null;
74
	    URLConnection urlConn = null;
88
	    DataOutputStream printout;
75
	    DataOutputStream printout;
89
	    BufferedReader reader;
76
	    BufferedReader reader;
Line 203... Line 190...
203
		if("".equals(status) || !"Processing".equals(status)){
190
		if("".equals(status) || !"Processing".equals(status)){
204
			//We've received an error. Retrieve the error values
191
			//We've received an error. Retrieve the error values
205
			resultMap.put(ERR_CODE, elem.getAttribute(ERR_CODE));
192
			resultMap.put(ERR_CODE, elem.getAttribute(ERR_CODE));
206
			resultMap.put(ERROR, elem.getAttribute(ERROR));
193
			resultMap.put(ERROR, elem.getAttribute(ERROR));
207
		}else{
194
		}else{
208
			resultMap.put(TXN_ID, elem.getAttribute(TXN_ID));
195
			resultMap.put(CAPTURE_TXN_ID, elem.getAttribute(TXN_ID));
209
			resultMap.put(PAYMENT_ID, elem.getAttribute(PAYMENT_ID));
196
			resultMap.put(PAYMENT_ID, elem.getAttribute(PAYMENT_ID));
210
			resultMap.put(AMOUNT, elem.getAttribute(AMOUNT));
197
			resultMap.put(AMOUNT, elem.getAttribute(AMOUNT));
211
			resultMap.put(DATE_TIME, elem.getAttribute(DATE_TIME));
198
			resultMap.put(CAPTURE_TIME, elem.getAttribute(DATE_TIME));
212
			resultMap.put(MODE, elem.getAttribute(MODE));
199
			resultMap.put(MODE, elem.getAttribute(MODE));
213
			resultMap.put(REF_NO, elem.getAttribute(REF_NO));
200
			resultMap.put(REF_NO, elem.getAttribute(REF_NO));
214
			resultMap.put(TXN_TYPE, elem.getAttribute(TXN_TYPE));
201
			resultMap.put(TXN_TYPE, elem.getAttribute(TXN_TYPE));
215
		}
202
		}
216
 
203
 
Line 221... Line 208...
221
		
208
		
222
		return resultMap;
209
		return resultMap;
223
	}
210
	}
224
	
211
	
225
	public static void main(String[] args){
212
	public static void main(String[] args){
-
 
213
	    //TODO: The following call has been deprecated now. Need to create a payment object to make this call now.
226
		capturePayment(30450.00, "2412653");
214
//		capturePayment(30450.00, "2412653");
227
		
215
		
228
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
216
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
229
 
217
 
230
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
218
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
231
//		<output  errorCode="12"  error="This payment is failed"  />
219
//		<output  errorCode="12"  error="This payment is failed"  />