Subversion Repositories SmartDukaan

Rev

Rev 3561 | Rev 6050 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1905 chandransh 1
package in.shop2020.serving.services;
2
 
2159 chandransh 3
import in.shop2020.payments.Attribute;
4
import in.shop2020.payments.PaymentStatus;
3126 rajveer 5
import in.shop2020.thrift.clients.PaymentClient;
1905 chandransh 6
 
2159 chandransh 7
import java.util.ArrayList;
8
import java.util.List;
1905 chandransh 9
 
10
import org.apache.log4j.Logger;
11
 
12
public class EbsPaymentService 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
 
2907 rajveer 24
    private static int gatewayId=2;
1905 chandransh 25
	private long paymentId;
26
 
1959 chandransh 27
	@Override
3561 rajveer 28
	public long createPayment(long currentCartId, long userId, long txnId, String paymentOption, long sourceId){
2199 chandransh 29
		log.info("Creating payment for the txn#: " + txnId + " for the user: " + userId + " for processing through EBS");
1905 chandransh 30
		CommonPaymentService cps = new CommonPaymentService();
3561 rajveer 31
		if(!cps.createPayment(currentCartId, userId, txnId, gatewayId, sourceId)){
1905 chandransh 32
			log.error("Error while creating the basic payment");
33
			return PAYMENT_NOT_CREATED;
34
		}
2159 chandransh 35
		paymentId = cps.getPaymentId();
1905 chandransh 36
 
2199 chandransh 37
		if(paymentOption != null){
38
			List<Attribute> attributes = new ArrayList<Attribute>();
39
			attributes.add(new Attribute(IPaymentService.PAYMENT_METHOD, paymentOption));
40
 
41
			try {
3126 rajveer 42
				PaymentClient paymentServiceClient = new PaymentClient();
2199 chandransh 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
			}
2159 chandransh 52
		}
53
 
1905 chandransh 54
		return paymentId;
55
	}
1959 chandransh 56
 
1905 chandransh 57
	public static void main(String[] args){
2708 chandransh 58
		//capturePayment(30450.00, "2412653");
1905 chandransh 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
}