Subversion Repositories SmartDukaan

Rev

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

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