| Line 4... |
Line 4... |
| 4 |
import in.shop2020.payment.domain.Refund;
|
4 |
import in.shop2020.payment.domain.Refund;
|
| 5 |
import in.shop2020.payment.handler.PaymentGatewayHandler;
|
5 |
import in.shop2020.payment.handler.PaymentGatewayHandler;
|
| 6 |
import in.shop2020.payment.handler.PaymentHandler;
|
6 |
import in.shop2020.payment.handler.PaymentHandler;
|
| 7 |
import in.shop2020.payment.handler.PaymentRequiringExtraProcessingHandler;
|
7 |
import in.shop2020.payment.handler.PaymentRequiringExtraProcessingHandler;
|
| 8 |
import in.shop2020.payment.handler.RefundHandler;
|
8 |
import in.shop2020.payment.handler.RefundHandler;
|
| - |
|
9 |
import in.shop2020.payment.service.handler.IPaymentHandler.Errors;
|
| 9 |
import in.shop2020.payments.Attribute;
|
10 |
import in.shop2020.payments.Attribute;
|
| 10 |
import in.shop2020.payments.ExtraPaymentProcessingType;
|
11 |
import in.shop2020.payments.ExtraPaymentProcessingType;
|
| 11 |
import in.shop2020.payments.Payment;
|
12 |
import in.shop2020.payments.Payment;
|
| 12 |
import in.shop2020.payments.PaymentException;
|
13 |
import in.shop2020.payments.PaymentException;
|
| 13 |
import in.shop2020.payments.PaymentGateway;
|
14 |
import in.shop2020.payments.PaymentGateway;
|
| Line 422... |
Line 423... |
| 422 |
//Capture and update the HDFC EMI payment
|
423 |
//Capture and update the HDFC EMI payment
|
| 423 |
return captureAndUpdateHdfcEmiPayment(payment);
|
424 |
return captureAndUpdateHdfcEmiPayment(payment);
|
| 424 |
} else if (gatewayId == EBAY_GATEWAY_ID || gatewayId == SNAPDEAL_GATEWAY_ID) {
|
425 |
} else if (gatewayId == EBAY_GATEWAY_ID || gatewayId == SNAPDEAL_GATEWAY_ID) {
|
| 425 |
return true;
|
426 |
return true;
|
| 426 |
} else if (gatewayId == PAYU_GATEWAY_ID) {
|
427 |
} else if (gatewayId == PAYU_GATEWAY_ID) {
|
| 427 |
return catpureAndUpdatePayuPayment(payment);
|
428 |
return captureAndUpdatePayuPayment(payment);
|
| 428 |
}
|
429 |
}
|
| 429 |
|
430 |
|
| 430 |
logger.error("We have an authorized payment from unknown gateway: " + gatewayId);
|
431 |
logger.error("We have an authorized payment from unknown gateway: " + gatewayId);
|
| 431 |
return false;
|
432 |
return false;
|
| 432 |
}
|
433 |
}
|
| 433 |
|
434 |
|
| - |
|
435 |
private boolean captureAndUpdatePayuPayment(in.shop2020.payment.domain.Payment payment) throws PaymentException{
|
| - |
|
436 |
long merchantPaymentId = payment.getId();
|
| - |
|
437 |
|
| - |
|
438 |
logger.info("Capturing Payu payment with id: " + merchantPaymentId);
|
| - |
|
439 |
Map<String, String> attrMap = new HashMap<String, String>();
|
| - |
|
440 |
Map<String, String> captureResult = PayuPaymentHandler.captureTransaction(merchantPaymentId + "", payment.getGatewayTxnId());
|
| - |
|
441 |
if(captureResult.containsKey(IPaymentHandler.ERROR)){
|
| - |
|
442 |
payment.setDescription(captureResult.get(IPaymentHandler.ERROR));
|
| - |
|
443 |
payment.setErrorCode(captureResult.get(IPaymentHandler.ERR_CODE));
|
| - |
|
444 |
payment.setErrorTimestamp(new Date());
|
| - |
|
445 |
if(captureResult.get(IPaymentHandler.ERR_CODE).equals(Errors.CAPTURE_FAILURE)) {
|
| - |
|
446 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| 434 |
private boolean catpureAndUpdatePayuPayment(
|
447 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
448 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
449 |
} else {
|
| - |
|
450 |
logger.error("Capture attempt failed for HDFC payment with id: " + merchantPaymentId);
|
| - |
|
451 |
payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
|
| 435 |
in.shop2020.payment.domain.Payment payment) {
|
452 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
453 |
throw new PaymentException(106, captureResult.get(IPaymentHandler.ERROR));
|
| - |
|
454 |
}
|
| 436 |
return false;
|
455 |
return false;
|
| - |
|
456 |
} else {
|
| - |
|
457 |
logger.info("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
|
| - |
|
458 |
payment.setDescription("Payment Captured");
|
| - |
|
459 |
payment.setGatewayTxnStatus("captured");
|
| - |
|
460 |
payment.setStatus(PaymentStatus.SUCCESS.getValue());
|
| - |
|
461 |
payment.setSuccessTimestamp(new Date());
|
| - |
|
462 |
payment.setReferenceCode(captureResult.get(PayuPaymentHandler.REF_NO));
|
| - |
|
463 |
attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, captureResult.get(IPaymentHandler.CAPTURE_TXN_ID));
|
| - |
|
464 |
attrMap.put(IPaymentHandler.CAPTURE_REF_ID, captureResult.get(IPaymentHandler.CAPTURE_REF_ID));
|
| - |
|
465 |
attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, captureResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
|
| - |
|
466 |
|
| - |
|
467 |
SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| - |
|
468 |
attrMap.put(HdfcPaymentHandler.CAPTURE_TIME, captureTimeDateFormatter.format(new Date()));
|
| - |
|
469 |
|
| - |
|
470 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
471 |
return true;
|
| - |
|
472 |
}
|
| 437 |
}
|
473 |
}
|
| 438 |
|
474 |
|
| 439 |
@Override
|
475 |
@Override
|
| 440 |
public boolean partiallyCapturePayment(long merchantTxnId, double amount, String xferBy, String xferTxnId, long xferDate) throws PaymentException, TException {
|
476 |
public boolean partiallyCapturePayment(long merchantTxnId, double amount, String xferBy, String xferTxnId, long xferDate) throws PaymentException, TException {
|
| 441 |
logger.info("Attempting to partially capture payment corresponding to our transaction " + merchantTxnId);
|
477 |
logger.info("Attempting to partially capture payment corresponding to our transaction " + merchantTxnId);
|