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