| 1905 |
chandransh |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 4566 |
rajveer |
3 |
import java.math.BigInteger;
|
|
|
4 |
import java.security.MessageDigest;
|
|
|
5 |
import java.security.NoSuchAlgorithmException;
|
| 2577 |
chandransh |
6 |
import java.util.List;
|
|
|
7 |
|
| 1905 |
chandransh |
8 |
import org.apache.log4j.Logger;
|
| 2118 |
chandransh |
9 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
10 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
11 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
12 |
import org.apache.struts2.convention.annotation.Results;
|
| 6050 |
anupam.sin |
13 |
import org.apache.thrift.transport.TTransportException;
|
| 1905 |
chandransh |
14 |
|
| 2118 |
chandransh |
15 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
16 |
|
| 1905 |
chandransh |
17 |
import in.shop2020.config.ConfigException;
|
| 2118 |
chandransh |
18 |
import in.shop2020.model.v1.order.LineItem;
|
| 1905 |
chandransh |
19 |
import in.shop2020.model.v1.order.Order;
|
| 6050 |
anupam.sin |
20 |
import in.shop2020.model.v1.order.RechargeOrder;
|
| 1905 |
chandransh |
21 |
import in.shop2020.model.v1.order.Transaction;
|
| 2159 |
chandransh |
22 |
import in.shop2020.payments.Attribute;
|
| 1905 |
chandransh |
23 |
import in.shop2020.payments.Payment;
|
| 2159 |
chandransh |
24 |
import in.shop2020.serving.services.IPaymentService;
|
| 6050 |
anupam.sin |
25 |
import in.shop2020.test.Address;
|
| 3126 |
rajveer |
26 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
27 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 6050 |
anupam.sin |
28 |
import in.shop2020.thrift.clients.UserClient;
|
| 1905 |
chandransh |
29 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
30 |
|
| 2118 |
chandransh |
31 |
@SuppressWarnings("serial")
|
| 6091 |
anupam.sin |
32 |
|
| 2118 |
chandransh |
33 |
@Results({
|
| 6091 |
anupam.sin |
34 |
@Result(name="recharge-redirect", type="redirectAction",
|
| 10118 |
amit.gupta |
35 |
params = {"actionName" , "recharge"}),
|
|
|
36 |
@Result(name="shipping-redirect", type="redirectAction",
|
|
|
37 |
params = {"actionName" , "shipping"}),
|
|
|
38 |
|
| 2118 |
chandransh |
39 |
})
|
|
|
40 |
public class EbsPayController extends ValidationAwareSupport{
|
| 1905 |
chandransh |
41 |
|
|
|
42 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
43 |
|
|
|
44 |
private static String accountId;
|
|
|
45 |
|
|
|
46 |
private static String returnUrl;
|
|
|
47 |
|
|
|
48 |
private static String mode;
|
|
|
49 |
|
| 4566 |
rajveer |
50 |
private static String ebsSecretKey;
|
|
|
51 |
|
| 6228 |
anupam.sin |
52 |
private String phone;//This is used for recharge orders of value less than 1000.
|
| 6215 |
anupam.sin |
53 |
|
| 1905 |
chandransh |
54 |
static{
|
|
|
55 |
try {
|
|
|
56 |
accountId = ConfigClient.getClient().get("ebs_account_id");
|
|
|
57 |
returnUrl = ConfigClient.getClient().get("ebs_return_url");
|
|
|
58 |
mode = ConfigClient.getClient().get("ebs_pay_mode");
|
| 4566 |
rajveer |
59 |
ebsSecretKey = ConfigClient.getClient().get("ebs_secret_key");
|
| 1905 |
chandransh |
60 |
} catch (ConfigException e) {
|
| 2046 |
chandransh |
61 |
mode = "LIVE";
|
| 1905 |
chandransh |
62 |
log.error("Unable to get EBS payment configuration.");
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
private String id;
|
|
|
67 |
|
| 2577 |
chandransh |
68 |
private String paymentOption = null;
|
| 2159 |
chandransh |
69 |
|
| 2118 |
chandransh |
70 |
private StringBuilder description;
|
|
|
71 |
|
| 1905 |
chandransh |
72 |
private double amount;
|
|
|
73 |
|
|
|
74 |
private ContactDetails billingDetails;
|
|
|
75 |
|
|
|
76 |
public String show(){
|
| 3126 |
rajveer |
77 |
PaymentClient paymentServiceClient = null;
|
| 1905 |
chandransh |
78 |
Payment payment = null;
|
|
|
79 |
try {
|
|
|
80 |
long paymentId = Long.parseLong(this.id);
|
| 3126 |
rajveer |
81 |
paymentServiceClient = new PaymentClient();
|
| 1905 |
chandransh |
82 |
payment = paymentServiceClient.getClient().getPayment(paymentId);
|
|
|
83 |
} catch (Exception e) {
|
| 2118 |
chandransh |
84 |
log.error("Error while getting payment client", e);
|
|
|
85 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
86 |
return "shipping-redirect";
|
| 1905 |
chandransh |
87 |
}
|
|
|
88 |
|
|
|
89 |
Order order = null;
|
|
|
90 |
try {
|
|
|
91 |
long txnId = payment.getMerchantTxnId();
|
| 3126 |
rajveer |
92 |
TransactionClient transactionServiceClient = new TransactionClient();
|
| 1905 |
chandransh |
93 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
94 |
Transaction transaction = txnClient.getTransaction(txnId);
|
|
|
95 |
order = transaction.getOrders().get(0);
|
|
|
96 |
} catch (Exception e) {
|
| 2118 |
chandransh |
97 |
log.error("Error while getting transaction information", e);
|
|
|
98 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
99 |
return "shipping-redirect";
|
| 1905 |
chandransh |
100 |
}
|
|
|
101 |
|
| 2118 |
chandransh |
102 |
setDescription(order);
|
| 2159 |
chandransh |
103 |
setPaymentOption(payment);
|
| 2118 |
chandransh |
104 |
|
| 1905 |
chandransh |
105 |
this.amount = payment.getAmount();
|
|
|
106 |
this.billingDetails = new ContactDetails(order.getCustomer_name(),
|
|
|
107 |
order.getCustomer_email(), order.getCustomer_address1(),
|
|
|
108 |
order.getCustomer_city(), order.getCustomer_state(),
|
|
|
109 |
order.getCustomer_pincode(), "IND",
|
|
|
110 |
order.getCustomer_mobilenumber());
|
|
|
111 |
|
|
|
112 |
log.info(billingDetails);
|
|
|
113 |
|
|
|
114 |
return "show";
|
|
|
115 |
}
|
| 6050 |
anupam.sin |
116 |
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* This method is used for Recharge payments. It is being called by RechargePaymentController.
|
|
|
120 |
* @return
|
|
|
121 |
*/
|
|
|
122 |
public String edit(){
|
|
|
123 |
PaymentClient paymentServiceClient = null;
|
|
|
124 |
Payment payment = null;
|
|
|
125 |
try {
|
|
|
126 |
long paymentId = Long.parseLong(this.id);
|
|
|
127 |
paymentServiceClient = new PaymentClient();
|
|
|
128 |
payment = paymentServiceClient.getClient().getPayment(paymentId);
|
|
|
129 |
} catch (Exception e) {
|
|
|
130 |
log.error("Error while getting payment client", e);
|
|
|
131 |
addActionError("We are experiencing some problems. Please try later.");
|
| 6091 |
anupam.sin |
132 |
return "recharge-redirect";
|
| 6050 |
anupam.sin |
133 |
}
|
|
|
134 |
|
|
|
135 |
RechargeOrder rechargeOrder = null;
|
|
|
136 |
try {
|
|
|
137 |
long txnId = payment.getMerchantTxnId();
|
|
|
138 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
139 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
140 |
rechargeOrder = txnClient.getRechargeOrdersForTransaction(txnId);
|
|
|
141 |
} catch (Exception e) {
|
|
|
142 |
log.error("Error while getting transaction information", e);
|
|
|
143 |
addActionError("We are experiencing some problems. Please try later.");
|
| 6091 |
anupam.sin |
144 |
return "recharge-redirect";
|
| 6050 |
anupam.sin |
145 |
}
|
|
|
146 |
|
|
|
147 |
String desc = "Recharge for Rs. " + rechargeOrder.getTotalAmount() + ", operator : " + rechargeOrder.getOperatorId();
|
|
|
148 |
this.description = new StringBuilder(desc);
|
|
|
149 |
setPaymentOption(payment);
|
|
|
150 |
|
|
|
151 |
this.amount = payment.getAmount();
|
| 6233 |
anupam.sin |
152 |
if(getPhone().isEmpty()) {
|
| 6228 |
anupam.sin |
153 |
UserClient userClient;
|
|
|
154 |
in.shop2020.model.v1.user.Address address = null;
|
|
|
155 |
try {
|
|
|
156 |
userClient = new UserClient();
|
|
|
157 |
long addressId = userClient.getClient().getDefaultAddressId(rechargeOrder.getUserId());
|
|
|
158 |
address = userClient.getClient().getAddressById(addressId);
|
|
|
159 |
this.billingDetails = new ContactDetails(address.getName(),
|
|
|
160 |
rechargeOrder.getUserEmailId(), address.getLine1(),
|
|
|
161 |
address.getCity(), address.getState(),
|
|
|
162 |
address.getPin(), "IND",
|
|
|
163 |
address.getPhone());
|
|
|
164 |
} catch (Exception e) {
|
|
|
165 |
log.error("Unable to get address to put in billing details");
|
|
|
166 |
e.printStackTrace();
|
|
|
167 |
}
|
|
|
168 |
} else {
|
|
|
169 |
this.billingDetails = new ContactDetails(rechargeOrder.getUserEmailId(),
|
|
|
170 |
rechargeOrder.getUserEmailId(), id,
|
|
|
171 |
id, id,
|
|
|
172 |
"110001", "IND",
|
|
|
173 |
getPhone());
|
| 6050 |
anupam.sin |
174 |
}
|
| 6215 |
anupam.sin |
175 |
log.info("Billing details of recharge order " + rechargeOrder.getDisplayId() + " : " + billingDetails);
|
| 6050 |
anupam.sin |
176 |
return "show";
|
|
|
177 |
}
|
| 1905 |
chandransh |
178 |
|
| 2118 |
chandransh |
179 |
public String getDescription(){
|
|
|
180 |
if(this.description.length() >= 255)
|
|
|
181 |
return this.description.substring(0, 255);
|
|
|
182 |
else
|
|
|
183 |
return this.description.toString();
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
private void setDescription(Order order){
|
| 2534 |
chandransh |
187 |
StringBuilder descriptionBuilder = new StringBuilder(255);
|
| 2118 |
chandransh |
188 |
for(LineItem line: order.getLineitems()){
|
|
|
189 |
if(line.getBrand() != null){
|
| 2534 |
chandransh |
190 |
descriptionBuilder.append(line.getBrand() + " ");
|
| 2118 |
chandransh |
191 |
}
|
|
|
192 |
if(line.getModel_name() != null){
|
| 2534 |
chandransh |
193 |
descriptionBuilder.append(line.getModel_name() + " ");
|
| 2118 |
chandransh |
194 |
}
|
|
|
195 |
if(line.getModel_number() != null){
|
| 2534 |
chandransh |
196 |
descriptionBuilder.append(line.getModel_number() + " ");
|
| 2118 |
chandransh |
197 |
}
|
|
|
198 |
if(line.getColor() != null){
|
| 2534 |
chandransh |
199 |
descriptionBuilder.append(line.getColor() + " ");
|
| 2118 |
chandransh |
200 |
}
|
|
|
201 |
}
|
| 2534 |
chandransh |
202 |
String desc = descriptionBuilder.toString();
|
|
|
203 |
desc = desc.replaceAll("[^a-zA-Z0-9\\s\\-\\@\\/\\.]", "");
|
|
|
204 |
this.description = new StringBuilder(desc);
|
| 2118 |
chandransh |
205 |
}
|
|
|
206 |
|
| 1905 |
chandransh |
207 |
public void setId(String id) {
|
|
|
208 |
this.id = id;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public String getId() {
|
|
|
212 |
return id;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public String getAccountId() {
|
|
|
216 |
return accountId;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public static String getReturnUrl() {
|
|
|
220 |
return returnUrl;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
public static String getMode() {
|
|
|
224 |
return mode;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public double getAmount() {
|
|
|
228 |
return amount;
|
|
|
229 |
}
|
| 2159 |
chandransh |
230 |
|
|
|
231 |
public void setPaymentOption(Payment payment) {
|
| 2199 |
chandransh |
232 |
this.paymentOption = null;
|
| 2577 |
chandransh |
233 |
List<Attribute> attributes = payment.getAttributes();
|
|
|
234 |
if(attributes == null)
|
|
|
235 |
return;
|
|
|
236 |
for(Attribute attr : attributes){
|
| 2159 |
chandransh |
237 |
if(attr.getName().equals(IPaymentService.PAYMENT_METHOD))
|
|
|
238 |
this.paymentOption = attr.getValue();
|
|
|
239 |
}
|
|
|
240 |
}
|
| 1905 |
chandransh |
241 |
|
| 2159 |
chandransh |
242 |
public String getPaymentOption(){
|
|
|
243 |
return paymentOption;
|
|
|
244 |
}
|
| 4566 |
rajveer |
245 |
|
|
|
246 |
public String getSecureHash() throws NoSuchAlgorithmException{
|
|
|
247 |
String pass = ebsSecretKey + "|" + accountId + "|" + amount + "|" + id + "|" + returnUrl + "|" + mode;
|
|
|
248 |
MessageDigest m = MessageDigest.getInstance("MD5");
|
|
|
249 |
byte[] data = pass.getBytes();
|
|
|
250 |
m.update(data,0,data.length);
|
|
|
251 |
BigInteger i = new BigInteger(1,m.digest());
|
|
|
252 |
String secureHash = String.format("%1$032X", i);
|
|
|
253 |
return secureHash;
|
|
|
254 |
}
|
| 2159 |
chandransh |
255 |
|
| 1905 |
chandransh |
256 |
public ContactDetails getBillingDetails() {
|
|
|
257 |
return billingDetails;
|
|
|
258 |
}
|
|
|
259 |
|
| 6215 |
anupam.sin |
260 |
public void setPhone(String phone) {
|
|
|
261 |
this.phone = phone;
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
public String getPhone() {
|
|
|
266 |
return phone;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
public static class ContactDetails{
|
| 1905 |
chandransh |
270 |
private String name;
|
|
|
271 |
private String email;
|
|
|
272 |
private String address;
|
|
|
273 |
private String city;
|
|
|
274 |
private String state;
|
|
|
275 |
private String postalCode;
|
|
|
276 |
private String country;
|
|
|
277 |
private String phone;
|
|
|
278 |
|
|
|
279 |
public ContactDetails(String name, String email, String address,
|
|
|
280 |
String city, String state, String postalCode, String country,
|
|
|
281 |
String phone) {
|
|
|
282 |
this.name = name;
|
|
|
283 |
this.email = email;
|
|
|
284 |
this.address = address;
|
|
|
285 |
this.city = city;
|
|
|
286 |
this.state = state;
|
|
|
287 |
this.postalCode = postalCode;
|
|
|
288 |
this.country = country;
|
|
|
289 |
this.phone = phone;
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
@Override
|
|
|
293 |
public String toString() {
|
|
|
294 |
return "ContactDetails [name=" + name + ", email=" + email
|
|
|
295 |
+ ", address=" + address + ", city=" + city + ", state="
|
|
|
296 |
+ state + ", postalCode=" + postalCode + ", country="
|
|
|
297 |
+ country + ", phone=" + phone + "]";
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
public String getName() {
|
|
|
301 |
return name;
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
public String getEmail() {
|
|
|
305 |
return email;
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
public String getAddress() {
|
|
|
309 |
return address;
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
public String getCity() {
|
|
|
313 |
return city;
|
|
|
314 |
}
|
|
|
315 |
|
|
|
316 |
public String getState() {
|
|
|
317 |
return state;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
public String getPostalCode() {
|
|
|
321 |
return postalCode;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
public String getCountry() {
|
|
|
325 |
return country;
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
public String getPhone() {
|
|
|
329 |
return phone;
|
|
|
330 |
}
|
|
|
331 |
}
|
| 6903 |
anupam.sin |
332 |
|
|
|
333 |
public static void main(String[] args) {
|
|
|
334 |
{
|
|
|
335 |
String encrypted = "2be98afc86aa7f2e4cb79ac798cc2fd8a";
|
|
|
336 |
BigInteger bi_r0 = new BigInteger("0933910847463829827159347601486730416058");
|
|
|
337 |
/*String password = "shop2020";
|
|
|
338 |
|
|
|
339 |
BigInteger bi_passwd = new BigInteger(password.getBytes());
|
|
|
340 |
System.out.println(bi_passwd);
|
|
|
341 |
|
|
|
342 |
|
|
|
343 |
BigInteger bi_r1 = bi_r0.xor(bi_passwd);
|
|
|
344 |
System.out.println(bi_r1);
|
|
|
345 |
System.out.println((bi_r1.toString(16)));
|
|
|
346 |
*/
|
|
|
347 |
try
|
|
|
348 |
{
|
|
|
349 |
BigInteger bi_enc = new BigInteger(encrypted, 16);
|
|
|
350 |
System.out.println(bi_enc);
|
|
|
351 |
BigInteger bi_result = bi_enc.xor(bi_r0);
|
|
|
352 |
System.out.println(bi_result);
|
|
|
353 |
String str = new String(bi_result.toByteArray());
|
|
|
354 |
System.out.println(str);
|
|
|
355 |
} catch (Exception e) {
|
|
|
356 |
System.out.println("oops");
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
}
|
| 1905 |
chandransh |
360 |
}
|