| 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.HashMap;
|
| 5 |
import java.util.List;
|
- |
|
| 6 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 7 |
|
6 |
|
| 8 |
import org.apache.logging.log4j.Logger;
|
7 |
import org.apache.logging.log4j.Logger;
|
| 9 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 10 |
import org.springframework.beans.factory.annotation.Value;
|
9 |
import org.springframework.beans.factory.annotation.Value;
|
| 11 |
import org.springframework.stereotype.Component;
|
10 |
import org.springframework.stereotype.Component;
|
| 12 |
|
11 |
|
| 13 |
import com.spice.profitmandi.thrift.clients.PaymentClient;
|
- |
|
| 14 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
- |
|
| 15 |
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
|
- |
|
| 16 |
import com.spice.profitmandi.web.res.order.PayuPayPojo;
|
12 |
import com.spice.profitmandi.web.res.order.PayuPayPojo;
|
| 17 |
|
13 |
|
| 18 |
import in.shop2020.config.ConfigException;
|
- |
|
| 19 |
import in.shop2020.model.v1.order.LineItem;
|
- |
|
| 20 |
import in.shop2020.model.v1.order.Order;
|
- |
|
| 21 |
import in.shop2020.model.v1.order.Transaction;
|
- |
|
| 22 |
import in.shop2020.payments.Attribute;
|
- |
|
| 23 |
import in.shop2020.payments.Payment;
|
- |
|
| 24 |
|
14 |
|
| 25 |
|
15 |
|
| 26 |
@Component
|
16 |
@Component
|
| 27 |
public class PayuHandler {
|
17 |
public class PayuHandler {
|
| 28 |
|
18 |
|
| Line 89... |
Line 79... |
| 89 |
/**
|
79 |
/**
|
| 90 |
* This method is used for Recharge payments. It is being called by RechargePaymentController.
|
80 |
* This method is used for Recharge payments. It is being called by RechargePaymentController.
|
| 91 |
* @return
|
81 |
* @return
|
| 92 |
*/
|
82 |
*/
|
| 93 |
|
83 |
|
| 94 |
private String getDescription (Order order){
|
- |
|
| 95 |
StringBuilder descriptionBuilder = new StringBuilder(255);
|
- |
|
| 96 |
for(LineItem line: order.getLineitems()){
|
- |
|
| 97 |
if(line.getBrand() != null){
|
- |
|
| 98 |
descriptionBuilder.append(line.getBrand() + " ");
|
- |
|
| 99 |
}
|
- |
|
| 100 |
if(line.getModel_name() != null){
|
- |
|
| 101 |
descriptionBuilder.append(line.getModel_name() + " ");
|
- |
|
| 102 |
}
|
- |
|
| 103 |
if(line.getModel_number() != null){
|
- |
|
| 104 |
descriptionBuilder.append(line.getModel_number() + " ");
|
- |
|
| 105 |
}
|
- |
|
| 106 |
if(line.getColor() != null){
|
- |
|
| 107 |
descriptionBuilder.append(line.getColor() + " ");
|
- |
|
| 108 |
}
|
- |
|
| 109 |
}
|
- |
|
| 110 |
String desc = descriptionBuilder.toString();
|
- |
|
| 111 |
desc.replaceAll("[^a-zA-Z0-9\\s\\-\\@\\/\\.]", "");
|
- |
|
| 112 |
descriptionBuilder = new StringBuilder(desc);
|
- |
|
| 113 |
if(descriptionBuilder.length() >= 255)
|
- |
|
| 114 |
return descriptionBuilder.substring(0, 255).trim();
|
- |
|
| 115 |
else
|
- |
|
| 116 |
return descriptionBuilder.toString().trim();
|
- |
|
| 117 |
}
|
- |
|
| 118 |
|
- |
|
| 119 |
/*private String getPaymentOption(Payment payment) {
|
84 |
/*private String getPaymentOption(Payment payment) {
|
| 120 |
String paymentType = null;
|
85 |
String paymentType = null;
|
| 121 |
String paymentOpt = null;
|
86 |
String paymentOpt = null;
|
| 122 |
List<Attribute> attributes = payment.getAttributes();
|
87 |
List<Attribute> attributes = payment.getAttributes();
|
| 123 |
if(attributes == null)
|
88 |
if(attributes == null)
|
| Line 145... |
Line 110... |
| 145 |
}
|
110 |
}
|
| 146 |
return sb.toString();
|
111 |
return sb.toString();
|
| 147 |
}
|
112 |
}
|
| 148 |
|
113 |
|
| 149 |
|
114 |
|
| 150 |
public boolean validatePaymentParams(double returnedAmount, Payment payment, String hash, Map<String, String> paymentParams) {
|
- |
|
| 151 |
if (!(payment != null && Math.abs(payment.getAmount() - returnedAmount) <= 0.50
|
- |
|
| 152 |
&& hash.equals(getSecureHash(paymentParams)))) {
|
- |
|
| 153 |
// We did not request this payment or the authorised amount is
|
- |
|
| 154 |
// different.
|
- |
|
| 155 |
log.error("Checks and balance failed on returned data");
|
- |
|
| 156 |
return false;
|
- |
|
| 157 |
}
|
- |
|
| 158 |
return true;
|
- |
|
| 159 |
}
|
- |
|
| 160 |
|
- |
|
| 161 |
public String getSecureHash(Map<String, String> paymentParams){
|
115 |
public String getSecureHash(Map<String, String> paymentParams){
|
| 162 |
try{
|
116 |
try{
|
| 163 |
String pass = salt + "|" + paymentParams.get("status") + "|||||||||||" + paymentParams.get("email") + "|" + paymentParams.get("firstname") + "|" + paymentParams.get("productinfo") + "|" + paymentParams.get("amount") + "|" + paymentParams.get("txnid") + "|" + accountId;
|
117 |
String pass = salt + "|" + paymentParams.get("status") + "|||||||||||" + paymentParams.get("email") + "|" + paymentParams.get("firstname") + "|" + paymentParams.get("productinfo") + "|" + paymentParams.get("amount") + "|" + paymentParams.get("txnid") + "|" + accountId;
|
| 164 |
System.out.println(pass);
|
118 |
System.out.println(pass);
|
| 165 |
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
119 |
MessageDigest md = MessageDigest.getInstance("SHA-512");
|