Subversion Repositories SmartDukaan

Rev

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