Rev 10269 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.services;import in.shop2020.payments.Attribute;import in.shop2020.payments.Payment;import in.shop2020.payments.PaymentStatus;import in.shop2020.thrift.clients.PaymentClient;import java.util.ArrayList;import java.util.List;import org.apache.log4j.Logger;public class HdfcEmiPaymentService implements IPaymentService {private static Logger log = Logger.getLogger(HdfcEmiPaymentService.class);private String redirectURL;public HdfcEmiPaymentService() {}public long createPayment(long userId, long txnId, String paymentOption, int gatewayId, String paymentType){log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC EMI");CommonPaymentService cps = new CommonPaymentService();if(!cps.createPayment(userId, txnId, gatewayId)){log.error("Error while creating the basic payment");return PAYMENT_NOT_CREATED;}else{return initializePayment(cps.getPaymentId(), paymentOption, cps.getAmount(), paymentType);}}private long initializePayment(long merchantPaymentId, String paymentOption, double amount,String paymentType){List<Attribute> attributes = new ArrayList<Attribute>();attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));double emiAmount = CommonPaymentService.calculateEmiAmount(paymentOption, amount);if(emiAmount > 0){attributes.add(new Attribute(IPaymentService.EMI_AMOUNT, ""+emiAmount));}PaymentClient paymentServiceClient = null;try {paymentServiceClient = new PaymentClient();} catch (Exception e) {log.error("Error while getting payment client", e);return PAYMENT_NOT_CREATED;}try {paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);this.redirectURL = paymentServiceClient.getClient().initializeHdfcEmiPayment(merchantPaymentId, false);return merchantPaymentId;}catch (Exception e) {log.error("Error while initializing payment.", e);return PAYMENT_NOT_CREATED;}}public String getRedirectUrl(){return this.redirectURL;}public static void main(String args[]){Payment payment = new Payment();payment.setPaymentId(216);payment.setAmount(40000);payment.setGatewayPaymentId("TESTSTSTS");// The underlying method calls are no longer valid since all the// information required to capture a payment is read from the database// itself and can't be specified through the call.//This test checks what happens when the txn id is left blank//capturePayment(payment, ""); //Result: !ERROR!-GW00205-Invalid Subsequent Transaction.//This test checks what happends with an invalid txn id//capturePayment(payment, "6022630101411740"); //Result: !ERROR!-GW00201-Transaction not found.//The next three tests require a valid AUTH transaction id.//This test checks what happens when we attempt to capture an amount greater than what was authorized.//capturePayment(payment, "9644960021411730"); //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.//This test checks what happens when we attempt to capture a valid transaction with the right amount. This transaction should be CAPTURED.//payment.setAmount(21698);//capturePayment(payment, "9644960021411730"); //Result: CAPTURED//This test tries to capture an already captured payment.//capturePayment(payment, "9644960021411730"); //Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.}}