Project

General

Profile

Files » ProcessCardPaymentBBL_th.jsp

Soh Keong, 02/26/2021 12:08 PM

 
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"
import = "java.sql.Connection,
java.util.Map,
java.util.HashMap,
java.util.Locale,
java.io.InputStreamReader,
java.io.BufferedReader,
java.net.URL,
java.net.URLConnection,
java.net.URLEncoder,
com.ecosway.bbl.service.BBLService,
com.ecosway.bbl.service.BBLServiceImpl,
com.ecosway.bbl.model.ResponseBBL,
my.com.eCosway.constants.FormParameters,
my.com.eCosway.constants.CommonConstants,
my.com.eCosway.th.orders.MemberBoRegAfterPayment,
my.com.eCosway.th.orders.PurchaseAfterPayment,
my.com.eCosway.db.DataBean,
my.com.eCosway.beans.OrderBean,
my.com.eCosway.util.OrderIdEncryptionUtil,
my.com.eCosway.util.BundleUtil"%>

<%@ include file="include/Common_th.inc" %>
<%!
private final String CURRENT_PAGE = "ProcessCardPaymentBBL_th.jsp";
private final String ERROR_PAYMENT_PAGE = "ErrorPage_th.jsp";
private final String COSWAY_ORDER_ID_PREFIX = "CW";

private String getNextUrlAfterProcessPurchaseOrder(Connection connectionUsa, Connection connectionStore, String orderId, int mainCategoryRefNo) throws Exception{
PurchaseAfterPayment purchaseAfterPayment = null;
OrderBean mainOrderBean = null;
Map<String, Object> resultMap = null;
String nextUrl = ERROR_PAYMENT_PAGE;
String orderStatus = null;
try{
purchaseAfterPayment = new PurchaseAfterPayment();
purchaseAfterPayment.setConnectionUsa(connectionUsa);
purchaseAfterPayment.setConnectionStore(connectionStore);
purchaseAfterPayment.setOrderId(orderId);
purchaseAfterPayment.setMainCategoryRefNo(mainCategoryRefNo);
resultMap = purchaseAfterPayment.getResultAfterProcessPurchaseOrder();
orderStatus = (String)resultMap.get(PurchaseAfterPayment.DATA_ORDER_STATUS);
if (orderStatus.equals(CommonConstants.ORDER_STATUS_APPROVED)){
mainOrderBean = (OrderBean) resultMap.get(PurchaseAfterPayment.DATA_MAIN_ORDER_BEAN);
nextUrl = "ProductOrderReceipt_th.jsp?orderId="+OrderIdEncryptionUtil.getEncryptedOrderIdAndShopperRefNo(orderId, mainOrderBean.getShopperRefNo());
}
}
catch(Exception e){
throw new Exception("getNextUrlAfterProcessPurchaseOrder() - Error : "+e.getMessage());
}
return nextUrl;
}

private String getNextUrlAfterProcessBoRegOrder(Connection connectionUsa, Connection connectionStore, String orderId) throws Exception{
MemberBoRegAfterPayment memberBoRegAfterPayment = null;
OrderBean mainOrderBean = null;
Map<String, Object> resultMap = null;
String nextUrl = ERROR_PAYMENT_PAGE;
String orderStatus = null;
try{
memberBoRegAfterPayment = new MemberBoRegAfterPayment();
memberBoRegAfterPayment.setConnectionUsa(connectionUsa);
memberBoRegAfterPayment.setConnectionStore(connectionStore);
memberBoRegAfterPayment.setOrderId(orderId);
resultMap = memberBoRegAfterPayment.getResultAfterProcessBoRegOrder();
orderStatus = (String)resultMap.get(PurchaseAfterPayment.DATA_ORDER_STATUS);
if (orderStatus.equals(CommonConstants.ORDER_STATUS_APPROVED)){
mainOrderBean = (OrderBean) resultMap.get(PurchaseAfterPayment.DATA_MAIN_ORDER_BEAN);
nextUrl = "MemberBoRegReceipt_th.jsp?orderId="+OrderIdEncryptionUtil.getEncryptedOrderId(orderId);
}
}
catch(Exception e){
throw new Exception("getNextUrlAfterProcessBoRegOrder() - Error : "+e.getMessage());
}
return nextUrl;
}

private String getNextUrlAfterProcessBoRenewalOrder(String orderId) throws Exception{
String processUrl = null;
String nextUrl = null;
try{
processUrl = "http://localhost/ecos2office/ec/ProcessCardPaymentBBL.jsp?orderId="+orderId;
nextUrl = getConetntFromUrl(processUrl);
}
catch(Exception e){
throw new Exception("getNextUrlAfterProcessBoRenewalOrder() - Error : "+e.getMessage());
}
return nextUrl;
}



private boolean isSuccessProcessCoswayOrder(HttpServletRequest request) throws Exception{
URL url = null;
URLConnection conn = null;
BufferedReader rd = null;
String processUrl = null;
String lineStr = null;
boolean isSuccess = false;
String paramString = "";
StringBuilder sb = null;
try{
if(request.getQueryString() == null){
sb = new StringBuilder("Ref=").append(request.getParameter("Ref"));
sb.append("&successcode=").append(request.getParameter("successcode"));
sb.append("&Amt=").append(request.getParameter("Amt"));
sb.append("&remark=").append(request.getParameter("remark"));
sb.append("&PayRef=").append(request.getParameter("PayRef"));
sb.append("&AuthId=").append(request.getParameter("AuthId"));
sb.append("&TxTime=").append(URLEncoder.encode(request.getParameter("TxTime"),"UTF-8"));
}else{
sb = new StringBuilder(request.getQueryString());
}
sb.append("&allowRedirect=");
sb.append(CommonConstants.REDIRECT_TO_RECEIPT_NO);
processUrl = "http://localhost/cosway/th/ProcessCardPaymentBBL_th.jsp?"+sb.toString();
url = new URL(processUrl);
conn = url.openConnection();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
System.out.println(" **************************88888888888888************ "+processUrl);
while ((lineStr = rd.readLine()) != null){
if (getString(lineStr).equals("OK"))
isSuccess = true;
}
}
catch(Exception e){
throw new Exception("isSuccessProcessCoswayOrder() - Error : "+e.getMessage());
}
return isSuccess;
}

private String getConetntFromUrl(String urlStr) throws Exception{
URL url = null;
URLConnection conn = null;
BufferedReader rd = null;
StringBuffer str = new StringBuffer();
String lineStr = null;
String tempListStr = null;
try{
url = new URL( urlStr);
conn = url.openConnection();
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((lineStr = rd.readLine()) != null && lineStr.contains("http")){
str.append(lineStr);
}
}
catch(Exception e){
throw new Exception("getConetntFromUrl() - Error : "+e.getMessage());
}
return str.toString();
}

%>
<%

BundleUtil bundleUtil = null;
BBLService service = null;
ResponseBBL responseBBL = null;
Connection conUsa = null;
Connection conStore = null;
String orderId = null;
String allowRedirect = CommonConstants.REDIRECT_TO_RECEIPT_YES;
String nextUrl = ERROR_PAYMENT_PAGE;

try{
try{
conUsa = DataBean.getConnectionByDataSource(common_dataSourceUsa);
conStore = DataBean.getConnectionByDataSource(common_dataSourceStore);
orderId = getString(request.getParameter("Ref"));
if (orderId.startsWith(COSWAY_ORDER_ID_PREFIX) && isSuccessProcessCoswayOrder(request)){
System.out.println("Success..............................."+orderId);
nextUrl = null;
out.println("OK");
}else{
service = new BBLServiceImpl();
responseBBL = service.updateTransaction(conUsa, request);
if (responseBBL.getOrderID().length() > 0 && responseBBL.isValid()){
System.out.println(CURRENT_PAGE + "?orderId="+responseBBL.getOrderID());
if (responseBBL.getTransactionType().equals(CommonConstants.CREDIT_CARD_PAY_FOR_PURCHASE)){
nextUrl = getNextUrlAfterProcessPurchaseOrder(conUsa,conStore, responseBBL.getOrderID(), common_mainCategoryRefNo);
}else if (responseBBL.getTransactionType().equals(CommonConstants.CREDIT_CARD_PAY_FOR_REGISTRATION)){
nextUrl = getNextUrlAfterProcessBoRegOrder(conUsa, conStore, responseBBL.getOrderID());
}else if (responseBBL.getTransactionType().equals(CommonConstants.CREDIT_CARD_PAY_FOR_BO_RENEWAL)){
nextUrl = getNextUrlAfterProcessBoRenewalOrder(responseBBL.getOrderID());
}
out.println("OK");
}
}
}
catch(Exception e){
System.err.println(CURRENT_PAGE + " - "+e.getMessage());
}
finally{
if (conUsa != null)
conUsa.close();
if (conStore != null)
conStore.close();


}
if (nextUrl != null)
response.sendRedirect(nextUrl);

}
catch(Exception e){
System.err.println(CURRENT_PAGE + " - "+e.getMessage());
}
%>
(1-1/3)