Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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