Subversion Repositories SmartDukaan

Rev

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

Rev 6050 Rev 6058
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.config.ConfigException;
3
import in.shop2020.config.ConfigException;
-
 
4
import in.shop2020.model.v1.order.RechargeOrder;
4
import in.shop2020.model.v1.order.RechargeOrderStatus;
5
import in.shop2020.model.v1.order.RechargeOrderStatus;
5
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.payments.Attribute;
7
import in.shop2020.payments.Attribute;
7
import in.shop2020.payments.Payment;
8
import in.shop2020.payments.Payment;
8
import in.shop2020.payments.PaymentException;
9
import in.shop2020.payments.PaymentException;
9
import in.shop2020.payments.PaymentService.Client;
10
import in.shop2020.payments.PaymentService.Client;
10
import in.shop2020.payments.PaymentStatus;
11
import in.shop2020.payments.PaymentStatus;
11
import in.shop2020.serving.services.CommonPaymentService;
-
 
12
import in.shop2020.thrift.clients.PaymentClient;
12
import in.shop2020.thrift.clients.PaymentClient;
13
import in.shop2020.thrift.clients.TransactionClient;
13
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.UserClient;
14
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.thrift.clients.config.ConfigClient;
15
import in.shop2020.thrift.clients.config.ConfigClient;
16
 
16
 
17
import java.io.IOException;
17
import java.io.IOException;
18
 
18
 
19
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletRequest;
20
 
20
 
-
 
21
import org.apache.log4j.Logger;
21
import org.apache.struts2.interceptor.ServletRequestAware;
22
import org.apache.struts2.interceptor.ServletRequestAware;
22
import org.apache.thrift.TException;
23
import org.apache.thrift.TException;
23
import org.apache.log4j.Logger;
-
 
24
 
24
 
25
/**
25
/**
26
 * This controller processes payment data received on the back channel from
26
 * This controller processes payment data received on the back channel from
27
 * HDFC. Since this request doesn't have any cookies associated with it, we
27
 * HDFC. Since this request doesn't have any cookies associated with it, we
28
 * can't extend the BaseController which is intercepted by UserInterceptor. Thus
28
 * can't extend the BaseController which is intercepted by UserInterceptor. Thus
Line 131... Line 131...
131
        Client paymentClient = paymentServiceClient.getClient();
131
        Client paymentClient = paymentServiceClient.getClient();
132
        Payment payment = null;
132
        Payment payment = null;
133
        try {
133
        try {
134
            payment = paymentClient.getPayment(merchantPaymentId);
134
            payment = paymentClient.getPayment(merchantPaymentId);
135
            txnId = payment.getMerchantTxnId();
135
            txnId = payment.getMerchantTxnId();
-
 
136
            RechargeOrder rechargeOrder = transactionServiceClient.getClient().getRechargeOrdersForTransaction(txnId);
136
            if(!validatePaymentParams(paymentId, amount, udf5, payment))
137
            if(!validatePaymentParams(paymentId, amount, udf5, payment))
137
                return "index";
138
                return "index";
138
 
139
 
139
            if (result != null && result.trim().equals(PaymentReturnStatus.APPROVED.value())) {
140
            if (result != null && result.trim().equals(PaymentReturnStatus.APPROVED.value())) {
140
                log.info("Payment " + merchantPaymentId + " authorized successfully. Updating the database.");
141
                log.info("Payment " + merchantPaymentId + " authorized successfully. Updating the database.");
141
                String description = "Payment authorized";
142
                String description = "Payment authorized";
142
                updatePaymentDetails(merchantPaymentId, description, PaymentStatus.AUTHORIZED, request, paymentClient);
143
                updatePaymentDetails(merchantPaymentId, description, PaymentStatus.AUTHORIZED, request, paymentClient);
143
                transactionServiceClient.getClient().updateRechargeOrderStatus(txnId, RechargeOrderStatus.PAYMENT_SUCCESSFUL);
144
                transactionServiceClient.getClient().updateRechargeOrderStatus(rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_SUCCESSFUL);
144
                this.redirectUrl = successUrl + "?paymentId=" + merchantPaymentId;
145
                this.redirectUrl = successUrl + "?paymentId=" + merchantPaymentId;
145
            } else {
146
            } else {
146
                updatePaymentDetails(merchantPaymentId, errorText, PaymentStatus.FAILED, request, paymentClient);
147
                updatePaymentDetails(merchantPaymentId, errorText, PaymentStatus.FAILED, request, paymentClient);
147
                transactionServiceClient.getClient().updateRechargeOrderStatus(txnId, RechargeOrderStatus.PAYMENT_FAILED);
148
                transactionServiceClient.getClient().updateRechargeOrderStatus(rechargeOrder.getId(), RechargeOrderStatus.PAYMENT_FAILED);
148
 
149
 
149
                this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
150
                this.redirectUrl = errorUrl + "?paymentId=" + merchantPaymentId;
150
            }
151
            }
151
        } catch (PaymentException e1) {
152
        } catch (PaymentException e1) {
152
            log.error("Payment exception. It is serious, check merchant payment id + " + merchantPaymentId, e1);
153
            log.error("Payment exception. It is serious, check merchant payment id + " + merchantPaymentId, e1);