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