| Line 18... |
Line 18... |
| 18 |
import in.shop2020.payments.PaymentGateway;
|
18 |
import in.shop2020.payments.PaymentGateway;
|
| 19 |
import in.shop2020.payments.PaymentService.Iface;
|
19 |
import in.shop2020.payments.PaymentService.Iface;
|
| 20 |
import in.shop2020.payments.PaymentStatus;
|
20 |
import in.shop2020.payments.PaymentStatus;
|
| 21 |
|
21 |
|
| 22 |
public class PaymentServiceHandler implements Iface {
|
22 |
public class PaymentServiceHandler implements Iface {
|
| - |
|
23 |
public static final long PAYMENT_NOT_CREATED = -1;
|
| - |
|
24 |
private static final String FLAG_KEY = "IsFlagged";
|
| - |
|
25 |
private static final String TXN_KEY = "TransactionID";
|
| - |
|
26 |
private static final String AUTH_TXN_ID = "AuthTxnId";
|
| - |
|
27 |
private static final String CAPTURE_TXN_ID = "CaptureTxnId";
|
| - |
|
28 |
private static final String CAPTURE_TIME = "CaptureTime";
|
| 23 |
|
29 |
|
| 24 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
30 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
| 25 |
PaymentHandler paymentHandler = (PaymentHandler) context.getBean("paymentHandler");
|
31 |
PaymentHandler paymentHandler = (PaymentHandler) context.getBean("paymentHandler");
|
| 26 |
PaymentGatewayHandler paymentGatewayHandler = (PaymentGatewayHandler) context.getBean("paymentGatewayHandler");
|
32 |
PaymentGatewayHandler paymentGatewayHandler = (PaymentGatewayHandler) context.getBean("paymentGatewayHandler");
|
| 27 |
|
33 |
|
| 28 |
@Override
|
34 |
@Override
|
| Line 127... |
Line 133... |
| 127 |
for(in.shop2020.payment.domain.Payment payment : daoPayments){
|
133 |
for(in.shop2020.payment.domain.Payment payment : daoPayments){
|
| 128 |
payments.add(payment.getThriftPayment());
|
134 |
payments.add(payment.getThriftPayment());
|
| 129 |
}
|
135 |
}
|
| 130 |
return payments;
|
136 |
return payments;
|
| 131 |
}
|
137 |
}
|
| - |
|
138 |
|
| - |
|
139 |
@Override
|
| - |
|
140 |
public Payment updateAndCaptureEbsPayment(Map<String, String> paymentParams) throws PaymentException, TException {
|
| - |
|
141 |
long merchantPaymentId = Long.parseLong(paymentParams.get("MerchantRefNo"));
|
| - |
|
142 |
String gatewayPaymentId = paymentParams.get("PaymentID");
|
| - |
|
143 |
double amount = Double.parseDouble(paymentParams.get("Amount"));
|
| - |
|
144 |
String isFlagged = paymentParams.get(FLAG_KEY);
|
| - |
|
145 |
String gatewayTxnStatus = paymentParams.get("ResponseCode");
|
| - |
|
146 |
String description = paymentParams.get("ResponseMessage");
|
| - |
|
147 |
String authTxnId = paymentParams.get(TXN_KEY);
|
| - |
|
148 |
|
| - |
|
149 |
|
| - |
|
150 |
List<Attribute> attributes = new ArrayList<Attribute>();
|
| - |
|
151 |
attributes.add(new Attribute(FLAG_KEY, isFlagged));
|
| - |
|
152 |
attributes.add(new Attribute(AUTH_TXN_ID, authTxnId));
|
| - |
|
153 |
|
| - |
|
154 |
Payment payment = null;
|
| - |
|
155 |
try {
|
| - |
|
156 |
payment = getPayment(merchantPaymentId);
|
| - |
|
157 |
} catch (PaymentException e1) {
|
| - |
|
158 |
throw new PaymentException(e1);
|
| - |
|
159 |
}
|
| - |
|
160 |
|
| - |
|
161 |
if(!validatePaymentParams(amount, payment)){
|
| - |
|
162 |
throw new PaymentException(102, "Checks and balance failed on returned data");
|
| - |
|
163 |
}
|
| - |
|
164 |
|
| - |
|
165 |
if(gatewayTxnStatus.equals("0")){
|
| - |
|
166 |
//Update payment status as authorized
|
| - |
|
167 |
updatePaymentDetails(merchantPaymentId, gatewayPaymentId, "", gatewayTxnStatus, description, "", "", "", "", PaymentStatus.AUTHORIZED, "", attributes);
|
| - |
|
168 |
|
| - |
|
169 |
Map<String, String> captureResult = EbsPaymentHandler.capturePayment(amount, "" + gatewayPaymentId);
|
| - |
|
170 |
|
| - |
|
171 |
String captureStatus = captureResult.get(EbsPaymentHandler.STATUS);
|
| - |
|
172 |
|
| - |
|
173 |
if("".equals(captureStatus)){
|
| - |
|
174 |
//Failure
|
| - |
|
175 |
description = captureResult.get(EbsPaymentHandler.ERROR);
|
| - |
|
176 |
String errorCode = captureResult.get(EbsPaymentHandler.ERR_CODE);
|
| - |
|
177 |
|
| - |
|
178 |
updatePaymentDetails(merchantPaymentId, gatewayPaymentId, "", gatewayTxnStatus, description, "", "", "", errorCode, PaymentStatus.FAILED, "", attributes);
|
| - |
|
179 |
}else{
|
| - |
|
180 |
//Success
|
| - |
|
181 |
attributes.add(new Attribute(CAPTURE_TXN_ID, captureResult.get(EbsPaymentHandler.TXN_ID)));
|
| - |
|
182 |
attributes.add(new Attribute(CAPTURE_TIME, captureResult.get(EbsPaymentHandler.DATE_TIME)));
|
| - |
|
183 |
|
| - |
|
184 |
updatePaymentDetails(merchantPaymentId, gatewayPaymentId, "", captureStatus, description, "", "", "", "", PaymentStatus.SUCCESS, "", attributes);
|
| - |
|
185 |
}
|
| - |
|
186 |
|
| - |
|
187 |
|
| - |
|
188 |
}else{
|
| - |
|
189 |
updatePaymentDetails(merchantPaymentId, gatewayPaymentId, "", gatewayTxnStatus, description, "", "", "", "", PaymentStatus.FAILED, "", attributes);
|
| - |
|
190 |
}
|
| - |
|
191 |
|
| - |
|
192 |
payment = getPayment(merchantPaymentId);
|
| - |
|
193 |
|
| - |
|
194 |
return payment;
|
| - |
|
195 |
}
|
| - |
|
196 |
|
| - |
|
197 |
@Override
|
| - |
|
198 |
public String initializeHdfcPayment(long merchantPaymentId) throws PaymentException, TException {
|
| - |
|
199 |
in.shop2020.payment.domain.Payment payment = paymentHandler.getPayment(merchantPaymentId);
|
| - |
|
200 |
String redirectURL;
|
| - |
|
201 |
try {
|
| - |
|
202 |
redirectURL = HdfcPaymentHandler.initializeHdfcPayment(payment, this);
|
| - |
|
203 |
} catch (Exception e) {
|
| - |
|
204 |
throw new PaymentException(102, "Error while initiliazing payment. Check service log for more details.");
|
| - |
|
205 |
}
|
| - |
|
206 |
return redirectURL;
|
| - |
|
207 |
}
|
| - |
|
208 |
|
| - |
|
209 |
@Override
|
| - |
|
210 |
public Map<String, String> captureHdfcPayment(long merchantPaymentId){
|
| - |
|
211 |
in.shop2020.payment.domain.Payment payment = paymentHandler.getPayment(merchantPaymentId);
|
| - |
|
212 |
return HdfcPaymentHandler.capturePayment(payment);
|
| - |
|
213 |
}
|
| - |
|
214 |
|
| - |
|
215 |
private boolean validatePaymentParams(double amount, Payment payment){
|
| - |
|
216 |
if(payment==null || payment.getAmount()!= amount){
|
| - |
|
217 |
// We did not request this payment or the authorised amount is different.
|
| - |
|
218 |
return false;
|
| - |
|
219 |
}
|
| - |
|
220 |
return true;
|
| - |
|
221 |
}
|
| 132 |
}
|
222 |
}
|