Subversion Repositories SmartDukaan

Rev

Rev 3561 | Rev 6050 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 rajveer 1
package in.shop2020.serving.services;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.apache.log4j.Logger;
7
 
8
import in.shop2020.payments.Attribute;
2334 chandransh 9
import in.shop2020.payments.Payment;
1318 rajveer 10
import in.shop2020.payments.PaymentStatus;
3126 rajveer 11
import in.shop2020.thrift.clients.PaymentClient;
1318 rajveer 12
 
1905 chandransh 13
public class HdfcPaymentService implements IPaymentService {
1318 rajveer 14
	private static final long serialVersionUID = 1L;
15
	private static Logger log = Logger.getLogger(Class.class);
16
 
17
	private String redirectURL;
2758 chandransh 18
	private static int gatewayId=1;
1318 rajveer 19
 
20
	public HdfcPaymentService() {
21
 
22
	}
23
 
3561 rajveer 24
	public long createPayment(long currentCartId, long userId, long txnId, String paymentOption, long sourceId){
2199 chandransh 25
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC");
1905 chandransh 26
		CommonPaymentService cps = new CommonPaymentService();
3561 rajveer 27
		if(!cps.createPayment(currentCartId, userId, txnId, gatewayId, sourceId)){
1905 chandransh 28
			log.error("Error while creating the basic payment");
29
			return PAYMENT_NOT_CREATED;
2758 chandransh 30
		}else{
31
			return initializePayment(cps.getPaymentId(), paymentOption);
1318 rajveer 32
		}
2758 chandransh 33
	}
34
 
35
	private long initializePayment(long merchantPaymentId, String paymentOption){
36
		List<Attribute> attributes = new ArrayList<Attribute>();
37
		attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
3126 rajveer 38
		PaymentClient paymentServiceClient = null;
1905 chandransh 39
		try {
3126 rajveer 40
			paymentServiceClient = new PaymentClient();
1905 chandransh 41
		} catch (Exception e) {
2758 chandransh 42
			log.error("Error while getting payment client", e);
1905 chandransh 43
			return PAYMENT_NOT_CREATED;
44
		}
1318 rajveer 45
 
46
		try {
2758 chandransh 47
			paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
48
			this.redirectURL = paymentServiceClient.getClient().initializeHdfcPayment(merchantPaymentId);
49
			return merchantPaymentId;
1318 rajveer 50
		}catch (Exception e) {
2334 chandransh 51
			log.error("Error while initializing payment.", e);
2758 chandransh 52
			return PAYMENT_NOT_CREATED;
1318 rajveer 53
		}
54
	}
55
 
56
	public String getRedirectUrl(){
57
		return this.redirectURL;
58
	}
2334 chandransh 59
 
60
	public static void main(String args[]){
61
		Payment payment = new Payment();
62
		payment.setPaymentId(216);
63
		payment.setAmount(40000);
64
		payment.setGatewayPaymentId("TESTSTSTS");
65
 
3010 chandransh 66
        // The underlying method calls are no longer valid since all the
67
        // information required to capture a payment is read from the database
68
        // itself and can't be specified through the call.
69
 
2334 chandransh 70
		//This test checks what happens when the txn id is left blank
3010 chandransh 71
		//capturePayment(payment, "");					//Result: !ERROR!-GW00205-Invalid Subsequent Transaction.
2334 chandransh 72
 
73
		//This test checks what happends with an invalid txn id 
3010 chandransh 74
		//capturePayment(payment, "6022630101411740"); 	//Result: !ERROR!-GW00201-Transaction not found.
2334 chandransh 75
 
76
		//The next three tests require a valid AUTH transaction id.
77
		//This test checks what happens when we attempt to capture an amount greater than what was authorized.
3010 chandransh 78
		//capturePayment(payment, "9644960021411730");	//Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
2334 chandransh 79
 
80
		//This test checks what happens when we attempt to capture a valid transaction with the right amount. This transaction should be CAPTURED.
3010 chandransh 81
		//payment.setAmount(21698);
82
		//capturePayment(payment, "9644960021411730");	//Result: CAPTURED
2334 chandransh 83
 
84
		//This test tries to capture an already captured payment.
3010 chandransh 85
		//capturePayment(payment, "9644960021411730");	//Result: !ERROR!-GW00177-Failed Capture Greater Than Auth check.
2334 chandransh 86
	}
1318 rajveer 87
}
88