Subversion Repositories SmartDukaan

Rev

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

Rev 6449 Rev 6482
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
	
-
 
275
	public synchronized boolean refundPayment(long merchantTxnId, double amount) throws PaymentException, TException {
-
 
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);
-
 
278
        if(payments ==null || payments.isEmpty())
-
 
279
            throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
-
 
280
        
-
 
281
        in.shop2020.payment.domain.Payment payment = payments.get(0);
-
 
282
        switch(PaymentStatus.findByValue(payment.getStatus())){
-
 
283
        case PENDING:
-
 
284
            logger.error("Attempt to refund a non-authorized payment");
-
 
285
            return false;
-
 
286
        case INIT:
-
 
287
            logger.warn("Attempt to refund a non-authorized payment");
-
 
288
            return false;
-
 
289
        case AUTHORIZED:
-
 
290
        	logger.warn("Attempt to refund a non-captured payment");
-
 
291
            return false;
-
 
292
        case CAPTURE_IN_PROCESS:
-
 
293
        	logger.warn("Attempt to refund a non-captured payment");
-
 
294
            return false;
-
 
295
        case PROVISIONALLY_CAPTURED:
-
 
296
        	logger.warn("Attempt to refund a non-captured payment");
-
 
297
            return false;
-
 
298
        case SUCCESS:
-
 
299
            break;
-
 
300
        case FAILED:
-
 
301
            logger.error("Attempting to capture a failed payment");
-
 
302
            return false;
-
 
303
        }
-
 
304
        
-
 
305
        long gatewayId = payment.getGatewayId();
-
 
306
        
-
 
307
        if(gatewayId == HDFC_GATEWAY_ID){
-
 
308
            //Capture and update the HDFC payment
-
 
309
            return refundHdfcPayment(payment, amount);
-
 
310
        } 
-
 
311
        
-
 
312
//        else if (gatewayId == EBS_GATEWAY_ID){
-
 
313
//            //Capture and update the EBS payment
-
 
314
//            return refundEbsPayment(payment);
-
 
315
//        } else if (HDFC_EMI_GATEWAY_IDS.contains(gatewayId)){
-
 
316
//            //Capture and update the HDFC EMI payment
-
 
317
//            return refundsHdfcEmiPayment(payment);
-
 
318
//        }
-
 
319
        
-
 
320
        logger.error("We have an captured payment from unknown gateway: " + gatewayId);
-
 
321
        return false;
-
 
322
    }
-
 
323
	
-
 
324
	
274
	@Override
325
	@Override
275
    public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
326
    public long createRefund(long orderId, long merchantTxnId, double amount) throws PaymentException, TException{
276
	    logger.info("Attempting to create a refund for order: " + orderId);
327
		logger.info("Attempting to create a refund for order: " + orderId);
-
 
328
		if(!refundPayment(merchantTxnId, amount)){
-
 
329
			throw new PaymentException(104, "Not able to refund corresponding to the merchant txn " + merchantTxnId);
-
 
330
		}
277
		List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
331
		List<in.shop2020.payment.domain.Payment> payments = paymentHandler.getPaymentForTxn(merchantTxnId);
278
		if(payments ==null || payments.isEmpty())
332
		if(payments ==null || payments.isEmpty())
279
			throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
333
			throw new PaymentException(104, "No payments found corresponding to the merchant txn " + merchantTxnId);
280
		
334
		
281
		in.shop2020.payment.domain.Payment payment = payments.get(0);
335
		in.shop2020.payment.domain.Payment payment = payments.get(0);
Line 543... Line 597...
543
            paymentHandler.updatePayment(payment, attrMap);
597
            paymentHandler.updatePayment(payment, attrMap);
544
            return true;
598
            return true;
545
        }
599
        }
546
    }
600
    }
547
 
601
 
-
 
602
 
-
 
603
    /**
-
 
604
     * Refund the HDFC payment represented by the given payment object. If the
-
 
605
     * refund attempt is not successful, will not any action.
-
 
606
     * 
-
 
607
     * @param payment The payment which has to be captured.
-
 
608
     * @amount amount to be refunded
-
 
609
     * @return True if the payment attempt is successful, false if not.
-
 
610
     * @throws PaymentException 
-
 
611
     */
-
 
612
    private boolean refundHdfcPayment(in.shop2020.payment.domain.Payment payment, double amount) throws PaymentException {
-
 
613
        long merchantPaymentId = payment.getId();
-
 
614
        logger.info("Refunding HDFC payment with id: " + merchantPaymentId);
-
 
615
        Map<String, String> refundResult = HdfcPaymentHandler.refundPayment(payment, amount);
-
 
616
        String captureStatus = refundResult.get(IPaymentHandler.STATUS);
-
 
617
        String gatewayStatus = refundResult.get(IPaymentHandler.GATEWAY_STATUS);
-
 
618
 
-
 
619
        Map<String, String> attrMap = new HashMap<String, String>();
-
 
620
        if (!captureStatus.trim().equals("0") 
-
 
621
                || !HdfcPaymentReturnStatus.CAPTURED.value().equals(gatewayStatus)) {
-
 
622
            return false;
-
 
623
        } else {
-
 
624
            // Success
-
 
625
            logger.info("Refund attempt successful for HDFC payment with id: " + merchantPaymentId);
-
 
626
            payment.setDescription("Payment Refunded");
-
 
627
            payment.setGatewayTxnStatus(gatewayStatus);
-
 
628
            payment.setStatus(PaymentStatus.SUCCESS.getValue());           
-
 
629
            
-
 
630
            attrMap.put(IPaymentHandler.CAPTURE_TXN_ID, refundResult.get(IPaymentHandler.CAPTURE_TXN_ID));
-
 
631
            attrMap.put(IPaymentHandler.CAPTURE_REF_ID, refundResult.get(IPaymentHandler.CAPTURE_REF_ID));
-
 
632
            attrMap.put(IPaymentHandler.CAPTURE_AUTH_ID, refundResult.get(IPaymentHandler.CAPTURE_AUTH_ID));
-
 
633
 
-
 
634
            SimpleDateFormat captureTimeDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
635
            attrMap.put(HdfcPaymentHandler.CAPTURE_TIME, captureTimeDateFormatter.format(new Date()));
-
 
636
 
-
 
637
            paymentHandler.updatePayment(payment, attrMap);
-
 
638
            return true;
-
 
639
          }
-
 
640
    }
-
 
641
 
-
 
642
 
-
 
643
    
548
    /**
644
    /**
549
     * Updates the settlement details of COD payments. Sets payment status as
645
     * Updates the settlement details of COD payments. Sets payment status as
550
     * either PARTIALLY CAPTURED or SUCCESS depending on whether the complete
646
     * either PARTIALLY CAPTURED or SUCCESS depending on whether the complete
551
     * amount has been captured. Other parameters are set as attributes.
647
     * amount has been captured. Other parameters are set as attributes.
552
     * 
648
     *