Project

General

Profile

Programming Guide » History » Version 9

chin-yeh, 09/21/2011 02:43 PM

1 2 chin-yeh
{{toc}}
2
3 1 chin-yeh
h1. Programming Guide
4 2 chin-yeh
5
Describes how to integrate the mPay into online mall.
6
7 4 chin-yeh
*Demo application:*
8
* Generate Redirect URL (for hosted payment form)
9
> http://192.168.2.68/ecosway/mpay-sample/payment_form.html
10 5 chin-yeh
* Query Payment Status:
11 4 chin-yeh
> http://192.168.2.68/ecosway/mpay-sample/query.html
12 3 chin-yeh
13 2 chin-yeh
h2. Source files
14
15
> Get the source files from [[wiki#SCM|SCM]].
16
17
*Files:*
18
* my.com.eCosway.mpay
19
** Commons - list of common constant
20
** MpayInterfaceUtils - an utility to perform data persistence related operation
21
** MpayPaymentUtils - the mPay APIs
22
** MpayProperties - data model of the mPay properties
23
** PaymentRequest - data model of the mPay's payment request
24
** PaymentResponse - data model of the mPay's payment response
25
* resources.properties.mpay
26
** mpay.properties - the application properties file
27 8 chin-yeh
* source file of demo application (JSP):
28
** mpay-sample folder
29 5 chin-yeh
30
h2. Generate Redirect URL
31
32 6 chin-yeh
Generates the URL which will be used to redirect user to the mPay's hosted payment form.
33
34 9 chin-yeh
* *Method Signature:*
35
<pre>
36
<code class="JAVA">
37
public static Map<String, String> genRedirectFormData(String orderNo,
38
			Date txnDate, String amount, String returnUrl, String locale,
39
			PaymentMethod paymentMethod)
40
</code>
41
</pre>
42
* *Demo application:*
43 7 chin-yeh
> [[Programming Guide]]
44 6 chin-yeh
45 5 chin-yeh
h3. Input Parameters
46
47 6 chin-yeh
* *orderNo* - the unique order number 
48
* *txtDate* - the transaction date
49
* *amount* - the transaction amount
50
* *returnUrl* - mPay will redirect the user to this URL after made the payment
51
* *locale* - the display language of the payment form
52
* *paymentMethod* - the payment method, e.g. _CUP_, _Alipay_
53
54
h3. Output Parameters
55 1 chin-yeh
56 7 chin-yeh
Use the returned key-pair values to construct the *HTML form*. 
57 1 chin-yeh
58 8 chin-yeh
Due to the limit of the length of a URL, the recommended HTTP method is *POST*. This is because extremely long URL will not work in most popular browsers and most importantly the length of the query string is unknown.
59 7 chin-yeh
60
*Returned key-pair values:*
61
* *form_action* - the URL of the hosted payment form. To be placed in the *action* attribute of the form
62
* *encmsg* - the encrypted message. To be placed in the input element
63
* *sigmsg* - the signed message. To be placed in the input element
64
* *certserial* - the serial number of the certificate. To be placed in the input element
65
66 5 chin-yeh
h3. Code Snippets
67 1 chin-yeh
68 7 chin-yeh
<pre>
69
<code class="JAVA">
70
<body>
71 1 chin-yeh
72 7 chin-yeh
<%
73
	String orderNo = request.getParameter("order_no");
74
	String txnDate = request.getParameter("txn_date");
75
	String amount = request.getParameter("amount");
76
	String returnUrl = request.getParameter("return_url");
77
	String locale = request.getParameter("locale");
78
	String paymentMethod = request.getParameter("payment_method");
79
	
80
	Date transactionDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(txnDate);
81
	PaymentMethod cardType = PaymentMethod.valueOf(paymentMethod);
82
	
83
	Map<String, String> formData = MpayPaymentUtils.genRedirectFormData(
84
			orderNo, 
85
			transactionDate,
86
			amount,
87
			returnUrl,
88
			locale,
89
			cardType);
90
%>
91
92
<p>
93
	Redirecting you to the mPay payment form, it may takes up to 1 minute...
94 1 chin-yeh
</p>
95 7 chin-yeh
96 9 chin-yeh
<form name="form1" method="post" action="<%= formData.get("form_action") %>">
97 7 chin-yeh
	<input type=hidden name=encmsg value="<%=formData.get("encmsg")%>"/>
98
	<input type=hidden name=sigmsg value="<%=formData.get("sigmsg")%>"/>
99
	<input type=hidden name=certserial value="<%=formData.get("certserial")%>"/>
100
</form>
101
102
<script language="javascript">
103
104
function submitForm(){
105
    document.form1.submit();
106
}
107
108
window.onload=submitForm ;
109
110
</script>
111
112
</body>
113
</code>
114
</pre>
115
116
117 5 chin-yeh
h2. Query Payment Status
118
119
h3. Input Parameters
120
121
h3. Output Parameters
122
123 1 chin-yeh
h3. Code Snippets
124 7 chin-yeh
125
<pre>
126
<code class="JAVA">
127
128
</code>
129
</pre>