Programming Guide » History » Version 6
chin-yeh, 10/18/2011 03:20 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 | # gather the |
||
22 | 5 | chin-yeh | |
23 | h2. Generate the form action URL |
||
24 | |||
25 | Generates the <code>form</code> action URL which is needed in the self-hosted payment form. |
||
26 | |||
27 | _Method Signature:_ |
||
28 | <pre> |
||
29 | <code class="JAVA"> |
||
30 | public static String getFormActionUrl(String orderId, String orderDescription, BigDecimal orderAmount, String returnUrl) |
||
31 | </code> |
||
32 | </pre> |
||
33 | |||
34 | h3. Input Parameters |
||
35 | |||
36 | * _orderId_ - the unique ID for the order |
||
37 | * _orderDescription_ - a simple description of the order |
||
38 | * _orderAmount_ - the settlement amount of the order in 2 decimal places, e.g. 12.34 |
||
39 | * _returnUrl_ - the receipt URL |
||
40 | |||
41 | h3. Output Parameters |
||
42 | |||
43 | Returns a <code>form</code> action URL |
||
44 | |||
45 | h3. Code Snippets |
||
46 | |||
47 | <pre> |
||
48 | <code class="JAVA"> |
||
49 | String orderId = request.getParameter("order-id"); |
||
50 | String orderDescription = request.getParameter("order-description"); |
||
51 | BigDecimal orderAmount = new BigDecimal(request.getParameter("order-amount")); |
||
52 | String returnUrl = request.getParameter("return-url"); |
||
53 | |||
54 | String formUrl = PaymentUtils.getFormActionUrl(orderId, |
||
55 | orderDescription, |
||
56 | orderAmount, |
||
57 | returnUrl); |
||
58 | </code> |
||
59 | </pre> |
||
60 | 6 | chin-yeh | |
61 | h2. Payment Status Callback |
||
62 | |||
63 | 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]]. |
||
64 | |||
65 | *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]]). |
||
66 | |||
67 | _Method Signature:_ |
||
68 | <pre> |
||
69 | <code class="JAVA"> |
||
70 | public static String queryAndPersistPaymentStatus(Connection dbConnection, HttpServletRequest servletRequest) |
||
71 | </code> |
||
72 | </pre> |
||
73 | |||
74 | h3. Input Parameters |
||
75 | |||
76 | * _dbConnection_ - an established database connection |
||
77 | * _servletRequest_ - <code>HttpServletRequest</code> object which will be used to obtain the request parameter, <code>token-id</code> |
||
78 | |||
79 | h3. Output Parameters |
||
80 | |||
81 | the <code>order ID</code> that used in the particular payment transaction |
||
82 | |||
83 | |||
84 | h3. Code Snippets |
||
85 | |||
86 | <pre> |
||
87 | <code class="JAVA"> |
||
88 | Connection connection = createDbConnection("java:/DB2DS_USA"); |
||
89 | String orderId = ""; |
||
90 | try { |
||
91 | orderId = PaymentUtils.queryAndPersistPaymentStatus(connection, request); |
||
92 | } finally { |
||
93 | if (connection != null) { |
||
94 | connection.close(); |
||
95 | } |
||
96 | } |
||
97 | </code> |
||
98 | </pre> |