| 6390 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
import java.security.MessageDigest;
|
|
|
3 |
import java.security.NoSuchAlgorithmException;
|
|
|
4 |
import java.util.List;
|
| 6442 |
rajveer |
5 |
import java.util.Map;
|
| 6390 |
rajveer |
6 |
|
|
|
7 |
import org.apache.log4j.Logger;
|
|
|
8 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
9 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
10 |
|
|
|
11 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
12 |
|
|
|
13 |
import in.shop2020.config.ConfigException;
|
|
|
14 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
15 |
import in.shop2020.model.v1.order.Order;
|
|
|
16 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
17 |
import in.shop2020.payments.Attribute;
|
|
|
18 |
import in.shop2020.payments.Payment;
|
|
|
19 |
import in.shop2020.serving.services.IPaymentService;
|
|
|
20 |
import in.shop2020.thrift.clients.PaymentClient;
|
|
|
21 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
22 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
|
|
23 |
|
|
|
24 |
@SuppressWarnings("serial")
|
| 6808 |
rajveer |
25 |
|
| 6390 |
rajveer |
26 |
@Results({
|
|
|
27 |
@Result(name="shipping-redirect", type="redirectAction",
|
|
|
28 |
params = {"actionName" , "shipping"})
|
|
|
29 |
})
|
|
|
30 |
public class InnovitiPayController extends ValidationAwareSupport{
|
|
|
31 |
|
|
|
32 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
33 |
|
|
|
34 |
private static String accountId;
|
|
|
35 |
|
| 6806 |
rajveer |
36 |
private static String returnUrl;
|
| 6390 |
rajveer |
37 |
|
|
|
38 |
private static String salt;
|
|
|
39 |
|
| 6806 |
rajveer |
40 |
private static String gatewayUrl;
|
|
|
41 |
|
|
|
42 |
private static String subAccountId;
|
|
|
43 |
|
| 6390 |
rajveer |
44 |
static{
|
|
|
45 |
try {
|
|
|
46 |
accountId = ConfigClient.getClient().get("innoviti_account_id");
|
|
|
47 |
returnUrl = ConfigClient.getClient().get("innoviti_return_url");
|
|
|
48 |
salt = ConfigClient.getClient().get("innoviti_secret_key");
|
| 6806 |
rajveer |
49 |
subAccountId = ConfigClient.getClient().get("innoviti_sub_account_id");
|
| 6810 |
rajveer |
50 |
gatewayUrl = ConfigClient.getClient().get("innoviti_gateway_url");
|
| 6390 |
rajveer |
51 |
} catch (ConfigException e) {
|
|
|
52 |
log.error("Unable to get Innoviti payment configuration.");
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
private String id;
|
|
|
57 |
|
|
|
58 |
private String paymentOption = null;
|
|
|
59 |
|
|
|
60 |
private StringBuilder description;
|
|
|
61 |
|
|
|
62 |
private double amount;
|
|
|
63 |
|
| 6442 |
rajveer |
64 |
private double emiAmount = 0;
|
|
|
65 |
|
| 6390 |
rajveer |
66 |
private ContactDetails billingDetails;
|
|
|
67 |
|
|
|
68 |
public String show(){
|
|
|
69 |
PaymentClient paymentServiceClient = null;
|
|
|
70 |
Payment payment = null;
|
|
|
71 |
try {
|
|
|
72 |
long paymentId = Long.parseLong(this.id);
|
|
|
73 |
paymentServiceClient = new PaymentClient();
|
|
|
74 |
payment = paymentServiceClient.getClient().getPayment(paymentId);
|
|
|
75 |
} catch (Exception e) {
|
|
|
76 |
log.error("Error while getting payment client", e);
|
|
|
77 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
78 |
return "shipping-redirect";
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
Order order = null;
|
|
|
82 |
try {
|
|
|
83 |
long txnId = payment.getMerchantTxnId();
|
|
|
84 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
85 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = transactionServiceClient.getClient();
|
|
|
86 |
Transaction transaction = txnClient.getTransaction(txnId);
|
|
|
87 |
order = transaction.getOrders().get(0);
|
| 8942 |
rajveer |
88 |
// Map<Long, Double> miscCharges = txnClient.getMiscCharges(txnId);
|
|
|
89 |
// System.out.println(miscCharges);
|
|
|
90 |
// if(miscCharges != null & !miscCharges.isEmpty()){
|
|
|
91 |
// emiAmount = miscCharges.get(1L);
|
|
|
92 |
// }
|
| 6390 |
rajveer |
93 |
} catch (Exception e) {
|
|
|
94 |
log.error("Error while getting transaction information", e);
|
|
|
95 |
addActionError("We are experiencing some problems. Please try later.");
|
|
|
96 |
return "shipping-redirect";
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
setDescription(order);
|
|
|
100 |
setPaymentOption(payment);
|
|
|
101 |
|
|
|
102 |
this.amount = payment.getAmount();
|
| 7078 |
rajveer |
103 |
this.billingDetails = new ContactDetails(order.getCustomer_name().trim(),
|
|
|
104 |
order.getCustomer_email().trim(), order.getCustomer_address1(), order.getCustomer_address2(),
|
| 6390 |
rajveer |
105 |
order.getCustomer_city(), order.getCustomer_state(),
|
|
|
106 |
order.getCustomer_pincode(), "India",
|
| 7078 |
rajveer |
107 |
order.getCustomer_mobilenumber().trim());
|
| 6390 |
rajveer |
108 |
|
|
|
109 |
log.info(billingDetails);
|
|
|
110 |
|
|
|
111 |
return "show";
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public String getDescription(){
|
|
|
115 |
if(this.description.length() >= 255)
|
|
|
116 |
return this.description.substring(0, 255).trim();
|
|
|
117 |
else
|
|
|
118 |
return this.description.toString().trim();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
private void setDescription(Order order){
|
|
|
122 |
StringBuilder descriptionBuilder = new StringBuilder(255);
|
|
|
123 |
for(LineItem line: order.getLineitems()){
|
|
|
124 |
if(line.getBrand() != null){
|
|
|
125 |
descriptionBuilder.append(line.getBrand() + " ");
|
|
|
126 |
}
|
|
|
127 |
if(line.getModel_name() != null){
|
|
|
128 |
descriptionBuilder.append(line.getModel_name() + " ");
|
|
|
129 |
}
|
|
|
130 |
if(line.getModel_number() != null){
|
|
|
131 |
descriptionBuilder.append(line.getModel_number() + " ");
|
|
|
132 |
}
|
|
|
133 |
if(line.getColor() != null){
|
|
|
134 |
descriptionBuilder.append(line.getColor() + " ");
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
String desc = descriptionBuilder.toString();
|
|
|
138 |
desc = desc.replaceAll("[^a-zA-Z0-9\\s\\-\\@\\/\\.]", "");
|
|
|
139 |
this.description = new StringBuilder(desc);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
public void setId(String id) {
|
|
|
143 |
this.id = id;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
public String getId() {
|
|
|
147 |
return id;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public String getAccountId() {
|
|
|
151 |
return accountId;
|
|
|
152 |
}
|
|
|
153 |
|
| 6806 |
rajveer |
154 |
public String getSubAccountId() {
|
|
|
155 |
return subAccountId;
|
|
|
156 |
}
|
|
|
157 |
|
| 6390 |
rajveer |
158 |
public static String getReturnUrl() {
|
|
|
159 |
return returnUrl;
|
|
|
160 |
}
|
|
|
161 |
|
| 6806 |
rajveer |
162 |
public String getGatewayUrl(){
|
|
|
163 |
return gatewayUrl;
|
|
|
164 |
}
|
|
|
165 |
|
| 6390 |
rajveer |
166 |
public double getAmount() {
|
|
|
167 |
return amount;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public void setPaymentOption(Payment payment) {
|
|
|
171 |
this.paymentOption = null;
|
|
|
172 |
List<Attribute> attributes = payment.getAttributes();
|
|
|
173 |
if(attributes == null)
|
|
|
174 |
return;
|
|
|
175 |
for(Attribute attr : attributes){
|
|
|
176 |
if(attr.getName().equals(IPaymentService.PAYMENT_METHOD))
|
|
|
177 |
this.paymentOption = attr.getValue();
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
public String getPaymentOption(){
|
|
|
183 |
return paymentOption;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public String getProcessingCode(){
|
| 6442 |
rajveer |
187 |
return paymentOption;
|
| 6390 |
rajveer |
188 |
}
|
|
|
189 |
|
| 6442 |
rajveer |
190 |
public String isCtx(){
|
|
|
191 |
return "YES";
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public double getCtxProcessingFee(){
|
|
|
195 |
return emiAmount;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
public double getCtxInterest(){
|
|
|
199 |
return ProceedToPayController.getInterestRate(Long.parseLong(paymentOption));
|
|
|
200 |
}
|
|
|
201 |
|
| 6390 |
rajveer |
202 |
public String getSecureHash() throws NoSuchAlgorithmException{
|
|
|
203 |
// MD5(orderId "|" merchantId "|" subMerchantId "|" amt "|" cur "|" proSku "|" Cname "|" mobile "|" emailId "|" redirUrl "|" 123^~abc%) (Salt Value Decide by Merchant and uniPAY-Net))
|
| 6806 |
rajveer |
204 |
String pass = id + "|" + accountId + "|" + subAccountId + "|" + amount + "|" + "INR" + "|" + getDescription() + "|" + billingDetails.getName() + "|" + billingDetails.getPhone() + "|" + billingDetails.getEmail() + "|" + returnUrl + "|" + salt;
|
| 6390 |
rajveer |
205 |
System.out.println(pass);
|
|
|
206 |
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
207 |
md.update(pass.getBytes(), 0, pass.getBytes().length);
|
|
|
208 |
byte[] mdbytes = md.digest();
|
|
|
209 |
// convert the byte to hex format method
|
|
|
210 |
StringBuffer sb = new StringBuffer();
|
|
|
211 |
for (int i = 0; i < mdbytes.length; i++) {
|
|
|
212 |
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
|
|
|
213 |
}
|
|
|
214 |
return sb.toString();
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
public ContactDetails getBillingDetails() {
|
|
|
218 |
return billingDetails;
|
|
|
219 |
}
|
|
|
220 |
|
| 6806 |
rajveer |
221 |
|
| 6390 |
rajveer |
222 |
public static void main(String[] args) throws NoSuchAlgorithmException {
|
| 6432 |
rajveer |
223 |
//String pass = "410|1234567800|uniPAY|5985|INR|||||RedirectUrl|123^~abc%)";
|
|
|
224 |
//String pass = "113724|544433321212272|3001|3586|INR|Micromax Smarty A25 Black|Rajveer|1111111111|rajveer.singh@shop2020.in|http://www.shop2020.in/innoviti-pay-response|123^~uni%";
|
|
|
225 |
String pass = "113734|544433321212272|3001|3586|INR|Micromax Smarty A25 Black|Rajveer|1111111111|rajveer.singh@shop2020.in|http://www.shop2020.in/innoviti-pay-response|123^~uni%";
|
|
|
226 |
//5fc923e520bce47ff14b3aa1a5245287
|
|
|
227 |
//5fc923e520bce47ff14b3aa1a5245287
|
|
|
228 |
//15d4dbc305d0b56ce1973726bdee526d
|
|
|
229 |
//db4d6309123fd1543882eba3123f52b4
|
|
|
230 |
//93d97a5f16fb132c8728ee799e81915e
|
|
|
231 |
//bf29c85dcd387c1160fe64a2af8b0463
|
|
|
232 |
|
|
|
233 |
|
| 6390 |
rajveer |
234 |
System.out.println(pass);
|
|
|
235 |
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
236 |
md.update(pass.getBytes(), 0, pass.getBytes().length);
|
|
|
237 |
byte[] mdbytes = md.digest();
|
|
|
238 |
// convert the byte to hex format method
|
|
|
239 |
StringBuffer sb = new StringBuffer();
|
|
|
240 |
for (int i = 0; i < mdbytes.length; i++) {
|
|
|
241 |
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
|
|
|
242 |
}
|
|
|
243 |
System.out.println(sb.toString());
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
public static class ContactDetails{
|
|
|
247 |
private String name;
|
|
|
248 |
private String email;
|
|
|
249 |
private String address1;
|
|
|
250 |
private String address2;
|
|
|
251 |
private String city;
|
|
|
252 |
private String state;
|
|
|
253 |
private String postalCode;
|
|
|
254 |
private String country;
|
|
|
255 |
private String phone;
|
|
|
256 |
|
|
|
257 |
public ContactDetails(String name, String email, String address1, String address2,
|
|
|
258 |
String city, String state, String postalCode, String country,
|
|
|
259 |
String phone) {
|
|
|
260 |
this.name = name;
|
|
|
261 |
this.email = email;
|
|
|
262 |
this.address1 = address1;
|
|
|
263 |
this.address2 = address2;
|
|
|
264 |
this.city = city;
|
|
|
265 |
this.state = state;
|
|
|
266 |
this.postalCode = postalCode;
|
|
|
267 |
this.country = country;
|
|
|
268 |
this.phone = phone;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
@Override
|
|
|
272 |
public String toString() {
|
|
|
273 |
return "ContactDetails [name=" + name + ", email=" + email
|
|
|
274 |
+ ", address1=" + address1 + ", address2=" + address2 + ",city=" + city + ", state="
|
|
|
275 |
+ state + ", postalCode=" + postalCode + ", country="
|
|
|
276 |
+ country + ", phone=" + phone + "]";
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
public String getName() {
|
|
|
280 |
return name;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
public String getEmail() {
|
|
|
284 |
return email;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
public String getAddress1() {
|
|
|
288 |
return address1;
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
public String getAddress2() {
|
|
|
292 |
return address2;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
public String getCity() {
|
|
|
296 |
return city;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
public String getState() {
|
|
|
300 |
return state;
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
public String getPostalCode() {
|
|
|
304 |
return postalCode;
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
public String getCountry() {
|
|
|
308 |
return country;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
public String getPhone() {
|
|
|
312 |
return phone;
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
}
|