Project

General

Profile

Programming Guide » History » Version 13

chin-yeh, 10/19/2011 09:36 AM

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 13 chin-yeh
* [[programming guide#Step-By-Step|Step-By-Step]] - describes how to integrate the NMI payment gateway
7 2 chin-yeh
* 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 10 chin-yeh
_See also [[Specification#Payment-Flow|Payment Flow]]_
20 3 chin-yeh
21
*Steps:*
22 7 chin-yeh
# To get the *form URL*, pass the required parameters to [[programming guide#Generate-the-form-action-URL|getFormActionUrl]] method.
23
# Use the *form URL* (in which obtained in the previous step) to construct the payment form with the following <code>input</code> elements:
24
** billing-cc-number
25
** billing-cc-exp
26
** cvv
27
** billing-first-name
28 8 chin-yeh
** billing-last-name
29
** billing-address1
30
** billing-city
31
** billing-state
32
** billing-postal
33
** billing-country
34
** billing-phone
35
** billing-email
36 9 chin-yeh
*** _Example:_ 
37
!payment_form.png!
38 11 chin-yeh
** *Notes:* the URL of this payment form should be *HTTPS*
39 12 chin-yeh
# Validate all of the fields in the form using *JavaScript* (do not use server-side validation). The payment form will be submitted directly to the payment gateway and the payment gateway will direct the user back to the receipt page, which specified the in the previous step.
40 9 chin-yeh
# The redirect URL will contains the *token-id* query parameter. But the method, [[programming guide#Generate-the-form-action-URL|queryAndPersistPaymentStatus]] will extract the parameter on your behalf.
41
# Use the order ID that returned by the method, [[programming guide#Generate-the-form-action-URL|queryAndPersistPaymentStatus]] to get the payment status in the [[Specification#Interface-Table-Used|Interface table]].
42
# The content of the receipt page is depends on the payment status.
43
# done.
44 5 chin-yeh
45
h2. Generate the form action URL
46
47
Generates the <code>form</code> action URL which is needed in the self-hosted payment form.
48
49
_Method Signature:_
50
<pre>
51
<code class="JAVA">
52
public static String getFormActionUrl(String orderId, String orderDescription, BigDecimal orderAmount, String returnUrl)
53
</code>
54
</pre>
55
56
h3. Input Parameters
57
58
* _orderId_ - the unique ID for the order
59
* _orderDescription_ - a simple description of the order
60
* _orderAmount_ - the settlement amount of the order in 2 decimal places, e.g. 12.34
61
* _returnUrl_ - the receipt URL
62
63
h3. Output Parameters
64
65
Returns a <code>form</code> action URL
66
67
h3. Code Snippets
68
69
<pre>
70
<code class="JAVA">
71
	String orderId = request.getParameter("order-id");
72
	String orderDescription = request.getParameter("order-description");
73
	BigDecimal orderAmount = new BigDecimal(request.getParameter("order-amount"));
74
	String returnUrl = request.getParameter("return-url");
75
	
76
	String formUrl = PaymentUtils.getFormActionUrl(orderId, 
77
			orderDescription, 
78
			orderAmount, 
79
			returnUrl);
80
</code>
81
</pre>
82 6 chin-yeh
83
h2. Payment Status Callback
84
85
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]].
86
87
*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]]).
88
89
_Method Signature:_
90
<pre>
91
<code class="JAVA">
92
public static String queryAndPersistPaymentStatus(Connection dbConnection, HttpServletRequest servletRequest)
93
</code>
94
</pre>
95
96
h3. Input Parameters
97
98
* _dbConnection_ - an established database connection
99
* _servletRequest_ - <code>HttpServletRequest</code> object which will be used to obtain the request parameter, <code>token-id</code>
100
101
h3. Output Parameters
102
103
the <code>order ID</code> that used in the particular payment transaction
104
105
106
h3. Code Snippets
107
108
<pre>
109
<code class="JAVA">
110
	Connection connection = createDbConnection("java:/DB2DS_USA");
111
	String orderId = "";
112
	try {
113
		orderId = PaymentUtils.queryAndPersistPaymentStatus(connection, request);
114
	} finally {
115
		if (connection != null) {
116
			connection.close();
117
		}
118
	}
119
</code>
120
</pre>