Project

General

Profile

Programming Guide » History » Version 8

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