| 1905 |
chandransh |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
|
|
3 |
import org.apache.log4j.Logger;
|
| 2118 |
chandransh |
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;
|
| 1905 |
chandransh |
8 |
|
| 2118 |
chandransh |
9 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
10 |
|
| 1905 |
chandransh |
11 |
import in.shop2020.config.ConfigException;
|
| 2118 |
chandransh |
12 |
import in.shop2020.model.v1.order.LineItem;
|
| 1905 |
chandransh |
13 |
import in.shop2020.model.v1.order.Order;
|
|
|
14 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
15 |
import in.shop2020.payments.Payment;
|
|
|
16 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
|
|
17 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
|
|
18 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
19 |
|
| 2118 |
chandransh |
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 |
})
|
|
|
29 |
public class EbsPayController extends ValidationAwareSupport{
|
| 1905 |
chandransh |
30 |
|
|
|
31 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
32 |
|
|
|
33 |
private static String accountId;
|
|
|
34 |
|
|
|
35 |
private static String returnUrl;
|
|
|
36 |
|
|
|
37 |
private static String mode;
|
|
|
38 |
|
|
|
39 |
static{
|
|
|
40 |
try {
|
|
|
41 |
accountId = ConfigClient.getClient().get("ebs_account_id");
|
|
|
42 |
returnUrl = ConfigClient.getClient().get("ebs_return_url");
|
|
|
43 |
mode = ConfigClient.getClient().get("ebs_pay_mode");
|
|
|
44 |
} catch (ConfigException e) {
|
| 2046 |
chandransh |
45 |
mode = "LIVE";
|
| 1905 |
chandransh |
46 |
log.error("Unable to get EBS payment configuration.");
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
private String id;
|
|
|
51 |
|
| 2118 |
chandransh |
52 |
private StringBuilder description;
|
|
|
53 |
|
| 1905 |
chandransh |
54 |
private double amount;
|
|
|
55 |
|
|
|
56 |
private ContactDetails billingDetails;
|
|
|
57 |
|
|
|
58 |
public String show(){
|
|
|
59 |
PaymentServiceClient paymentServiceClient = null;
|
|
|
60 |
Payment payment = null;
|
|
|
61 |
try {
|
|
|
62 |
long paymentId = Long.parseLong(this.id);
|
|
|
63 |
paymentServiceClient = new PaymentServiceClient();
|
|
|
64 |
payment = paymentServiceClient.getClient().getPayment(paymentId);
|
|
|
65 |
} catch (Exception e) {
|
| 2118 |
chandransh |
66 |
log.error("Error while getting payment client", e);
|
|
|
67 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
68 |
return "shipping-redirect";
|
| 1905 |
chandransh |
69 |
}
|
|
|
70 |
|
|
|
71 |
Order order = null;
|
| 2118 |
chandransh |
72 |
LineItem lineItem = null;
|
| 1905 |
chandransh |
73 |
try {
|
|
|
74 |
long txnId = payment.getMerchantTxnId();
|
|
|
75 |
TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
|
|
|
76 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
77 |
Transaction transaction = txnClient.getTransaction(txnId);
|
|
|
78 |
order = transaction.getOrders().get(0);
|
| 2118 |
chandransh |
79 |
lineItem = order.getLineitems().get(0);
|
| 1905 |
chandransh |
80 |
} catch (Exception e) {
|
| 2118 |
chandransh |
81 |
log.error("Error while getting transaction information", e);
|
|
|
82 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
83 |
return "shipping-redirect";
|
| 1905 |
chandransh |
84 |
}
|
|
|
85 |
|
| 2118 |
chandransh |
86 |
setDescription(order);
|
|
|
87 |
|
| 1905 |
chandransh |
88 |
this.amount = payment.getAmount();
|
|
|
89 |
this.billingDetails = new ContactDetails(order.getCustomer_name(),
|
|
|
90 |
order.getCustomer_email(), order.getCustomer_address1(),
|
|
|
91 |
order.getCustomer_city(), order.getCustomer_state(),
|
|
|
92 |
order.getCustomer_pincode(), "IND",
|
|
|
93 |
order.getCustomer_mobilenumber());
|
|
|
94 |
|
|
|
95 |
log.info(billingDetails);
|
|
|
96 |
|
|
|
97 |
return "show";
|
|
|
98 |
}
|
|
|
99 |
|
| 2118 |
chandransh |
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 |
|
| 1905 |
chandransh |
125 |
public void setId(String id) {
|
|
|
126 |
this.id = id;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
public String getId() {
|
|
|
130 |
return id;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
public String getAccountId() {
|
|
|
134 |
return accountId;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public static String getReturnUrl() {
|
|
|
138 |
return returnUrl;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
public static String getMode() {
|
|
|
142 |
return mode;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public double getAmount() {
|
|
|
146 |
return amount;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
public ContactDetails getBillingDetails() {
|
|
|
150 |
return billingDetails;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
public static class ContactDetails{
|
|
|
154 |
private String name;
|
|
|
155 |
private String email;
|
|
|
156 |
private String address;
|
|
|
157 |
private String city;
|
|
|
158 |
private String state;
|
|
|
159 |
private String postalCode;
|
|
|
160 |
private String country;
|
|
|
161 |
private String phone;
|
|
|
162 |
|
|
|
163 |
public ContactDetails(String name, String email, String address,
|
|
|
164 |
String city, String state, String postalCode, String country,
|
|
|
165 |
String phone) {
|
|
|
166 |
this.name = name;
|
|
|
167 |
this.email = email;
|
|
|
168 |
this.address = address;
|
|
|
169 |
this.city = city;
|
|
|
170 |
this.state = state;
|
|
|
171 |
this.postalCode = postalCode;
|
|
|
172 |
this.country = country;
|
|
|
173 |
this.phone = phone;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
@Override
|
|
|
177 |
public String toString() {
|
|
|
178 |
return "ContactDetails [name=" + name + ", email=" + email
|
|
|
179 |
+ ", address=" + address + ", city=" + city + ", state="
|
|
|
180 |
+ state + ", postalCode=" + postalCode + ", country="
|
|
|
181 |
+ country + ", phone=" + phone + "]";
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
public String getName() {
|
|
|
185 |
return name;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
public String getEmail() {
|
|
|
189 |
return email;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
public String getAddress() {
|
|
|
193 |
return address;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public String getCity() {
|
|
|
197 |
return city;
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public String getState() {
|
|
|
201 |
return state;
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
public String getPostalCode() {
|
|
|
205 |
return postalCode;
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
public String getCountry() {
|
|
|
209 |
return country;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
public String getPhone() {
|
|
|
213 |
return phone;
|
|
|
214 |
}
|
|
|
215 |
}
|
|
|
216 |
}
|