Project

General

Profile

Programming Guide » History » Version 7

chin-yeh, 09/21/2011 02:35 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 3 chin-yeh
28
*Demo application:*
29 1 chin-yeh
> can be found in mpay-sample folder (web content)
30 5 chin-yeh
31
h2. Generate Redirect URL
32
33 6 chin-yeh
Generates the URL which will be used to redirect user to the mPay's hosted payment form.
34
35 7 chin-yeh
Demo application:
36
> [[Programming Guide]]
37 6 chin-yeh
38 5 chin-yeh
h3. Input Parameters
39
40 6 chin-yeh
* *orderNo* - the unique order number 
41
* *txtDate* - the transaction date
42
* *amount* - the transaction amount
43
* *returnUrl* - mPay will redirect the user to this URL after made the payment
44
* *locale* - the display language of the payment form
45
* *paymentMethod* - the payment method, e.g. _CUP_, _Alipay_
46
47
h3. Output Parameters
48 1 chin-yeh
49 7 chin-yeh
Use the returned key-pair values to construct the *HTML form*. 
50 1 chin-yeh
51 7 chin-yeh
Due to the maximum 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.
52
53
*Returned key-pair values:*
54
* *form_action* - the URL of the hosted payment form. To be placed in the *action* attribute of the form
55
* *encmsg* - the encrypted message. To be placed in the input element
56
* *sigmsg* - the signed message. To be placed in the input element
57
* *certserial* - the serial number of the certificate. To be placed in the input element
58
59 5 chin-yeh
h3. Code Snippets
60 1 chin-yeh
61 7 chin-yeh
<pre>
62
<code class="JAVA">
63
<body>
64 1 chin-yeh
65 7 chin-yeh
<%
66
	String orderNo = request.getParameter("order_no");
67
	String txnDate = request.getParameter("txn_date");
68
	String amount = request.getParameter("amount");
69
	String returnUrl = request.getParameter("return_url");
70
	String locale = request.getParameter("locale");
71
	String paymentMethod = request.getParameter("payment_method");
72
	
73
	Date transactionDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(txnDate);
74
	PaymentMethod cardType = PaymentMethod.valueOf(paymentMethod);
75
	
76
	Map<String, String> formData = MpayPaymentUtils.genRedirectFormData(
77
			orderNo, 
78
			transactionDate,
79
			amount,
80
			returnUrl,
81
			locale,
82
			cardType);
83
%>
84
85
<p>
86
	Redirecting you to the mPay payment form, it may takes up to 1 minute...
87
</p>
88
89
<form name=form1 method=post action="<%= formData.get("form_action") %>">
90
	<input type=hidden name=encmsg value="<%=formData.get("encmsg")%>"/>
91
	<input type=hidden name=sigmsg value="<%=formData.get("sigmsg")%>"/>
92
	<input type=hidden name=certserial value="<%=formData.get("certserial")%>"/>
93
</form>
94
95
<script language="javascript">
96
97
function submitForm(){
98
    document.form1.submit();
99
}
100
101
window.onload=submitForm ;
102
103
</script>
104
105
</body>
106
</code>
107
</pre>
108
109
110 5 chin-yeh
h2. Query Payment Status
111
112
h3. Input Parameters
113
114
h3. Output Parameters
115
116 1 chin-yeh
h3. Code Snippets
117 7 chin-yeh
118
<pre>
119
<code class="JAVA">
120
121
</code>
122
</pre>