Subversion Repositories SmartDukaan

Rev

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

Rev 21452 Rev 21469
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller.checkout;
1
package com.spice.profitmandi.web.controller.checkout;
2
import java.security.MessageDigest;
2
import java.security.MessageDigest;
3
import java.security.NoSuchAlgorithmException;
3
import java.security.NoSuchAlgorithmException;
-
 
4
import java.util.HashMap;
4
import java.util.List;
5
import java.util.List;
-
 
6
import java.util.Map;
5
 
7
 
6
import org.slf4j.Logger;
8
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
9
import org.slf4j.LoggerFactory;
8
import org.springframework.stereotype.Component;
10
import org.springframework.stereotype.Component;
9
 
11
 
Line 27... Line 29...
27
 
29
 
28
	private static final Logger log = LoggerFactory.getLogger(PayuHandler.class);
30
	private static final Logger log = LoggerFactory.getLogger(PayuHandler.class);
29
	
31
	
30
	private static String accountId;
32
	private static String accountId;
31
	
33
	
32
	private static String returnUrl = "/payu-pay-response";
34
	private static String returnUrl = "http://bigustav.com/checkout/payu-pay-response";
33
 
35
 
34
	private static String cancelUrl = "/pay-options";
36
	private static String cancelUrl = "http://bigustav.com/checkout/payu-pay-cancelled";
35
 
37
 
36
	
38
	
37
	public static String successUrl;
-
 
38
	public static String errorUrl;	
-
 
39
	
39
	
40
	private static String salt;
40
	private static String salt;
41
	
41
	
42
	private static String postActionUrl;
42
	private static String postActionUrl;
43
	
43
	
44
	static{
44
	static{
45
		try {
45
		try {
46
			ConfigClient client = ConfigClient.getClient();
46
			ConfigClient client = ConfigClient.getClient();
47
			accountId = client.get("payu_account_id");
47
			accountId = client.get("payu_account_id");
48
			salt = client.get("payu_secret_key");
48
			salt = client.get("payu_secret_key");
49
			returnUrl = client.get("payu_return_url");
-
 
50
			cancelUrl = client.get("pay_options_url");
-
 
51
			postActionUrl = client.get("payu_post_url");
49
			postActionUrl = client.get("payu_post_url");
52
			successUrl = client.get("payu_success_url");
-
 
53
			errorUrl = client.get("payu_error_url");
-
 
54
			//"https://test.payu.in/_payment";
50
			//"https://test.payu.in/_payment";
55
		} catch (ConfigException e) {
51
		} catch (ConfigException e) {
56
			log.error("Unable to get PayU payment configuration.");
52
			log.error("Unable to get PayU payment configuration.");
57
		}
53
		}
58
	}
54
	}
Line 128... Line 124...
128
			return descriptionBuilder.substring(0, 255).trim();
124
			return descriptionBuilder.substring(0, 255).trim();
129
		else
125
		else
130
			return descriptionBuilder.toString().trim();
126
			return descriptionBuilder.toString().trim();
131
	}
127
	}
132
 
128
 
133
	public String getAccountId() {
-
 
134
		return accountId;
-
 
135
	}
-
 
136
 
-
 
137
	public static String getReturnUrl() {
-
 
138
		return returnUrl;
-
 
139
	}
-
 
140
 
-
 
141
	private String getPaymentOption(Payment payment) {
129
	private String getPaymentOption(Payment payment) {
142
		String paymentType = null;
130
		String paymentType = null;
143
		String paymentOpt = null;
131
		String paymentOpt = null;
144
		List<Attribute> attributes = payment.getAttributes();
132
		List<Attribute> attributes = payment.getAttributes();
145
		if(attributes == null)
133
		if(attributes == null)
Line 165... Line 153...
165
		for (int i = 0; i < mdbytes.length; i++) {
153
		for (int i = 0; i < mdbytes.length; i++) {
166
			sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
154
			sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
167
		}
155
		}
168
		return sb.toString();
156
		return sb.toString();
169
	}
157
	}
-
 
158
	
-
 
159
 
-
 
160
	public boolean validatePaymentParams(double returnedAmount, Payment payment, String hash, Map<String, String> paymentParams) {
-
 
161
		if (!(payment != null && Math.abs(payment.getAmount() - returnedAmount) <= 0.50
-
 
162
				&& hash.equals(getSecureHash(paymentParams)))) {
-
 
163
			// We did not request this payment or the authorised amount is
-
 
164
			// different.
-
 
165
			log.error("Checks and balance failed on returned data");
-
 
166
			return false;
-
 
167
		}
-
 
168
		return true;
-
 
169
	}
-
 
170
	
-
 
171
	public String getSecureHash(Map<String, String>  paymentParams){
-
 
172
		try{
-
 
173
			String pass = salt + "|" + paymentParams.get("status") + "|||||||||||" + paymentParams.get("email") + "|" +  paymentParams.get("firstname") + "|" + paymentParams.get("productinfo") + "|" + paymentParams.get("amount") + "|" + paymentParams.get("txnid") + "|" + accountId;
-
 
174
			System.out.println(pass);
-
 
175
			MessageDigest md = MessageDigest.getInstance("SHA-512");
-
 
176
			md.update(pass.getBytes(), 0, pass.getBytes().length);
-
 
177
			byte[] mdbytes = md.digest();
-
 
178
			//	convert the byte to hex format method
-
 
179
			StringBuffer sb = new StringBuffer();
-
 
180
			for (int i = 0; i < mdbytes.length; i++) {
-
 
181
				sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
-
 
182
			}
-
 
183
			return sb.toString();
-
 
184
		}catch(NoSuchAlgorithmException nsae){
-
 
185
			log.error("No such algorithm exception");
-
 
186
			return null;
-
 
187
		}
-
 
188
	}
-
 
189
 
-
 
190
	public Map<String, String> getPaymentParams(Map<String, String[]> map) {
-
 
191
		Map<String, String> paymentParams = new HashMap<>();
-
 
192
		for (Object key : map.keySet()) {
-
 
193
			String keyStr = (String) key;
-
 
194
			String[] vals = (String[]) map.get(keyStr);
-
 
195
			String value = vals[0];
-
 
196
			System.out.println("Key " + (String) key + "     :    " + value);
-
 
197
			paymentParams.put(keyStr, value);
-
 
198
		}
-
 
199
		return paymentParams;
-
 
200
	}
170
 
201
 
171
	public static class ContactDetails{
202
	public static class ContactDetails{
172
		private String name;
203
		private String name;
173
		private String email;
204
		private String email;
174
		private String address;
205
		private String address;