Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8842 anupam.sin 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.model.v1.order.RechargeOrder;
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 EbsPaymentService 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
 
25
    private static int gatewayId=2;
26
	private long paymentId;
27
 
28
	@Override
29
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
30
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through EBS");
31
		CommonPaymentService cps = new CommonPaymentService();
32
		if(!cps.createPayment(userId, txnId, gatewayId)){
33
			log.error("Error while creating the basic payment");
34
			return PAYMENT_NOT_CREATED;
35
		}
36
		paymentId = cps.getPaymentId();
37
 
38
		if(paymentOption != null){
39
			List<Attribute> attributes = new ArrayList<Attribute>();
40
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
41
 
42
			try {
43
				PaymentClient paymentServiceClient = new PaymentClient();
44
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
45
			} catch (Exception e) {
46
				log.error("Error while saving payment option attribute", e);
47
				// TODO: We've already created the payment. We could allow the
48
				// payment to go through. The customer will be a little
49
				// annoyed to have to select from a host of options again but
50
				// will be better than completely disallowing him.
51
				return PAYMENT_NOT_CREATED;
52
			}
53
		}
54
 
55
		return paymentId;
56
	}
57
 
58
	public long createPayment(RechargeOrder rechargeOrder, String paymentOption) {
59
	    log.info("Creating payment for the txn#: " + rechargeOrder.getId() + " for the user: " + rechargeOrder.getUserId() + " for processing through EBS");
60
        CommonPaymentService cps = new CommonPaymentService();
61
        if(!cps.createPayment(rechargeOrder, gatewayId)){
62
            log.error("Error while creating the basic payment");
63
            return PAYMENT_NOT_CREATED;
64
        }
65
        paymentId = cps.getPaymentId();
66
 
67
        if(paymentOption != null){
68
            List<Attribute> attributes = new ArrayList<Attribute>();
69
            attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
70
 
71
            try {
72
                PaymentClient paymentServiceClient = new PaymentClient();
73
                paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
74
            } catch (Exception e) {
75
                log.error("Error while saving payment option attribute", e);
76
                // TODO: We've already created the payment. We could allow the
77
                // payment to go through. The customer will be a little
78
                // annoyed to have to select from a host of options again but
79
                // will be better than completely disallowing him.
80
                return PAYMENT_NOT_CREATED;
81
            }
82
        }
83
 
84
        return paymentId;
85
    }
86
 
87
	public static void main(String[] args){
88
		//capturePayment(30450.00, "2412653");
89
 
90
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
91
 
92
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
93
//		<output  errorCode="12"  error="This payment is failed"  />
94
//		<output  errorCode="13"  error="This payment is captured already"  />		
95
	}
96
}