Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
6060 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 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 static int gatewayId=7;
25
	private long paymentId;
26
 
27
	@Override
28
	public long createPayment(long currentCartId, long userId, long txnId, String paymentOption, long sourceId){
29
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through EBS");
30
		CommonPaymentService cps = new CommonPaymentService();
31
		if(!cps.createPayment(currentCartId, userId, txnId, gatewayId, sourceId)){
32
			log.error("Error while creating the basic payment");
33
			return PAYMENT_NOT_CREATED;
34
		}
35
		paymentId = cps.getPaymentId();
36
 
37
		if(paymentOption != null){
38
			List<Attribute> attributes = new ArrayList<Attribute>();
39
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
40
 
41
			try {
42
				PaymentClient paymentServiceClient = new PaymentClient();
43
				paymentServiceClient.getClient().updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.INIT, null, attributes);
44
			} catch (Exception e) {
45
				log.error("Error while saving payment option attribute", e);
46
				// TODO: We've already created the payment. We could allow the
47
				// payment to go through. The customer will be a little
48
				// annoyed to have to select from a host of options again but
49
				// will be better than completely disallowing him.
50
				return PAYMENT_NOT_CREATED;
51
			}
52
		}
53
 
54
		return paymentId;
55
	}
56
 
57
	public static void main(String[] args){
58
		//capturePayment(30450.00, "2412653");
59
 
60
//		<output  transactionId="4793507"  paymentId="2411078"  amount="25005"  dateTime="2011-05-16 09:03:15"  mode="TEST"  referenceNo="4"  transactionType="Captured"  status="Processing"  />";
61
 
62
//		<output  errorCode="2"  error="Invalid Account ID/Secret Key"  />
63
//		<output  errorCode="12"  error="This payment is failed"  />
64
//		<output  errorCode="13"  error="This payment is captured already"  />		
65
	}
66
}