Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
6060 rajveer 1
package in.shop2020.serving.services;
2
 
13373 amit.gupta 3
import in.shop2020.model.v1.order.RechargeOrder;
6060 rajveer 4
import in.shop2020.payments.Attribute;
5
import in.shop2020.payments.PaymentStatus;
6
import in.shop2020.thrift.clients.PaymentClient;
7
 
8
import java.util.ArrayList;
9
import java.util.List;
10
 
11
import org.apache.log4j.Logger;
12
 
13
public class PayuPaymentService implements IPaymentService{
14
 
15
	private static Logger log = Logger.getLogger(Class.class);
16
 
17
	public static final String TXN_ID = "transactionId";
18
	public static final String PAYMENT_ID = "paymentId";
19
	public static final String AMOUNT = "amount";
20
	public static final String DATE_TIME = "dateTime";
21
	public static final String MODE = "mode";
22
	public static final String REF_NO = "referenceNo";
23
	public static final String TXN_TYPE = "transactionType";
24
 
13373 amit.gupta 25
    private static int gatewayId=19;
26
 
6060 rajveer 27
	private long paymentId;
28
 
29
	@Override
6390 rajveer 30
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
13391 amit.gupta 31
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through PAYU");
6060 rajveer 32
		CommonPaymentService cps = new CommonPaymentService();
13391 amit.gupta 33
		if(!cps.createPayment(userId, txnId, PayuPaymentService.gatewayId)){
6060 rajveer 34
			log.error("Error while creating the basic payment");
35
			return PAYMENT_NOT_CREATED;
36
		}
37
		paymentId = cps.getPaymentId();
38
 
39
		if(paymentOption != null){
40
			List<Attribute> attributes = new ArrayList<Attribute>();
41
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
42
 
43
			try {
44
				PaymentClient paymentServiceClient = new PaymentClient();
45
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
46
			} catch (Exception e) {
47
				log.error("Error while saving payment option attribute", e);
48
				// TODO: We've already created the payment. We could allow the
49
				// payment to go through. The customer will be a little
50
				// annoyed to have to select from a host of options again but
51
				// will be better than completely disallowing him.
52
				return PAYMENT_NOT_CREATED;
53
			}
54
		}
55
 
56
		return paymentId;
57
	}
13373 amit.gupta 58
 
59
	public long createPayment(RechargeOrder rechargeOrder, String paymentOption) {
60
	    log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through Payu");
61
        CommonPaymentService cps = new CommonPaymentService();
62
        if(!cps.createPayment(rechargeOrder, gatewayId)){
63
            log.error("Error while creating the basic payment");
64
            return PAYMENT_NOT_CREATED;
65
        }
66
        paymentId = cps.getPaymentId();
67
 
68
        if(paymentOption != null){
69
            List<Attribute> attributes = new ArrayList<Attribute>();
70
            attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
71
 
72
            try {
73
                PaymentClient paymentServiceClient = new PaymentClient();
74
                paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
75
            } catch (Exception e) {
76
                log.error("Error while saving payment option attribute", e);
77
                // TODO: We've already created the payment. We could allow the
78
                // payment to go through. The customer will be a little
79
                // annoyed to have to select from a host of options again but
80
                // will be better than completely disallowing him.
81
                return PAYMENT_NOT_CREATED;
82
            }
83
        }
6060 rajveer 84
 
13373 amit.gupta 85
        return paymentId;
86
    }
6060 rajveer 87
 
13373 amit.gupta 88
	public static void main(String[] args){		
6060 rajveer 89
	}
90
}