前言:

  很多接案的人,都會碰到需要接金流的時候。而歐付寶是個台灣的金流平台。

  這邊記錄下,串接的心得。我用的語言是Java, 採liferay這個portal平台,不過這份教學當然適合servlet.

  不過官方技術文件,太規格導向了。應該要方便developer快速開發才是 很多資訊還是要向官方問才知道。

流程 :

  1. 假設有一個網購網站,有使用者下了單之後,採用信用卡付款。此時照官方使用範例

    會把所有資訊弄成html的語法(html hidden fields),再加密送出去。

    eg. 
    <input type="hidden" name="Language" value="English">
  2. 如果不懂,覺得太抽象可以用 http://dev.lovewed.tw/allpay/ 這個網站來測試整個流程(歐付寶有提供測試平台,測試信用卡 卡號)。

    了解整個流程後,我們可以確定歐付寶正常無誤就可以開始串寫程式了。


  3. payment.jsp, 這支是負責user填完資料驗證後,且在我方server有紀錄後,送給轉到歐付寶付款用的。
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <%@ page import="AllPay.Payment.Integration.*" %>
    <%@ page import="java.util.Hashtable" %>
    <%@ page import="java.util.Set" %>
    <%@ page import="java.util.TreeSet" %>
    <%@ page import="java.util.Date" %>
    <%@ page import="java.util.List" %>
    <%@ page import="java.util.ArrayList" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>AllPay</title>
    </head>
    <body>
    <%
        List<String> enErrors = new ArrayList<String>();
        try {
            AllInOne oPayment = new AllInOne();
            
            /* 服務參數 */
            oPayment.ServiceMethod = HttpMethod.HttpPOST;
            oPayment.ServiceURL = "";
            oPayment.HashKey = "";
            oPayment.HashIV = "";
            oPayment.MerchantID = "";
            
            /* 基本參數 */
            oPayment.Send.ReturnURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp";
            oPayment.Send.ClientBackURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp";
            oPayment.Send.OrderResultURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp";
            oPayment.Send.MerchantTradeNo = String.valueOf((new Date()).getTime());
            oPayment.Send.MerchantTradeDate = new Date();
            oPayment.Send.TotalAmount = new Decimal("300");
            oPayment.Send.TradeDesc = AllPayFunction.genString("測試");
            oPayment.Send.ChoosePayment = PaymentMethod.ALL;
            oPayment.Send.Remark = AllPayFunction.genString("測試Pay");
            oPayment.Send.ChooseSubPayment = PaymentMethodItem.ATM_TAISHIN;
            oPayment.Send.NeedExtraPaidInfo = ExtraPaymentInfo.Yes;
            oPayment.Send.DeviceSource = DeviceType.PC;
            
            oPayment.SendExtend.ExpireDate = 1;
            oPayment.SendExtend.PaymentInfoURL = "http://172.16.30.41:8080/AllPayWeb/checkOutFeedback_All.jsp";
            //oPayment.SendExtend.ClientRedirectURL = "http://172.16.30.41:8080/";
            
            // 加入選購商品資料。
            Item a1 = new Item();
            a1.Name = "一棟房子";
            a1.Price = new Decimal("300");
            a1.Currency = "元";
            a1.Quantity = 2;
            a1.URL = "<<產品說明位址>>";
            oPayment.Send.Items.add(a1);
            
            Item a2 = new Item();
            a2.Name = "iPhone 6S";
            a2.Price = new Decimal("400");
            a2.Currency = "元";
            a2.Quantity = 8;
            a2.URL = "<<產品說明位址>>";
            oPayment.Send.Items.add(a2);
            
            enErrors.addAll(oPayment.CheckOut(response.getWriter()));
            
        }
        catch (Exception e) {
            enErrors.add(e.getMessage());
        }
        finally {
            if (enErrors.size() > 0)
                out.print(enErrors);
        }
    %>
    </body>
    </html>
    bittorrent

相关文章:

  • 2021-10-18
  • 2021-12-31
  • 2021-12-04
  • 2022-01-01
  • 2021-08-27
  • 2022-01-12
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-02-07
  • 2021-11-23
  • 2021-11-05
  • 2021-12-04
  • 2021-08-31
相关资源
相似解决方案