| Line 269... |
Line 269... |
| 269 |
throw new PaymentException(102, "Error while initiliazing payment. Check service log for more details.");
|
269 |
throw new PaymentException(102, "Error while initiliazing payment. Check service log for more details.");
|
| 270 |
}
|
270 |
}
|
| 271 |
return redirectURL;
|
271 |
return redirectURL;
|
| 272 |
}
|
272 |
}
|
| 273 |
|
273 |
|
| 274 |
|
274 |
@Override
|
| 275 |
public synchronized boolean refundPayment(long merchantTxnId, double amount) throws PaymentException, TException {
|
275 |
public synchronized boolean refundPayment(long merchantTxnId, double amount, boolean isDigital) throws PaymentException, TException {
|
| 276 |
logger.info("Attempting to refund payment of amount " + amount + " corresponding to our transaction " + merchantTxnId);
|
276 |
logger.info("Attempting to refund payment of amount " + amount + " corresponding to our transaction " + merchantTxnId);
|
| 277 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
277 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
| 278 |
if(payments ==null || payments.isEmpty())
|
278 |
if(payments ==null || payments.isEmpty())
|
| 279 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
279 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
| 280 |
|
280 |
|
| - |
|
281 |
if(payments ==null || payments.isEmpty())
|
| - |
|
282 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
| - |
|
283 |
|
| 281 |
in.shop2020.payment.domain.Payment payment = payments.get(0);
|
284 |
in.shop2020.payment.domain.Payment payment = payments.get(0);
|
| - |
|
285 |
|
| - |
|
286 |
if(payment.getAmount() < amount){
|
| - |
|
287 |
logger.warn("Refund amount is more than payment amount.");
|
| - |
|
288 |
return false;
|
| - |
|
289 |
}
|
| - |
|
290 |
|
| 282 |
switch(PaymentStatus.findByValue(payment.getStatus())){
|
291 |
switch(PaymentStatus.findByValue(payment.getStatus())){
|
| 283 |
case PENDING:
|
292 |
case PENDING:
|
| 284 |
logger.error("Attempt to refund a non-authorized payment");
|
293 |
logger.error("Attempt to refund a non-authorized payment");
|
| 285 |
return false;
|
294 |
return false;
|
| 286 |
case INIT:
|
295 |
case INIT:
|
| Line 293... |
Line 302... |
| 293 |
logger.warn("Attempt to refund a non-captured payment");
|
302 |
logger.warn("Attempt to refund a non-captured payment");
|
| 294 |
return false;
|
303 |
return false;
|
| 295 |
case PROVISIONALLY_CAPTURED:
|
304 |
case PROVISIONALLY_CAPTURED:
|
| 296 |
logger.warn("Attempt to refund a non-captured payment");
|
305 |
logger.warn("Attempt to refund a non-captured payment");
|
| 297 |
return false;
|
306 |
return false;
|
| - |
|
307 |
case REFUNDED:
|
| - |
|
308 |
logger.warn("Attempt to refund a refunded payment");
|
| - |
|
309 |
return false;
|
| 298 |
case SUCCESS:
|
310 |
case SUCCESS:
|
| 299 |
break;
|
311 |
break;
|
| 300 |
case FAILED:
|
312 |
case FAILED:
|
| 301 |
logger.error("Attempting to capture a failed payment");
|
313 |
logger.error("Attempting to capture a failed payment");
|
| 302 |
return false;
|
314 |
return false;
|
| Line 323... |
Line 335... |
| 323 |
|
335 |
|
| 324 |
|
336 |
|
| 325 |
@Override
|
337 |
@Override
|
| 326 |
public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
|
338 |
public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
|
| 327 |
logger.info("Attempting to create a refund for order: " + orderId);
|
339 |
logger.info("Attempting to create a refund for order: " + orderId);
|
| 328 |
if(!refundPayment(merchantTxnId, amount)){
|
340 |
if(!refundPayment(merchantTxnId, amount, false)){
|
| 329 |
throw new PaymentException(104, "Not able to refund corresponding to the merchant txn " + merchantTxnId);
|
341 |
logger.warn("Not able to refund corresponding to the merchant txn " + merchantTxnId);
|
| 330 |
}
|
342 |
}
|
| 331 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
343 |
List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
|
| 332 |
if(payments ==null || payments.isEmpty())
|
344 |
if(payments ==null || payments.isEmpty())
|
| 333 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
345 |
throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
|
| 334 |
|
346 |
|
| Line 611... |
Line 623... |
| 611 |
*/
|
623 |
*/
|
| 612 |
private boolean refundHdfcPayment(in.shop2020.payment.domain.Payment payment, double amount) throws PaymentException {
|
624 |
private boolean refundHdfcPayment(in.shop2020.payment.domain.Payment payment, double amount) throws PaymentException {
|
| 613 |
long merchantPaymentId = payment.getId();
|
625 |
long merchantPaymentId = payment.getId();
|
| 614 |
logger.info("Refunding HDFC payment with id: " + merchantPaymentId);
|
626 |
logger.info("Refunding HDFC payment with id: " + merchantPaymentId);
|
| 615 |
Map<String, String> refundResult = HdfcPaymentHandler.refundPayment(payment, amount);
|
627 |
Map<String, String> refundResult = HdfcPaymentHandler.refundPayment(payment, amount);
|
| 616 |
String captureStatus = refundResult.get(IPaymentHandler.STATUS);
|
628 |
String refundStatus = refundResult.get(IPaymentHandler.STATUS);
|
| 617 |
String gatewayStatus = refundResult.get(IPaymentHandler.GATEWAY_STATUS);
|
629 |
String gatewayStatus = refundResult.get(IPaymentHandler.GATEWAY_STATUS);
|
| 618 |
|
630 |
|
| 619 |
Map<String, String> attrMap = new HashMap<String, String>();
|
631 |
Map<String, String> attrMap = new HashMap<String, String>();
|
| 620 |
if (!captureStatus.trim().equals("0")
|
632 |
if (!refundStatus.trim().equals("0")
|
| 621 |
|| !HdfcPaymentReturnStatus.CAPTURED.value().equals(gatewayStatus)) {
|
633 |
|| !HdfcPaymentReturnStatus.CAPTURED.value().equals(gatewayStatus)) {
|
| - |
|
634 |
|
| - |
|
635 |
logger.error("Refund attempt failed for HDFC payment with id: " + merchantPaymentId);
|
| - |
|
636 |
String description = refundResult.get(IPaymentHandler.ERROR);
|
| - |
|
637 |
String errorCode = refundResult.get(IPaymentHandler.ERR_CODE);
|
| - |
|
638 |
|
| - |
|
639 |
payment.setDescription(description);
|
| - |
|
640 |
payment.setErrorCode(errorCode);
|
| - |
|
641 |
payment.setErrorTimestamp(new Date());
|
| - |
|
642 |
|
| - |
|
643 |
if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
|
| - |
|
644 |
//payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
|
| - |
|
645 |
//paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
646 |
throw new PaymentException(106, "Could not capture due to connection issue. Try Later");
|
| - |
|
647 |
}
|
| - |
|
648 |
else {
|
| - |
|
649 |
payment.setStatus(PaymentStatus.FAILED.getValue());
|
| - |
|
650 |
paymentHandler.updatePayment(payment, attrMap);
|
| - |
|
651 |
persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
|
| - |
|
652 |
}
|
| - |
|
653 |
|
| 622 |
return false;
|
654 |
return false;
|
| 623 |
} else {
|
655 |
} else {
|
| 624 |
// Success
|
656 |
// Success
|
| 625 |
logger.info("Refund attempt successful for HDFC payment with id: " + merchantPaymentId);
|
657 |
logger.info("Refund attempt successful for HDFC payment with id: " + merchantPaymentId);
|
| 626 |
payment.setDescription("Payment Refunded");
|
658 |
payment.setDescription("Payment Refunded");
|
| 627 |
payment.setGatewayTxnStatus(gatewayStatus);
|
659 |
payment.setGatewayTxnStatus(gatewayStatus);
|
| 628 |
payment.setStatus(PaymentStatus.SUCCESS.getValue());
|
660 |
payment.setStatus(PaymentStatus.REFUNDED.getValue());
|
| 629 |
|
661 |
|
| 630 |
attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, refundResult.get(IPaymentHandler.CAPTURE_TXN_ID));
|
662 |
attrMap.put(IPaymentHandler.REFUND_TXN_ID, refundResult.get(IPaymentHandler.REFUND_TXN_ID));
|
| 631 |
attrMap.put(IPaymentHandler.CAPTURE_REF_ID, refundResult.get(IPaymentHandler.CAPTURE_REF_ID));
|
663 |
attrMap.put(IPaymentHandler.REFUND_REF_ID, refundResult.get(IPaymentHandler.REFUND_REF_ID));
|
| 632 |
attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, refundResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
|
664 |
attrMap.put(IPaymentHandler.REFUND_AUTH_ID, refundResult.get(IPaymentHandler.REFUND_AUTH_ID));
|
| 633 |
|
665 |
|
| 634 |
SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
666 |
SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 635 |
attrMap.put(HdfcPaymentHandler.CAPTURE_TIME, captureTimeDateFormatter.format(new Date()));
|
667 |
attrMap.put(HdfcPaymentHandler.REFUND_TIME, captureTimeDateFormatter.format(new Date()));
|
| 636 |
|
668 |
|
| 637 |
paymentHandler.updatePayment(payment, attrMap);
|
669 |
paymentHandler.updatePayment(payment, attrMap);
|
| 638 |
return true;
|
670 |
return true;
|
| 639 |
}
|
671 |
}
|
| 640 |
}
|
672 |
}
|