Subversion Repositories SmartDukaan

Rev

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

Rev 6488 Rev 6491
Line 315... Line 315...
315
        }
315
        }
316
        
316
        
317
        long gatewayId = payment.getGatewayId();
317
        long gatewayId = payment.getGatewayId();
318
        
318
        
319
        if(gatewayId == HDFC_GATEWAY_ID){
319
        if(gatewayId == HDFC_GATEWAY_ID){
320
            //Capture and update the HDFC payment
320
            //Refund the HDFC payment
321
            return refundHdfcPayment(payment, amount);
321
            return refundHdfcPayment(payment, amount);
-
 
322
        }else if (gatewayId == EBS_GATEWAY_ID){
-
 
323
            //Refund the EBS payment
-
 
324
            return refundEbsPayment(payment, amount);
322
        } 
325
        } 
323
        
-
 
324
//        else if (gatewayId == EBS_GATEWAY_ID){
-
 
325
//            //Capture and update the EBS payment
-
 
326
//            return refundEbsPayment(payment);
-
 
327
//        } else if (HDFC_EMI_GATEWAY_IDS.contains(gatewayId)){
326
        else if (HDFC_EMI_GATEWAY_IDS.contains(gatewayId)){
328
//            //Capture and update the HDFC EMI payment
327
             //Capture and update the HDFC EMI payment
329
//            return refundsHdfcEmiPayment(payment);
328
            return refundHdfcEmiPayment(payment, amount);
330
//        }
329
        }
331
        
330
        
332
        logger.error("We have an captured payment from unknown gateway: " + gatewayId);
331
        logger.error("We have an captured payment from unknown gateway: " + gatewayId);
333
        return false;
332
        return false;
334
    }
333
    }
335
	
334
	
Line 644... Line 643...
644
                //payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
643
                //payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
645
                //paymentHandler.updatePayment(payment, attrMap);
644
                //paymentHandler.updatePayment(payment, attrMap);
646
                throw new PaymentException(106, "Could not capture due to connection issue. Try Later");
645
                throw new PaymentException(106, "Could not capture due to connection issue. Try Later");
647
            }
646
            }
648
            else {
647
            else {
649
                payment.setStatus(PaymentStatus.FAILED.getValue());
648
//                payment.setStatus(PaymentStatus.FAILED.getValue());
650
                paymentHandler.updatePayment(payment, attrMap);
649
//                paymentHandler.updatePayment(payment, attrMap);
651
                persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
650
                persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
652
            }
651
            }
653
 
652
 
654
            return false;
653
            return false;
655
        } else {
654
        } else {
Line 670... Line 669...
670
            return true;
669
            return true;
671
          }
670
          }
672
    }
671
    }
673
 
672
 
674
 
673
 
-
 
674
    /**
-
 
675
     * Refund the HDFC EMI payment represented by the given payment object. If
-
 
676
     * the capture attempt is not successful, we will not do anything.
-
 
677
     * 
-
 
678
     * @param payment
-
 
679
     *            The payment which has to be captured.
-
 
680
     * @return True if the payment attempt is successful, false if not.
-
 
681
     * @throws PaymentException 
-
 
682
     */
-
 
683
    private boolean refundHdfcEmiPayment(in.shop2020.payment.domain.Payment payment, double amount) throws PaymentException{
-
 
684
        long merchantPaymentId = payment.getId();
-
 
685
        logger.info("Refunding HDFC payment with id: " + merchantPaymentId);
-
 
686
        Map<String, String> refundResult = HdfcEmiPaymentHandler.refundPayment(payment, amount);
-
 
687
        String refundStatus = refundResult.get(IPaymentHandler.STATUS);
-
 
688
        String gatewayStatus = refundResult.get(IPaymentHandler.GATEWAY_STATUS);
-
 
689
 
-
 
690
        Map<String, String> attrMap = new HashMap<String, String>();
-
 
691
        if (!refundStatus.trim().equals("0") 
-
 
692
                || !HdfcPaymentReturnStatus.CAPTURED.value().equals(gatewayStatus)) {
-
 
693
            // Failure
-
 
694
            logger.error("Refund attempt failed for HDFC payment with id: " + merchantPaymentId);
-
 
695
            String description = refundResult.get(IPaymentHandler.ERROR);
-
 
696
            String errorCode = refundResult.get(IPaymentHandler.ERR_CODE);
-
 
697
 
-
 
698
            payment.setDescription(description);
-
 
699
            payment.setErrorCode(errorCode);
-
 
700
            payment.setErrorTimestamp(new Date());                
-
 
701
 
-
 
702
            // Not marking payments as failed in case of connection issues
-
 
703
            if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
-
 
704
             //   payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());
-
 
705
             //   paymentHandler.updatePayment(payment, attrMap);
-
 
706
                throw new PaymentException(106, "Could not capture due to connection issue");
-
 
707
            }
-
 
708
            else {
-
 
709
              //  payment.setStatus(PaymentStatus.FAILED.getValue());
-
 
710
              //  paymentHandler.updatePayment(payment, attrMap);
-
 
711
                persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
-
 
712
            }
-
 
713
 
-
 
714
            return false;
-
 
715
        } else {
-
 
716
            // Success
-
 
717
            logger.info("Refund attempt successful for HDFC payment with id: " + merchantPaymentId);
-
 
718
            payment.setDescription("Payment Refunded");
-
 
719
            payment.setGatewayTxnStatus(gatewayStatus);
-
 
720
            payment.setStatus(PaymentStatus.REFUNDED.getValue());           
-
 
721
            
-
 
722
            attrMap.put(IPaymentHandler.REFUND_TXN_ID, refundResult.get(IPaymentHandler.REFUND_TXN_ID));
-
 
723
            attrMap.put(IPaymentHandler.REFUND_REF_ID, refundResult.get(IPaymentHandler.REFUND_REF_ID));
-
 
724
            attrMap.put(IPaymentHandler.REFUND_AUTH_ID, refundResult.get(IPaymentHandler.REFUND_AUTH_ID));
-
 
725
 
-
 
726
            SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
727
            attrMap.put(HdfcPaymentHandler.REFUND_TIME, captureTimeDateFormatter.format(new Date()));
-
 
728
 
-
 
729
            paymentHandler.updatePayment(payment, attrMap);
-
 
730
            return true;
-
 
731
          }
-
 
732
    }
-
 
733
    
-
 
734
    /**
-
 
735
     * Refund the EBS payment represented by the given payment object. If the
-
 
736
     * capture attempt is not successful, we will ignore. We don't retry or anything. 
-
 
737
     * We'll add the support of multiple attempts later on.
-
 
738
     * 
-
 
739
     * @param payment The payment which has to be captured.
-
 
740
     * @amount Amount to be refunded
-
 
741
     * @return True if the payment attempt is successful, false if not.
-
 
742
     * @throws PaymentException 
-
 
743
     */
-
 
744
    private boolean refundEbsPayment(in.shop2020.payment.domain.Payment payment, double amount) throws PaymentException{
-
 
745
        Map<String, String> refundResult = EbsPaymentHandler.refundPayment(payment, amount);
-
 
746
        String refundStatus = refundResult.get(EbsPaymentHandler.STATUS);
-
 
747
        
-
 
748
        Map<String, String> attrMap = new HashMap<String, String>();
-
 
749
        if("".equals(refundStatus)){
-
 
750
            //Failure
-
 
751
            logger.error("Refund attempt failed for EBS payment with id: " + payment.getId());
-
 
752
            String description = refundResult.get(EbsPaymentHandler.ERROR);
-
 
753
            String errorCode = refundResult.get(EbsPaymentHandler.ERR_CODE);
-
 
754
 
-
 
755
            payment.setDescription(description);
-
 
756
            payment.setErrorCode(errorCode);
-
 
757
            payment.setErrorTimestamp(new Date());
-
 
758
 
-
 
759
            if (IPaymentHandler.Errors.CONN_FAILURE.code.equals(errorCode)) {
-
 
760
//                payment.setStatus(PaymentStatus.CAPTURE_IN_PROCESS.getValue());            
-
 
761
//                paymentHandler.updatePayment(payment, attrMap);
-
 
762
                throw new PaymentException(106, "Could not capture due to connection issue");
-
 
763
            }
-
 
764
            else {
-
 
765
//                payment.setStatus(PaymentStatus.FAILED.getValue());            
-
 
766
//                paymentHandler.updatePayment(payment, attrMap);
-
 
767
                persistPaymentRequiringExtraProcessing(payment, ExtraPaymentProcessingType.FAILED_PAYMENTS);
-
 
768
            }
-
 
769
 
-
 
770
            return false;
-
 
771
        }else{
-
 
772
            //Success
-
 
773
            logger.info("Refund attempt successful for EBS payment with id: " + payment.getId());
-
 
774
            payment.setGatewayTxnStatus(refundStatus);
-
 
775
            payment.setStatus(PaymentStatus.REFUNDED.getValue());
-
 
776
            
-
 
777
            attrMap.put(IPaymentHandler.REFUND_TXN_ID, refundResult.get(IPaymentHandler.REFUND_TXN_ID));
-
 
778
            attrMap.put(IPaymentHandler.REFUND_TIME, refundResult.get(IPaymentHandler.REFUND_TIME));
-
 
779
            paymentHandler.updatePayment(payment, attrMap);
-
 
780
            return true;
-
 
781
        }
-
 
782
    }
-
 
783
    
675
    
784
    
676
    /**
785
    /**
677
     * Updates the settlement details of COD payments. Sets payment status as
786
     * Updates the settlement details of COD payments. Sets payment status as
678
     * either PARTIALLY CAPTURED or SUCCESS depending on whether the complete
787
     * either PARTIALLY CAPTURED or SUCCESS depending on whether the complete
679
     * amount has been captured. Other parameters are set as attributes.
788
     * amount has been captured. Other parameters are set as attributes.