Rev 1527 | Rev 2157 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import java.util.Date;import java.util.List;import org.apache.log4j.Logger;import org.apache.struts2.convention.annotation.InterceptorRef;import org.apache.struts2.convention.annotation.InterceptorRefs;import org.apache.thrift.TException;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.order.TransactionServiceException;import in.shop2020.model.v1.user.Cart;import in.shop2020.model.v1.user.ShoppingCartException;import in.shop2020.model.v1.user.UserAffiliateException;import in.shop2020.payments.PaymentException;import in.shop2020.serving.interceptors.TrackingInterceptor;import in.shop2020.thrift.clients.PaymentServiceClient;import in.shop2020.thrift.clients.TransactionServiceClient;import in.shop2020.thrift.clients.UserContextServiceClient;@InterceptorRefs({@InterceptorRef("myDefault"),@InterceptorRef("login")})public class PaySuccessController extends BaseController{private static final long serialVersionUID = 1L;private static Logger log = Logger.getLogger(Class.class);long merchantPaymentId;List<Order> orders = null;String message = null;public PaySuccessController(){super();}public String index() {this.message = "Payment completed successfully.";PaymentServiceClient paymentServiceClient = null;TransactionServiceClient transactionServiceClient = null;UserContextServiceClient userServiceClient = null;try {paymentServiceClient = new PaymentServiceClient();transactionServiceClient = new TransactionServiceClient();userServiceClient = new UserContextServiceClient();} catch (Exception e1) {// TODO Nothing to worrye1.printStackTrace();}merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));long txnId;try {txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());int totalItems = 0;if(cart != null){totalItems = cart.getLinesSize();}userinfo.setTotalItems(totalItems);if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), "payment success", "",Long.toString(merchantPaymentId), (new Date()).getTime());}} catch (PaymentException e) {log.error("Payment service not responding. Payment id is" + merchantPaymentId);e.printStackTrace();} catch (TException e) {log.error("Thrift service exception. Payment id is" + merchantPaymentId);e.printStackTrace();} catch (TransactionServiceException e) {log.error("Transaction service exception. Payment id is" + merchantPaymentId);e.printStackTrace();} catch (ShoppingCartException e) {log.error("Shopping cart service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());e.printStackTrace();} catch (UserAffiliateException e) {log.error("Affiliate service exception. Payment id is" + merchantPaymentId + " message id and name are " + e.getId() + e.getMessage());e.printStackTrace();}return "index";}public List<Order> getOrders(){return this.orders;}public String getMessage(){return this.message;}}