Project

General

Profile

Files » EcPayCreatePayment.jsp

Soh Keong, 03/02/2023 11:25 AM

 
<%@ page language="java" pageEncoding="UTF-8"
contentType="text/html; charset=UTF-8"
import="com.ecosway.testpage.conn.ConnUtil,
com.ecpay.service.EcPayService "%>

<%@ include file="../menu.jsp"%>


<%
String orderId = null;
String token = null;
String language = null;
EcPayService service = null;
String url = null;

try {

orderId = request.getParameter("orderId");
System.out.println("orderId["+orderId+"]");
System.out.println("token["+request.getParameter("token")+"]");
System.out.println("language["+request.getParameter("language")+"]");
System.out.println("payToken["+request.getParameter("payToken")+"]");

if (request.getParameter("token") != null) {
token = request.getParameter("token");
language = request.getParameter("language");
}

if (request.getParameter("payToken") != null) {
service = new EcPayService();
url = service.createPaymentPage(ConnUtil.getUsaConn(), orderId, request.getParameter("payToken"));
}

} catch (Exception e) {
e.printStackTrace();
} finally {
ConnUtil.closeConnection();
}
%>

<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Language" content="zh-TW">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1.0, user-scalable=yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="description" content="綠界科技 ECPay 提供信用卡刷卡、超商代收及取貨付款、ATM轉帳...等多種金流收款服務,會員可於綠界網站建立收款網址或使用API程式串接,應用彈性,收款隔日起即撥款。支付找綠界,買賣無國界。">
<!-- 必填,限制 81-150 字 -->
<meta name="keywords" content="信用卡,ATM轉帳,超商代碼,超商條碼,applepay,googlepay,samsungpay,金流服務">
<title>綠界科技 ECPay - 第三方支付領導品牌</title>

</head>
<body>
<div class="order-info">
<div id="ECPayPayment"></div>
<br />

<form action="" id="PayProcess" method="post">
<div style="text-align: center;">
<input id="PaymentType" name="PaymentType" type="hidden" value="" />
<input id="OrderId" name="OrderId" type="hidden" value="<%=orderId%>>" />
<input id="OrderId" name="OrderId" type="hidden" value="<%=orderId%>>" />
<%if(url != null){ %>
<input id="btnPay" type="button" class="btn single btn-gray-dark" value="確認付款" />
<%} %>
</div>
<br />
<div style="text-align: center;">
<%if(url != null){ %>
<a href=<%=url%>>Payment Result</a>
<%}else{ %>
消費者選擇付款方式取得的PayToken : <input id="payToken" name="payToken" type="Text" size="50" value="" />
<%} %>
</div>
</form>
</div>
</body>


<!-- 綠界科技 ECPay SDK 需引用JS 區塊 -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/node-forge@0.7.0/dist/forge.min.js"></script>
<script src="https://ecpg.ecpay.com.tw/Scripts/sdk-1.0.0.js?t=20210121100116"></script>

<script type="text/javascript">
$(function() {
//初始化SDK畫面
// 'Stage' / 'Prod';
// Display Loading Page : 0=No,1=Yes
ECPay.initialize('Stage', 1, function(errMsg) {

try {
ECPay.createPayment('<%=token%>', '<%=language%>', function(errMsg) {
if (errMsg != null)
ErrHandle(errMsg);
}, 'V2');
} catch (err) {
ErrHandle(err);
}
});

//消費者選擇完成付款方式,取得payToken
$('#btnPay').click(function() {

try {
ECPay.getPayToken(function(paymentInfo, errMsg) {
if (errMsg != null) {
ErrHandle(errMsg);
return;
}
;
$("#payToken").val(paymentInfo.PayToken);

$("#PayProcess").submit();
return true;
});
} catch (err) {
ErrHandle(err);
}

return false;
});
});

function ErrHandle(strErr) {

if (strErr != null) {
$('#ECPayPayment').append(
'<div style="text-align: center;"><label style="color: red;">'
+ strErr + '</label></div>');
console.log(strErr);
} else {
$('#ECPayPayment')
.append(
'<div style="text-align: center;"><label style="color: red;">Token取得失敗</label></div>');
console.log('Wrong');
}

//$('#btnPay').hide();
}
</script>
</html>
(3-3/5)