Subversion Repositories SmartDukaan

Rev

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

Rev 10968 Rev 20112
Line 15... Line 15...
15
	private static final long serialVersionUID = 1L;
15
	private static final long serialVersionUID = 1L;
16
	private static Logger log = Logger.getLogger(Class.class);
16
	private static Logger log = Logger.getLogger(Class.class);
17
	
17
	
18
	private String redirectURL;
18
	private String redirectURL;
19
	private static int gatewayId=1;
19
	private static int gatewayId=1;
20
	
20
	private long paymentId;
21
	public HdfcPaymentService() {
21
	public HdfcPaymentService() {
22
	
22
	
23
	}
23
	}
24
	
24
	
25
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
25
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
26
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC");
26
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through HDFC");
27
		CommonPaymentService cps = new CommonPaymentService();
27
		CommonPaymentService cps = new CommonPaymentService();
28
		if(!cps.createPayment(userId, txnId, gatewayId)){
28
		if(!cps.createPayment(userId, txnId, gatewayId)){
29
			log.error("Error while creating the basic payment");
29
			log.error("Error while creating the basic payment");
30
			return PAYMENT_NOT_CREATED;
30
			return PAYMENT_NOT_CREATED;
31
		}else{
-
 
32
			return initializePayment(cps.getPaymentId(), paymentOption);
-
 
33
		}
31
		}
-
 
32
		paymentId = cps.getPaymentId();
-
 
33
		if(paymentOption != null){
-
 
34
			List<Attribute> attributes = new ArrayList<Attribute>();
-
 
35
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
-
 
36
			
-
 
37
			try {
-
 
38
				PaymentClient paymentServiceClient = new PaymentClient();
-
 
39
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
-
 
40
			} catch (Exception e) {
-
 
41
				log.error("Error while saving payment option attribute", e);
-
 
42
				// TODO: We've already created the payment. We could allow the
-
 
43
				// payment to go through. The customer will be a little
-
 
44
				// annoyed to have to select from a host of options again but
-
 
45
				// will be better than completely disallowing him.
-
 
46
				return PAYMENT_NOT_CREATED;
-
 
47
			}
-
 
48
		}
-
 
49
 
-
 
50
		return paymentId;
34
	}
51
	}
35
	
52
	
36
	public long createPayment(RechargeOrder rechargeOrder, String paymentOption, String phone) {
53
	public long createPayment(RechargeOrder rechargeOrder, String paymentOption, String phone) {
37
	    log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through HDFC");
54
	    log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through HDFC");
38
	    log.info("createPayment phone---- " + phone);
55
	    log.info("createPayment phone---- " + phone);
Line 66... Line 83...
66
            log.error("Error while initializing payment.", e);
83
            log.error("Error while initializing payment.", e);
67
            return PAYMENT_NOT_CREATED;
84
            return PAYMENT_NOT_CREATED;
68
        }
85
        }
69
    }
86
    }
70
 
87
 
71
    private long initializePayment(long merchantPaymentId, String paymentOption){
-
 
72
		List<Attribute> attributes = new ArrayList<Attribute>();
-
 
73
		attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
-
 
74
		PaymentClient paymentServiceClient = null;
-
 
75
		try {
-
 
76
			paymentServiceClient = new PaymentClient();
-
 
77
		} catch (Exception e) {
-
 
78
			log.error("Error while getting payment client", e);
-
 
79
			return PAYMENT_NOT_CREATED;
-
 
80
		}
-
 
81
		
-
 
82
		try {
-
 
83
			paymentServiceClient.getClient().updatePaymentDetails(merchantPaymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
-
 
84
			this.redirectURL = paymentServiceClient.getClient().initializeHdfcPayment(merchantPaymentId, false);
-
 
85
			return merchantPaymentId;
-
 
86
		}catch (Exception e) {
-
 
87
			log.error("Error while initializing payment.", e);
-
 
88
			return PAYMENT_NOT_CREATED;
-
 
89
		}
-
 
90
	}
-
 
91
	
88
 
92
	public String getRedirectUrl(){
89
	public String getRedirectUrl(){
93
		return this.redirectURL;
90
		return this.redirectURL;
94
	}
91
	}
95
	
92
	
96
	public static void main(String args[]){
93
	public static void main(String args[]){