Subversion Repositories SmartDukaan

Rev

Rev 8942 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6390 rajveer 1
package in.shop2020.serving.services;
2
 
3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.PaymentStatus;
5
import in.shop2020.thrift.clients.PaymentClient;
6
 
7
import java.util.ArrayList;
8
import java.util.List;
9
 
10
import org.apache.log4j.Logger;
11
 
12
public class InnovitiPaymentService implements IPaymentService{
13
 
14
	private static Logger log = Logger.getLogger(Class.class);
15
 
16
	public static final String TXN_ID = "transactionId";
17
	public static final String PAYMENT_ID = "paymentId";
18
	public static final String AMOUNT = "amount";
19
	public static final String DATE_TIME = "dateTime";
20
	public static final String MODE = "mode";
21
	public static final String REF_NO = "referenceNo";
22
	public static final String TXN_TYPE = "transactionType";
23
 
24
	private long paymentId;
25
 
26
	@Override
20278 aman.kumar 27
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId, String paymentType){
6390 rajveer 28
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through Innoviti");
29
		CommonPaymentService cps = new CommonPaymentService();
30
		if(!cps.createPayment(userId, txnId, gatewayId)){
31
			log.error("Error while creating the basic payment");
32
			return PAYMENT_NOT_CREATED;
33
		}
34
		paymentId = cps.getPaymentId();
35
 
36
		if(paymentOption != null){
37
			List<Attribute> attributes = new ArrayList<Attribute>();
38
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
20278 aman.kumar 39
			attributes.add(new Attribute(IPaymentService.PAYMENT_TYPE, paymentType));
8942 rajveer 40
			double emiAmount = CommonPaymentService.calculateEmiAmount(paymentOption, cps.getAmount());
41
	        if(emiAmount > 0){
42
	        	attributes.add(new Attribute(IPaymentService.EMI_AMOUNT, ""+emiAmount));
43
	        }			
6390 rajveer 44
			try {
45
				PaymentClient paymentServiceClient = new PaymentClient();
46
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
47
			} catch (Exception e) {
48
				log.error("Error while saving payment option attribute", e);
49
				// TODO: We've already created the payment. We could allow the
50
				// payment to go through. The customer will be a little
51
				// annoyed to have to select from a host of options again but
52
				// will be better than completely disallowing him.
53
				return PAYMENT_NOT_CREATED;
54
			}
55
		}
56
 
57
		return paymentId;
58
	}
59
 
60
	public static void main(String[] args){
61
		//capturePayment(30450.00, "2412653");
62
 
63
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
64
 
65
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
66
//		<output  errorCode="12"  error="This payment is failed"  />
67
//		<output  errorCode="13"  error="This payment is captured already"  />		
68
	}
69
}