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
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
27
	public long createPayment(long userId, long txnId, String paymentOption, int gatewayId){
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));
8942 rajveer 39
			double emiAmount = CommonPaymentService.calculateEmiAmount(paymentOption, cps.getAmount());
40
	        if(emiAmount > 0){
41
	        	attributes.add(new Attribute(IPaymentService.EMI_AMOUNT, ""+emiAmount));
42
	        }			
6390 rajveer 43
			try {
44
				PaymentClient paymentServiceClient = new PaymentClient();
45
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
46
			} catch (Exception e) {
47
				log.error("Error while saving payment option attribute", e);
48
				// TODO: We've already created the payment. We could allow the
49
				// payment to go through. The customer will be a little
50
				// annoyed to have to select from a host of options again but
51
				// will be better than completely disallowing him.
52
				return PAYMENT_NOT_CREATED;
53
			}
54
		}
55
 
56
		return paymentId;
57
	}
58
 
59
	public static void main(String[] args){
60
		//capturePayment(30450.00, "2412653");
61
 
62
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
63
 
64
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
65
//		<output  errorCode="12"  error="This payment is failed"  />
66
//		<output  errorCode="13"  error="This payment is captured already"  />		
67
	}
68
}