Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
9269 amit.gupta 1
package in.shop2020.mobileapi.serving.services;
9103 anupam.sin 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
20278 aman.kumar 29
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId, String paymentType){
9103 anupam.sin 30
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through EBS");
31
		CommonPaymentService cps = new CommonPaymentService();
13286 amit.gupta 32
		if(!cps.createPayment(userId, txnId, EbsPaymentService.gatewayId)){
9103 anupam.sin 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));
20278 aman.kumar 41
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentType));
9103 anupam.sin 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
 
20278 aman.kumar 58
	public long createPayment(RechargeOrder rechargeOrder, String paymentOption, String paymentType) {
9103 anupam.sin 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));
20278 aman.kumar 70
            attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));
9103 anupam.sin 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
        }
84
 
85
        return paymentId;
86
    }
87
 
88
	public static void main(String[] args){
89
		//capturePayment(30450.00, "2412653");
90
 
91
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
92
 
93
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
94
//		<output  errorCode="12"  error="This payment is failed"  />
95
//		<output  errorCode="13"  error="This payment is captured already"  />		
96
	}
97
}