Subversion Repositories SmartDukaan

Rev

Rev 2046 | Rev 2145 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2046 Rev 2118
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import org.apache.log4j.Logger;
3
import org.apache.log4j.Logger;
-
 
4
import org.apache.struts2.convention.annotation.InterceptorRef;
-
 
5
import org.apache.struts2.convention.annotation.InterceptorRefs;
-
 
6
import org.apache.struts2.convention.annotation.Result;
-
 
7
import org.apache.struts2.convention.annotation.Results;
-
 
8
 
-
 
9
import com.opensymphony.xwork2.ValidationAwareSupport;
4
 
10
 
5
import in.shop2020.config.ConfigException;
11
import in.shop2020.config.ConfigException;
-
 
12
import in.shop2020.model.v1.order.LineItem;
6
import in.shop2020.model.v1.order.Order;
13
import in.shop2020.model.v1.order.Order;
7
import in.shop2020.model.v1.order.Transaction;
14
import in.shop2020.model.v1.order.Transaction;
8
import in.shop2020.payments.Payment;
15
import in.shop2020.payments.Payment;
9
import in.shop2020.thrift.clients.PaymentServiceClient;
16
import in.shop2020.thrift.clients.PaymentServiceClient;
10
import in.shop2020.thrift.clients.TransactionServiceClient;
17
import in.shop2020.thrift.clients.TransactionServiceClient;
11
import in.shop2020.thrift.clients.config.ConfigClient;
18
import in.shop2020.thrift.clients.config.ConfigClient;
12
 
19
 
-
 
20
@SuppressWarnings("serial")
-
 
21
@InterceptorRefs({
-
 
22
    @InterceptorRef("myDefault"),
-
 
23
    @InterceptorRef("login")
-
 
24
})
-
 
25
@Results({
-
 
26
	@Result(name="shipping-redirect", type="redirectAction", 
-
 
27
    		params = {"actionName" , "shipping"})
-
 
28
})
13
public class EbsPayController {
29
public class EbsPayController extends ValidationAwareSupport{
14
 
30
 
15
	private static Logger log = Logger.getLogger(Class.class);
31
	private static Logger log = Logger.getLogger(Class.class);
16
	
32
	
17
	private static String accountId;
33
	private static String accountId;
18
	
34
	
Line 31... Line 47...
31
		}
47
		}
32
	}
48
	}
33
	
49
	
34
	private String id;
50
	private String id;
35
	
51
	
-
 
52
	private StringBuilder description;
-
 
53
	
36
	private double amount;
54
	private double amount;
37
	
55
	
38
	private ContactDetails billingDetails;
56
	private ContactDetails billingDetails;
39
	
57
	
40
	public String show(){
58
	public String show(){
Line 43... Line 61...
43
		try {
61
		try {
44
			long paymentId = Long.parseLong(this.id);
62
			long paymentId = Long.parseLong(this.id);
45
			paymentServiceClient = new PaymentServiceClient();
63
			paymentServiceClient = new PaymentServiceClient();
46
			payment = paymentServiceClient.getClient().getPayment(paymentId);
64
			payment = paymentServiceClient.getClient().getPayment(paymentId);
47
		} catch (Exception e) {
65
		} catch (Exception e) {
48
			log.error("Error while getting payment client");
66
			log.error("Error while getting payment client", e);
49
			e.printStackTrace();
67
			addActionError("We are experiencing some problems. Please try later.");
50
			return "fail";
68
			return "shipping-redirect";
51
		}
69
		}
52
		
70
		
53
		Order order = null;
71
		Order order = null;
-
 
72
		LineItem lineItem = null;
54
		try {
73
		try {
55
			long txnId = payment.getMerchantTxnId();
74
			long txnId = payment.getMerchantTxnId();
56
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
75
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
57
			in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
76
			in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
58
			Transaction transaction = txnClient.getTransaction(txnId);
77
			Transaction transaction = txnClient.getTransaction(txnId);
59
			order = transaction.getOrders().get(0);
78
			order = transaction.getOrders().get(0);
-
 
79
			lineItem = order.getLineitems().get(0);
60
		} catch (Exception e) {
80
		} catch (Exception e) {
61
			e.printStackTrace();
81
			log.error("Error while getting transaction information", e);
-
 
82
			addActionError("We are experiencing some problems. Please try later.");
62
			return "fail";
83
			return "shipping-redirect";
63
		}
84
		}
64
		
85
		
-
 
86
		setDescription(order);
-
 
87
		
65
		this.amount = payment.getAmount();
88
		this.amount = payment.getAmount();
66
		this.billingDetails = new ContactDetails(order.getCustomer_name(),
89
		this.billingDetails = new ContactDetails(order.getCustomer_name(),
67
				order.getCustomer_email(), order.getCustomer_address1(),
90
				order.getCustomer_email(), order.getCustomer_address1(),
68
				order.getCustomer_city(), order.getCustomer_state(),
91
				order.getCustomer_city(), order.getCustomer_state(),
69
				order.getCustomer_pincode(), "IND",
92
				order.getCustomer_pincode(), "IND",
Line 72... Line 95...
72
		log.info(billingDetails);
95
		log.info(billingDetails);
73
		
96
		
74
		return "show";
97
		return "show";
75
	}
98
	}
76
 
99
 
-
 
100
	public String getDescription(){
-
 
101
		if(this.description.length() >= 255)
-
 
102
			return this.description.substring(0, 255);
-
 
103
		else
-
 
104
			return this.description.toString();
-
 
105
	}
-
 
106
	
-
 
107
	private void setDescription(Order order){
-
 
108
		this.description = new StringBuilder(255);
-
 
109
		for(LineItem line: order.getLineitems()){
-
 
110
			if(line.getBrand() != null){
-
 
111
				description.append(line.getBrand() + " ");
-
 
112
			}
-
 
113
			if(line.getModel_name() != null){
-
 
114
				description.append(line.getModel_name() + " "); 
-
 
115
			}
-
 
116
			if(line.getModel_number() != null){
-
 
117
				description.append(line.getModel_number() + " ");
-
 
118
			}
-
 
119
			if(line.getColor() != null){
-
 
120
				description.append(line.getColor() + " ");
-
 
121
			}
-
 
122
		}
-
 
123
	}
-
 
124
	
77
	public void setId(String id) {
125
	public void setId(String id) {
78
		this.id = id;
126
		this.id = id;
79
	}
127
	}
80
 
128
 
81
	public String getId() {
129
	public String getId() {