Subversion Repositories SmartDukaan

Rev

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

Rev 3375 Rev 3578
Line 1... Line 1...
1
package in.shop2020.payment.service.handler;
1
package in.shop2020.payment.service.handler;
2
 
2
 
-
 
3
import in.shop2020.crm.CRMService.Client;
-
 
4
import in.shop2020.payment.domain.Refund;
-
 
5
import in.shop2020.payment.handler.PaymentGatewayHandler;
-
 
6
import in.shop2020.payment.handler.PaymentHandler;
-
 
7
import in.shop2020.payment.handler.RefundHandler;
-
 
8
import in.shop2020.payments.Attribute;
-
 
9
import in.shop2020.payments.Payment;
-
 
10
import in.shop2020.payments.PaymentException;
-
 
11
import in.shop2020.payments.PaymentGateway;
-
 
12
import in.shop2020.payments.PaymentService.Iface;
-
 
13
import in.shop2020.payments.PaymentStatus;
-
 
14
import in.shop2020.thrift.clients.CRMClient;
-
 
15
 
3
import java.text.SimpleDateFormat;
16
import java.text.SimpleDateFormat;
4
import java.util.ArrayList;
17
import java.util.ArrayList;
5
import java.util.Date;
18
import java.util.Date;
6
import java.util.HashMap;
19
import java.util.HashMap;
7
import java.util.List;
20
import java.util.List;
8
import java.util.Map;
21
import java.util.Map;
9
 
22
 
10
import org.apache.thrift.TException;
23
import org.apache.thrift.TException;
-
 
24
import org.apache.thrift.transport.TTransportException;
11
import org.slf4j.Logger;
25
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
26
import org.slf4j.LoggerFactory;
13
import org.springframework.context.ApplicationContext;
27
import org.springframework.context.ApplicationContext;
14
import org.springframework.context.support.ClassPathXmlApplicationContext;
28
import org.springframework.context.support.ClassPathXmlApplicationContext;
15
 
29
 
16
import in.shop2020.payment.domain.Refund;
-
 
17
import in.shop2020.payment.handler.PaymentGatewayHandler;
-
 
18
import in.shop2020.payment.handler.PaymentHandler;
-
 
19
import in.shop2020.payment.handler.RefundHandler;
-
 
20
import in.shop2020.payments.Attribute;
-
 
21
import in.shop2020.payments.Payment;
-
 
22
import in.shop2020.payments.PaymentException;
-
 
23
import in.shop2020.payments.PaymentGateway;
-
 
24
import in.shop2020.payments.PaymentService.Iface;
-
 
25
import in.shop2020.payments.PaymentStatus;
-
 
26
 
-
 
27
public class PaymentServiceHandler implements Iface {
30
public class PaymentServiceHandler implements Iface {
28
    
31
    
29
    private static Logger logger = LoggerFactory.getLogger(PaymentServiceHandler.class);
32
    private static Logger logger = LoggerFactory.getLogger(PaymentServiceHandler.class);
30
    
33
    
31
    /**
34
    /**
Line 137... Line 140...
137
		payment.setErrorCode(errorCode);
140
		payment.setErrorCode(errorCode);
138
		if(status!=null){
141
		if(status!=null){
139
			payment.setStatus(status.getValue());
142
			payment.setStatus(status.getValue());
140
			if(status.equals(PaymentStatus.SUCCESS))
143
			if(status.equals(PaymentStatus.SUCCESS))
141
				payment.setSuccessTimestamp(new Date());
144
				payment.setSuccessTimestamp(new Date());
142
			else if(status.equals(PaymentStatus.FAILED))
145
			else if(status.equals(PaymentStatus.FAILED)) {
143
				payment.setErrorTimestamp(new Date());
146
			    payment.setErrorTimestamp(new Date());
-
 
147
			    createTicketForFailedPayment(payment);
-
 
148
			}
144
		}
149
		}
145
		
150
		
146
		payment.setGatewayTxnDate(gatewayTxnDate);
151
		payment.setGatewayTxnDate(gatewayTxnDate);
147
		
152
		
148
		Map<String, String> attrMap = new HashMap<String, String>();
153
		Map<String, String> attrMap = new HashMap<String, String>();
Line 154... Line 159...
154
		
159
		
155
		paymentHandler.updatePayment(payment, attrMap);
160
		paymentHandler.updatePayment(payment, attrMap);
156
		return true;
161
		return true;
157
	}
162
	}
158
 
163
 
-
 
164
	// Creates tickets for payment failures in CRM
-
 
165
	private void createTicketForFailedPayment(in.shop2020.payment.domain.Payment payment) {
-
 
166
        try {
-
 
167
            Client crmClient = new CRMClient().getClient();
-
 
168
            crmClient.processPaymentFailure(payment.getUserId());
-
 
169
        } catch (TTransportException e) {
-
 
170
            logger.error("Could not create CRM client", e);
-
 
171
        } catch (TException e) {
-
 
172
            logger.error("Could not process paymentId: " + payment.getId(), e);
-
 
173
        }
-
 
174
    }
-
 
175
 
159
	@Override
176
    @Override
160
	public List<Double> getSuccessfulPaymentsAmountRange() throws TException {
177
	public List<Double> getSuccessfulPaymentsAmountRange() throws TException {
161
	    logger.info("Getting the range of successful payments.");
178
	    logger.info("Getting the range of successful payments.");
162
		List<Double> minMaxAmounts = new ArrayList<Double>();
179
		List<Double> minMaxAmounts = new ArrayList<Double>();
163
		Map<String, Float> minMax = paymentHandler.getMinMaxPaymentAmount();
180
		Map<String, Float> minMax = paymentHandler.getMinMaxPaymentAmount();
164
		minMaxAmounts.add(Double.parseDouble(Float.toString(minMax.get("MIN"))));
181
		minMaxAmounts.add(Double.parseDouble(Float.toString(minMax.get("MIN"))));
Line 280... Line 297...
280
            payment.setDescription(description);
297
            payment.setDescription(description);
281
            payment.setErrorCode(errorCode);
298
            payment.setErrorCode(errorCode);
282
            payment.setStatus(PaymentStatus.FAILED.getValue());
299
            payment.setStatus(PaymentStatus.FAILED.getValue());
283
            payment.setErrorTimestamp(new Date());
300
            payment.setErrorTimestamp(new Date());
284
            paymentHandler.updatePayment(payment, attrMap);
301
            paymentHandler.updatePayment(payment, attrMap);
-
 
302
            createTicketForFailedPayment(payment);
285
            return false;
303
            return false;
286
        } else {
304
        } else {
287
            // Success
305
            // Success
288
            logger.error("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
306
            logger.error("Capture attempt successful for HDFC payment with id: " + merchantPaymentId);
289
            payment.setDescription("Payment Captured");
307
            payment.setDescription("Payment Captured");
Line 325... Line 343...
325
            payment.setDescription(description);
343
            payment.setDescription(description);
326
            payment.setErrorCode(errorCode);
344
            payment.setErrorCode(errorCode);
327
            payment.setStatus(PaymentStatus.FAILED.getValue());
345
            payment.setStatus(PaymentStatus.FAILED.getValue());
328
            payment.setErrorTimestamp(new Date());
346
            payment.setErrorTimestamp(new Date());
329
            paymentHandler.updatePayment(payment, attrMap);
347
            paymentHandler.updatePayment(payment, attrMap);
-
 
348
            createTicketForFailedPayment(payment);
330
            return false;
349
            return false;
331
        }else{
350
        }else{
332
            //Success
351
            //Success
333
            payment.setGatewayTxnStatus(captureStatus);
352
            payment.setGatewayTxnStatus(captureStatus);
334
            payment.setStatus(PaymentStatus.SUCCESS.getValue());
353
            payment.setStatus(PaymentStatus.SUCCESS.getValue());