Rev 6903 | Rev 12616 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import in.shop2020.datalogger.EventType;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.model.v1.order.TransactionServiceException;import in.shop2020.model.v1.user.Affiliate;import in.shop2020.model.v1.user.Cart;import in.shop2020.model.v1.user.ShoppingCartException;import in.shop2020.model.v1.user.TrackLogType;import in.shop2020.model.v1.user.UserAffiliateException;import in.shop2020.payments.PaymentException;import in.shop2020.serving.interceptors.TrackingInterceptor;import in.shop2020.serving.utils.FormattingUtils;import in.shop2020.serving.utils.Utils;import in.shop2020.thrift.clients.PaymentClient;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.thrift.clients.UserClient;import in.shop2020.utils.DataLogger;import java.text.SimpleDateFormat;import java.util.Calendar;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;@InterceptorRefs({@InterceptorRef("myDefault"),@InterceptorRef("login")})public class PaySuccessController extends BaseController{private static final long serialVersionUID = 1L;private static final String ITEM = "ITEM";private static final String ITEMS = "ITEMS";private static final String SHOOGLOO_AFF_NAME = "shoogloo";private static Logger log = Logger.getLogger(Class.class);private FormattingUtils formattingUtils = new FormattingUtils();private boolean isShooglooAff = false;long merchantPaymentId;long txnId;List<Order> orders = null;String message = null;private boolean isAnyOrderInsured;public PaySuccessController(){super();}public String index() {PaymentClient paymentServiceClient = null;TransactionClient transactionServiceClient = null;UserClient userServiceClient = null;try {paymentServiceClient = new PaymentClient();transactionServiceClient = new TransactionClient();userServiceClient = new UserClient();} catch (Exception e1) {// TODO Nothing to worrylog.error("Unable to initialize the client for either payment or transaction or user service", e1);}merchantPaymentId = Long.parseLong(this.request.getParameter("paymentId"));try {txnId = paymentServiceClient.getClient().getPayment(merchantPaymentId).getMerchantTxnId();orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());for(Order order : orders) {if(order.getInsurer() > 0) {setAnyOrderInsured(true);break;}}Cart cart = userServiceClient.getClient().getCart(userinfo.getCartId());if(cart != null){userinfo.setTotalItems(cart.getLinesSize());userinfo.setTotalAmount(cart.getTotalPrice());}else{userinfo.setTotalItems(0);userinfo.setTotalAmount(0);}String suffix = ITEM;if(orders.size() > 1)suffix = ITEMS;this.message = "You have successfully ordered <span class=\"orange\">" + orders.size() + " " + suffix + ".</span>";if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());userServiceClient.getClient().addTrackLog(affId, userinfo.getUserId(), TrackLogType.PAYMENT_SUCCESS, "",Long.toString(merchantPaymentId), (new Date()).getTime());Affiliate aff = userServiceClient.getClient().getAffiliateById(affId);if (aff.getName().equals(SHOOGLOO_AFF_NAME)) {isShooglooAff = true;}}} catch (PaymentException e) {log.error("Payment service not responding. Payment id is" + merchantPaymentId, e);} catch (TException e) {log.error("Thrift service exception. Payment id is" + merchantPaymentId, e);} catch (TransactionServiceException e) {log.error("Transaction service exception. Payment id is" + merchantPaymentId, e);} catch (ShoppingCartException e) {log.error("Shopping cart service exception. Payment id is" + merchantPaymentId, e);} catch (UserAffiliateException e) {log.error("Affiliate service exception. Payment id is" + merchantPaymentId, e);}DataLogger.logData(EventType.PAYMENT_SUCCESS, getSessionId(), userinfo.getUserId(),userinfo.getEmail(), Long.toString(merchantPaymentId), Utils.getItemIdStringFromOrders(orders));return "index";}public String formatPrice(double price) {return formattingUtils.formatPrice(price);}public List<Order> getOrders(){return this.orders;}public List<Order> getSuccessfulOrders(){if((this.orders.get(0).getStatus() == OrderStatus.COD_VERIFICATION_PENDING|| this.orders.get(0).getStatus() == OrderStatus.SUBMITTED_FOR_PROCESSING) && this.orders.get(0).getCreated_timestamp() + 10*60*1000 > Calendar.getInstance().getTimeInMillis()){return this.orders;}return null;}public String getMessage(){return this.message;}public boolean getIsShooglooAff() {return this.isShooglooAff;}public long getMerchantPaymentId() {return merchantPaymentId;}public long getTxnId() {return txnId;}public static String formatDate(long timestamp){SimpleDateFormat dateformat = new SimpleDateFormat("dd MMMM yyyy");return dateformat.format(new Date(timestamp));}@Overridepublic String getHeaderSnippet() {String url = request.getQueryString();if (url == null) {url = "";} else {url = "?" + url;}url = request.getRequestURI() + url;return pageLoader.getHeaderHtml(userinfo.isLoggedIn(), userinfo.getEmail(), userinfo.getTotalItems(), url , 0, false, userinfo.isPrivateDealUser());}public void setAnyOrderInsured(boolean isAnyOrderInsured) {this.isAnyOrderInsured = isAnyOrderInsured;}public boolean isAnyOrderInsured() {return isAnyOrderInsured;}}