| Line 35... |
Line 35... |
| 35 |
public class HdfcEmiPaymentHandler implements IPaymentHandler {
|
35 |
public class HdfcEmiPaymentHandler implements IPaymentHandler {
|
| 36 |
private static final int CAPTURE_STATUS_FOR_CONNECTION_ISSUE = -1;
|
36 |
private static final int CAPTURE_STATUS_FOR_CONNECTION_ISSUE = -1;
|
| 37 |
|
37 |
|
| 38 |
private static Logger log = Logger.getLogger(HdfcEmiPaymentHandler.class);
|
38 |
private static Logger log = Logger.getLogger(HdfcEmiPaymentHandler.class);
|
| 39 |
|
39 |
|
| 40 |
private static String aliasName;
|
- |
|
| 41 |
private static String responseURL;
|
40 |
private static String responseURL;
|
| 42 |
private static String errorURL;
|
41 |
private static String errorURL;
|
| 43 |
private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
|
42 |
private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
|
| 44 |
private static final String replacement = " ";
|
43 |
private static final String replacement = " ";
|
| 45 |
private static final int MAX_UDF_LENGTH = 30;
|
44 |
private static final int MAX_UDF_LENGTH = 30;
|
| 46 |
private static final String currencyCode = "356";
|
45 |
private static final String currencyCode = "356";
|
| 47 |
private static String resourceDirPath = "/tmp/emi-resource/";
|
- |
|
| 48 |
private static final String resourceFileName = "resource.cgn";
|
46 |
private static final String resourceFileName = "resource.cgn";
|
| 49 |
|
47 |
|
| 50 |
private enum ActionType{
|
48 |
private enum ActionType{
|
| 51 |
PURCHASE("1"),
|
49 |
PURCHASE("1"),
|
| 52 |
AUTH ("4"),
|
50 |
AUTH ("4"),
|
| 53 |
CAPTURE("5");
|
51 |
CAPTURE("5");
|
| 54 |
private String value;
|
52 |
private String value;
|
| Line 63... |
Line 61... |
| 63 |
public HdfcEmiPaymentHandler() {
|
61 |
public HdfcEmiPaymentHandler() {
|
| 64 |
// TODO Auto-generated constructor stub
|
62 |
// TODO Auto-generated constructor stub
|
| 65 |
}
|
63 |
}
|
| 66 |
|
64 |
|
| 67 |
static{
|
65 |
static{
|
| - |
|
66 |
int [] gatewayIds = {5,10,11,12};
|
| - |
|
67 |
for(int gatewayId: gatewayIds){
|
| - |
|
68 |
String resourceDirPath = "/tmp/emi-resource/" + gatewayId + "/";
|
| 68 |
try {
|
69 |
try {
|
| 69 |
InputStream inputStream = Class.class.getResourceAsStream(ConfigClient.getClient().get("emi_payment_resource_file_path") + resourceFileName);
|
70 |
InputStream inputStream = Class.class.getResourceAsStream(ConfigClient.getClient().get("emi_payment_resource_file_path") + resourceFileName);
|
| 70 |
File resourceDir = new File(resourceDirPath);
|
71 |
File resourceDir = new File(resourceDirPath);
|
| 71 |
if(!resourceDir.exists()){
|
72 |
if(!resourceDir.exists()){
|
| 72 |
resourceDir.mkdir();
|
73 |
resourceDir.mkdir();
|
| - |
|
74 |
}
|
| - |
|
75 |
|
| - |
|
76 |
OutputStream outStream = new FileOutputStream(resourceDirPath + resourceFileName);
|
| - |
|
77 |
byte buf[]=new byte[1024];
|
| - |
|
78 |
int len;
|
| - |
|
79 |
while((len=inputStream.read(buf))>0)
|
| - |
|
80 |
outStream.write(buf,0,len);
|
| - |
|
81 |
outStream.close();
|
| - |
|
82 |
inputStream.close();
|
| - |
|
83 |
|
| - |
|
84 |
responseURL = ConfigClient.getClient().get("emi_payment_response_url");
|
| - |
|
85 |
errorURL = ConfigClient.getClient().get("emi_payment_error_url");
|
| - |
|
86 |
} catch (ConfigException e) {
|
| - |
|
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();
|
| 73 |
}
|
94 |
}
|
| 74 |
|
- |
|
| 75 |
OutputStream outStream = new FileOutputStream(resourceDirPath + 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 |
|
- |
|
| 83 |
aliasName = ConfigClient.getClient().get("emi_payment_alias_name");
|
- |
|
| 84 |
responseURL = ConfigClient.getClient().get("emi_payment_response_url");
|
- |
|
| 85 |
errorURL = ConfigClient.getClient().get("emi_payment_error_url");
|
- |
|
| 86 |
} catch (ConfigException e) {
|
- |
|
| 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();
|
- |
|
| 94 |
}
|
95 |
}
|
| 95 |
}
|
96 |
}
|
| 96 |
|
97 |
|
| 97 |
public static Map<String, String> capturePayment(Payment payment){
|
98 |
public static Map<String, String> capturePayment(Payment payment){
|
| 98 |
String amount = "" + payment.getAmount();
|
99 |
String amount = "" + payment.getAmount();
|
| 99 |
String gatewayPaymentId = payment.getGatewayPaymentId();
|
100 |
String gatewayPaymentId = payment.getGatewayPaymentId();
|
| 100 |
log.info("Capturing amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
|
101 |
log.info("Capturing amount: Rs " + amount + " for payment Id: " + gatewayPaymentId);
|
| 101 |
|
102 |
|
| - |
|
103 |
String aliasName = null;
|
| - |
|
104 |
try {
|
| - |
|
105 |
aliasName = ConfigClient.getClient().get("emi_payment_alias_name" + payment.getGatewayId());
|
| - |
|
106 |
} catch (ConfigException e1) {
|
| - |
|
107 |
e1.printStackTrace();
|
| - |
|
108 |
}
|
| - |
|
109 |
String resourceDirPath = "/tmp/emi-resource/" + payment.getGatewayId() + "/";
|
| - |
|
110 |
|
| 102 |
//Prepare resultMap to elicit failure behaviour in case anything goes wrong.
|
111 |
//Prepare resultMap to elicit failure behaviour in case anything goes wrong.
|
| 103 |
Map<String, String> resultMap = new HashMap<String, String>();
|
112 |
Map<String, String> resultMap = new HashMap<String, String>();
|
| 104 |
resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
|
113 |
resultMap.put(STATUS, Errors.CAPTURE_FAILURE.code);
|
| 105 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
114 |
resultMap.put(ERR_CODE, Errors.CAPTURE_FAILURE.code);
|
| 106 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
115 |
resultMap.put(ERROR, Errors.CAPTURE_FAILURE.message);
|
| Line 163... |
Line 172... |
| 163 |
long merchantPaymentId = payment.getId();
|
172 |
long merchantPaymentId = payment.getId();
|
| 164 |
double amount = payment.getAmount();
|
173 |
double amount = payment.getAmount();
|
| 165 |
e24PaymentPipe pipe = new e24PaymentPipe();
|
174 |
e24PaymentPipe pipe = new e24PaymentPipe();
|
| 166 |
|
175 |
|
| 167 |
try {
|
176 |
try {
|
| 168 |
initializePayment(pipe, merchantPaymentId, amount);
|
177 |
initializePayment(pipe, merchantPaymentId, amount, payment.getGatewayId());
|
| 169 |
} catch (ShoppingCartException e1) {
|
178 |
} catch (ShoppingCartException e1) {
|
| 170 |
log.error("Error while creating hdfc payment.", e1);
|
179 |
log.error("Error while creating hdfc payment.", e1);
|
| 171 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
180 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
| 172 |
} catch (TException e1) {
|
181 |
} catch (TException e1) {
|
| 173 |
log.error("Error while creating hdfc payment.", e1);
|
182 |
log.error("Error while creating hdfc payment.", e1);
|
| Line 300... |
Line 309... |
| 300 |
attributes.add(attribute5);
|
309 |
attributes.add(attribute5);
|
| 301 |
|
310 |
|
| 302 |
return attributes;
|
311 |
return attributes;
|
| 303 |
}
|
312 |
}
|
| 304 |
|
313 |
|
| 305 |
private static void initializePayment(e24PaymentPipe pipe, long merchantPaymentId, double amounta) throws ShoppingCartException, TException{
|
314 |
private static void initializePayment(e24PaymentPipe pipe, long merchantPaymentId, double amounta, long gatewayId) throws ShoppingCartException, TException{
|
| - |
|
315 |
String aliasName = null;
|
| - |
|
316 |
try {
|
| - |
|
317 |
aliasName = ConfigClient.getClient().get("emi_payment_alias_name" + gatewayId);
|
| - |
|
318 |
} catch (ConfigException e1) {
|
| - |
|
319 |
e1.printStackTrace();
|
| - |
|
320 |
}
|
| - |
|
321 |
String resourceDirPath = "/tmp/emi-resource/" + gatewayId + "/";
|
| 306 |
String amount = (new Double(amounta)).toString();
|
322 |
String amount = (new Double(amounta)).toString();
|
| 307 |
|
323 |
|
| 308 |
//Following is the code which initilize e24PaymentPipe with proper value
|
324 |
//Following is the code which initilize e24PaymentPipe with proper value
|
| 309 |
pipe.setResourcePath(resourceDirPath); //mandatory
|
325 |
pipe.setResourcePath(resourceDirPath); //mandatory
|
| 310 |
String as = pipe.getResourcePath();
|
326 |
String as = pipe.getResourcePath();
|