| 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.model.v1.order.LineItem;
|
4 |
import in.shop2020.model.v1.order.LineItem;
|
| 5 |
import in.shop2020.model.v1.order.Order;
|
5 |
import in.shop2020.model.v1.order.Order;
|
| - |
|
6 |
import in.shop2020.model.v1.order.RechargeOrder;
|
| 6 |
import in.shop2020.model.v1.order.Transaction;
|
7 |
import in.shop2020.model.v1.order.Transaction;
|
| 7 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
8 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| - |
|
9 |
import in.shop2020.model.v1.user.Address;
|
| 8 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
10 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 9 |
import in.shop2020.payment.domain.Payment;
|
11 |
import in.shop2020.payment.domain.Payment;
|
| 10 |
import in.shop2020.payments.Attribute;
|
12 |
import in.shop2020.payments.Attribute;
|
| 11 |
import in.shop2020.payments.PaymentException;
|
13 |
import in.shop2020.payments.PaymentException;
|
| 12 |
import in.shop2020.payments.PaymentStatus;
|
14 |
import in.shop2020.payments.PaymentStatus;
|
| 13 |
import in.shop2020.thrift.clients.TransactionClient;
|
15 |
import in.shop2020.thrift.clients.TransactionClient;
|
| - |
|
16 |
import in.shop2020.thrift.clients.UserClient;
|
| 14 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
17 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 15 |
|
18 |
|
| 16 |
import java.io.File;
|
19 |
import java.io.File;
|
| 17 |
import java.io.FileNotFoundException;
|
20 |
import java.io.FileNotFoundException;
|
| 18 |
import java.io.FileOutputStream;
|
21 |
import java.io.FileOutputStream;
|
| Line 43... |
Line 46... |
| 43 |
private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
|
46 |
private static final String regex = "[^a-zA-Z0-9\\s\\-\\@\\/\\.]";
|
| 44 |
private static final String replacement = " ";
|
47 |
private static final String replacement = " ";
|
| 45 |
private static final int MAX_UDF_LENGTH = 30;
|
48 |
private static final int MAX_UDF_LENGTH = 30;
|
| 46 |
private static final String currencyCode = "356";
|
49 |
private static final String currencyCode = "356";
|
| 47 |
private static String resourceDirPath = "/tmp/resource/";
|
50 |
private static String resourceDirPath = "/tmp/resource/";
|
| - |
|
51 |
|
| - |
|
52 |
private static String responseURLforRecharge;
|
| - |
|
53 |
|
| - |
|
54 |
private static String errorURLforRecharge;
|
| 48 |
private static final String resourceFileName = "resource.cgn";
|
55 |
private static final String resourceFileName = "resource.cgn";
|
| 49 |
|
56 |
|
| 50 |
private enum ActionType{
|
57 |
private enum ActionType{
|
| 51 |
PURCHASE("1"),
|
58 |
PURCHASE("1"),
|
| 52 |
AUTH ("4"),
|
59 |
AUTH ("4"),
|
| Line 81... |
Line 88... |
| 81 |
inputStream.close();
|
88 |
inputStream.close();
|
| 82 |
|
89 |
|
| 83 |
aliasName = ConfigClient.getClient().get("payment_alias_name");
|
90 |
aliasName = ConfigClient.getClient().get("payment_alias_name");
|
| 84 |
responseURL = ConfigClient.getClient().get("payment_response_url");
|
91 |
responseURL = ConfigClient.getClient().get("payment_response_url");
|
| 85 |
errorURL = ConfigClient.getClient().get("payment_error_url");
|
92 |
errorURL = ConfigClient.getClient().get("payment_error_url");
|
| - |
|
93 |
responseURLforRecharge = ConfigClient.getClient().get("payment_response_url_for_recharge");
|
| - |
|
94 |
errorURLforRecharge = ConfigClient.getClient().get("recharge_success_url");
|
| 86 |
} catch (ConfigException e) {
|
95 |
} catch (ConfigException e) {
|
| 87 |
log.error("Unable to get data from config server.");
|
96 |
log.error("Unable to get data from config server.");
|
| 88 |
} catch (FileNotFoundException e) {
|
97 |
} catch (FileNotFoundException e) {
|
| 89 |
// TODO Auto-generated catch block
|
98 |
// TODO Auto-generated catch block
|
| 90 |
e.printStackTrace();
|
99 |
e.printStackTrace();
|
| 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, false);
|
| 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, boolean isDigital) throws ShoppingCartException, TException{
|
| 306 |
String amount = (new Double(amounta)).toString();
|
315 |
String amount = (new Double(amounta)).toString();
|
| 307 |
|
316 |
|
| 308 |
//Following is the code which initilize e24PaymentPipe with proper value
|
317 |
//Following is the code which initilize e24PaymentPipe with proper value
|
| 309 |
pipe.setResourcePath(resourceDirPath); //mandatory
|
318 |
pipe.setResourcePath(resourceDirPath); //mandatory
|
| 310 |
String as = pipe.getResourcePath();
|
319 |
String as = pipe.getResourcePath();
|
| Line 315... |
Line 324... |
| 315 |
log.info("Alias= " +ab);
|
324 |
log.info("Alias= " +ab);
|
| 316 |
|
325 |
|
| 317 |
pipe.setAction(ActionType.AUTH.value()); //mandatory
|
326 |
pipe.setAction(ActionType.AUTH.value()); //mandatory
|
| 318 |
String ac=pipe.getAction();
|
327 |
String ac=pipe.getAction();
|
| 319 |
log.info("Action= " +ac);
|
328 |
log.info("Action= " +ac);
|
| 320 |
|
329 |
|
| - |
|
330 |
if(isDigital) {
|
| 321 |
pipe.setResponseURL( responseURL ); //mandatory
|
331 |
pipe.setResponseURL( responseURLforRecharge ); //mandatory
|
| - |
|
332 |
pipe.setErrorURL( errorURLforRecharge); //mandatory
|
| - |
|
333 |
} else {
|
| - |
|
334 |
pipe.setResponseURL( responseURL );
|
| - |
|
335 |
pipe.setErrorURL( errorURL);
|
| - |
|
336 |
}
|
| 322 |
String at=pipe.getResponseURL();
|
337 |
String at=pipe.getResponseURL();
|
| 323 |
log.info("ResponseURL= "+at);
|
338 |
log.info("ResponseURL= "+at);
|
| 324 |
|
339 |
|
| 325 |
//pipe.setErrorURL( errorURL + "?paymentId=" + merchantPaymentId ); //mandatory
|
340 |
//pipe.setErrorURL( errorURL + "?paymentId=" + merchantPaymentId ); //mandatory
|
| 326 |
pipe.setErrorURL( errorURL);
|
- |
|
| 327 |
String ak=pipe.getErrorURL();
|
341 |
String ak=pipe.getErrorURL();
|
| 328 |
log.info("ErrorURL= " + ak);
|
342 |
log.info("ErrorURL= " + ak);
|
| 329 |
|
343 |
|
| 330 |
|
344 |
|
| 331 |
pipe.setAmt(amount);
|
345 |
pipe.setAmt(amount);
|
| Line 348... |
Line 362... |
| 348 |
if(udfString.length() > MAX_UDF_LENGTH){
|
362 |
if(udfString.length() > MAX_UDF_LENGTH){
|
| 349 |
udfString = udfString.substring(0, MAX_UDF_LENGTH);
|
363 |
udfString = udfString.substring(0, MAX_UDF_LENGTH);
|
| 350 |
}
|
364 |
}
|
| 351 |
return udfString;
|
365 |
return udfString;
|
| 352 |
}
|
366 |
}
|
| - |
|
367 |
|
| - |
|
368 |
public static String initializeHdfcPayment(in.shop2020.payment.domain.Payment payment, RechargeOrder rechargeOrder,
|
| - |
|
369 |
PaymentServiceHandler paymentServiceHandler) throws Exception {
|
| - |
|
370 |
long merchantPaymentId = payment.getId();
|
| - |
|
371 |
double amount = payment.getAmount();
|
| - |
|
372 |
e24PaymentPipe pipe = new e24PaymentPipe();
|
| - |
|
373 |
|
| - |
|
374 |
try {
|
| - |
|
375 |
initializePayment(pipe, merchantPaymentId, amount, true);
|
| - |
|
376 |
} catch (ShoppingCartException e1) {
|
| - |
|
377 |
log.error("Error while creating hdfc payment.", e1);
|
| - |
|
378 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
| - |
|
379 |
} catch (TException e1) {
|
| - |
|
380 |
log.error("Error while creating hdfc payment.", e1);
|
| - |
|
381 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
| - |
|
382 |
}
|
| - |
|
383 |
|
| - |
|
384 |
List<Attribute> attributes = null;
|
| - |
|
385 |
try {
|
| - |
|
386 |
attributes = getAttributesAndSetUdfs(pipe, rechargeOrder);
|
| - |
|
387 |
} catch (TransactionServiceException e1) {
|
| - |
|
388 |
log.error("Error while setting udfs to payment.", e1);
|
| - |
|
389 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
| - |
|
390 |
} catch (TException e1) {
|
| - |
|
391 |
log.error("Error while setting udfs to payment.", e1);
|
| - |
|
392 |
throw e1; //Payment couldn't be initialized. Will be redirected to the shipping page.
|
| - |
|
393 |
}
|
| - |
|
394 |
|
| - |
|
395 |
try {
|
| - |
|
396 |
if(pipe.performPaymentInitialization() != e24PaymentPipe.SUCCESS) {
|
| - |
|
397 |
log.error("Error sending Payment Initialization Request: ");
|
| - |
|
398 |
paymentServiceHandler.updatePaymentDetails(merchantPaymentId, null, "", "", pipe.getErrorMsg(), "", "", "", "", PaymentStatus.INIT, "", attributes);
|
| - |
|
399 |
} else {
|
| - |
|
400 |
log.info("Payment Initialization Request processed successfully for payment Id: " + merchantPaymentId);
|
| - |
|
401 |
String paymentID = pipe.getPaymentId();
|
| - |
|
402 |
paymentServiceHandler.updatePaymentDetails(merchantPaymentId, paymentID, "", "", "", "", "", "", "", PaymentStatus.INIT, "", attributes);
|
| - |
|
403 |
|
| - |
|
404 |
String payURL = pipe.getPaymentPage();
|
| - |
|
405 |
return payURL + "?PaymentID=" + paymentID;
|
| - |
|
406 |
}
|
| - |
|
407 |
} catch (NotEnoughDataException e) {
|
| - |
|
408 |
log.error("Error while initializing payment.", e);
|
| - |
|
409 |
}catch (Exception e) {
|
| - |
|
410 |
log.error("Error while initializing payment.", e);
|
| - |
|
411 |
}
|
| - |
|
412 |
//If the code reaches here, the payment initialization was not successful and we've not returned the redirect URL.
|
| - |
|
413 |
//Throw the exception so that any failovers can happen.
|
| - |
|
414 |
throw new PaymentException(115, "Unable to initialize HDFC payment");
|
| - |
|
415 |
}
|
| - |
|
416 |
|
| - |
|
417 |
private static List<Attribute> getAttributesAndSetUdfs(e24PaymentPipe pipe, RechargeOrder rechargeOrder) throws TransactionServiceException, TException {
|
| - |
|
418 |
|
| - |
|
419 |
StringBuilder orderDetails = new StringBuilder();
|
| - |
|
420 |
StringBuilder billingAddress = new StringBuilder();
|
| - |
|
421 |
String email = "";
|
| - |
|
422 |
String contactNumber = "";
|
| - |
|
423 |
|
| - |
|
424 |
//get udfs
|
| - |
|
425 |
Address address = null;
|
| - |
|
426 |
try {
|
| - |
|
427 |
UserClient userClient = new UserClient();
|
| - |
|
428 |
address = userClient.getClient().getAddressById(userClient.getClient().getDefaultAddressId(rechargeOrder.getUserId()));
|
| - |
|
429 |
} catch (Exception e) {
|
| - |
|
430 |
log.error("Unable to get transaction details", e);
|
| - |
|
431 |
}
|
| - |
|
432 |
|
| - |
|
433 |
contactNumber= address.getPhone();
|
| - |
|
434 |
email = rechargeOrder.getUserEmailId();
|
| - |
|
435 |
billingAddress.append(" ");
|
| - |
|
436 |
if(address.getPin()!=null){
|
| - |
|
437 |
billingAddress.append(address.getPin());
|
| - |
|
438 |
}
|
| - |
|
439 |
if(address.getCity()!=null){
|
| - |
|
440 |
billingAddress.append(" " + address.getCity());
|
| - |
|
441 |
}
|
| - |
|
442 |
if(address.getLine1()!=null){
|
| - |
|
443 |
billingAddress.append(" " + address.getLine1());
|
| - |
|
444 |
}
|
| - |
|
445 |
if(address.getLine2()!=null){
|
| - |
|
446 |
billingAddress.append(" " + address.getLine2());
|
| - |
|
447 |
}
|
| - |
|
448 |
if(address.getState()!=null){
|
| - |
|
449 |
billingAddress.append(" " + address.getState());
|
| - |
|
450 |
}
|
| - |
|
451 |
orderDetails.append("Recharge : " + rechargeOrder.getDisplayId());
|
| - |
|
452 |
orderDetails.append(" ");
|
| - |
|
453 |
|
| - |
|
454 |
Random random = new Random();
|
| - |
|
455 |
String merchantInfo = ""+random.nextLong();
|
| - |
|
456 |
|
| - |
|
457 |
String udf1 = formatUdf(orderDetails.toString());
|
| - |
|
458 |
String udf2 = formatUdf(email);
|
| - |
|
459 |
String udf3 = formatUdf(contactNumber);
|
| - |
|
460 |
String udf4 = formatUdf(billingAddress.toString());
|
| - |
|
461 |
String udf5 = merchantInfo;
|
| - |
|
462 |
|
| - |
|
463 |
log.info("udf1:" + udf1);
|
| - |
|
464 |
log.info("udf2:" + udf2);
|
| - |
|
465 |
log.info("udf3:" + udf3);
|
| - |
|
466 |
log.info("udf4:" + udf4);
|
| - |
|
467 |
log.info("udf5:" + udf5);
|
| - |
|
468 |
|
| - |
|
469 |
|
| - |
|
470 |
pipe.setUdf1(udf1); // UDF 1 - Order details
|
| - |
|
471 |
pipe.setUdf2(udf2); // UDF 2 - Email ID
|
| - |
|
472 |
pipe.setUdf3(udf3); // UDF 3 - Contact Number.
|
| - |
|
473 |
pipe.setUdf4(udf4); // UDF 4 - Billing Address
|
| - |
|
474 |
pipe.setUdf5(udf5); // UDF 5 - Merchant specific
|
| - |
|
475 |
|
| - |
|
476 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
| - |
|
477 |
Attribute attribute1 = new Attribute("udf1",udf1);
|
| - |
|
478 |
Attribute attribute2 = new Attribute("udf2",udf2);
|
| - |
|
479 |
Attribute attribute3 = new Attribute("udf3",udf3);
|
| - |
|
480 |
Attribute attribute4 = new Attribute("udf4",udf4);
|
| - |
|
481 |
Attribute attribute5 = new Attribute("udf5",udf5);
|
| - |
|
482 |
|
| - |
|
483 |
attributes.add(attribute1);
|
| - |
|
484 |
attributes.add(attribute2);
|
| - |
|
485 |
attributes.add(attribute3);
|
| - |
|
486 |
attributes.add(attribute4);
|
| - |
|
487 |
attributes.add(attribute5);
|
| - |
|
488 |
|
| - |
|
489 |
return attributes;
|
| - |
|
490 |
}
|
| 353 |
}
|
491 |
}
|