Project

General

Profile

Programming Guide » History » Version 7

chin-yeh, 10/18/2011 03:56 PM

1 1 chin-yeh
{{toc}}
2
3
h1. Programming Guide
4 2 chin-yeh
5
This guide describes how to make use of the NMI APIs for payment related transaction and it consists of 2 main parts:
6
* [[programming guide#Step-By-Step|Step-By-Step]] - describes the 
7
* API Reference - the detailed description of all the APIs mentioned in [[programming guide#Step-By-Step|Step-By-Step]]
8
9 3 chin-yeh
The demo application can be found here:
10 5 chin-yeh
> http://192.168.2.68/ukstore/nmi-sample/orders.jsp
11 3 chin-yeh
12 2 chin-yeh
h2. Step-By-Step
13
14
Before begin, install the following libraries into your development environment *_(remove the old versions if exists)_*:
15
* "HttpCore 4.1.2":http://192.168.2.13:8081/nexus/service/local/artifact/maven/redirect?r=central&g=org.apache.httpcomponents&a=httpcore&v=4.1.2&e=jar
16
* "HttpClient 4.1.2":http://192.168.2.13:8081/nexus/service/local/artifact/maven/redirect?r=central&g=org.apache.httpcomponents&a=httpclient&v=4.1.2&e=jar
17 3 chin-yeh
18
!ssd.png!
19
20
*Steps:*
21 7 chin-yeh
# To get the *form URL*, pass the required parameters to [[programming guide#Generate-the-form-action-URL|getFormActionUrl]] method.
22
# Use the *form URL* (in which obtained in the previous step) to construct the payment form with the following <code>input</code> elements:
23
** billing-cc-number
24
** billing-cc-exp
25
** cvv
26
** billing-first-name
27
# er
28 5 chin-yeh
29
h2. Generate the form action URL
30
31
Generates the <code>form</code> action URL which is needed in the self-hosted payment form.
32
33
_Method Signature:_
34
<pre>
35
<code class="JAVA">
36
public static String getFormActionUrl(String orderId, String orderDescription, BigDecimal orderAmount, String returnUrl)
37
</code>
38
</pre>
39
40
h3. Input Parameters
41
42
* _orderId_ - the unique ID for the order
43
* _orderDescription_ - a simple description of the order
44
* _orderAmount_ - the settlement amount of the order in 2 decimal places, e.g. 12.34
45
* _returnUrl_ - the receipt URL
46
47
h3. Output Parameters
48
49
Returns a <code>form</code> action URL
50
51
h3. Code Snippets
52
53
<pre>
54
<code class="JAVA">
55
	String orderId = request.getParameter("order-id");
56
	String orderDescription = request.getParameter("order-description");
57
	BigDecimal orderAmount = new BigDecimal(request.getParameter("order-amount"));
58
	String returnUrl = request.getParameter("return-url");
59
	
60
	String formUrl = PaymentUtils.getFormActionUrl(orderId, 
61
			orderDescription, 
62
			orderAmount, 
63
			returnUrl);
64
</code>
65
</pre>
66 6 chin-yeh
67
h2. Payment Status Callback
68
69
Queries the payment status using the <code>token ID</code> that returned by NMI. After obtained the payment status, update the particular record in the [[Specification#Interface-Table-Used|Interface table]].
70
71
*Important:* This method is supposed to be placed and invoked in the very beginning of the receipt page, (a.k.a. the <code>returnUrl</code> that specified in [[programming guide#Generate-the-form-action-URL|Generate form action URL]]).
72
73
_Method Signature:_
74
<pre>
75
<code class="JAVA">
76
public static String queryAndPersistPaymentStatus(Connection dbConnection, HttpServletRequest servletRequest)
77
</code>
78
</pre>
79
80
h3. Input Parameters
81
82
* _dbConnection_ - an established database connection
83
* _servletRequest_ - <code>HttpServletRequest</code> object which will be used to obtain the request parameter, <code>token-id</code>
84
85
h3. Output Parameters
86
87
the <code>order ID</code> that used in the particular payment transaction
88
89
90
h3. Code Snippets
91
92
<pre>
93
<code class="JAVA">
94
	Connection connection = createDbConnection("java:/DB2DS_USA");
95
	String orderId = "";
96
	try {
97
		orderId = PaymentUtils.queryAndPersistPaymentStatus(connection, request);
98
	} finally {
99
		if (connection != null) {
100
			connection.close();
101
		}
102
	}
103
</code>
104
</pre>