Programming Guide » History » Revision 20
« Previous |
Revision 20/21
(diff)
| Next »
chin-yeh, 11/01/2011 11:47 AM
- Table of contents
- Programming Guide
Programming Guide¶
This guide describes how to make use of the NMI APIs for payment related transaction and it consists of 2 main parts:- Step-By-Step - describes how to integrate the NMI payment gateway
- API Reference - the detailed description of all the APIs mentioned in Step-By-Step
The demo application can be found here:
Step-By-Step¶
Before begin, install the following libraries into your development environment (remove the old versions if exists):
See also Payment Flow
- To get the form URL, pass the required parameters to getFormActionUrl method.
- Use the form URL (in which obtained in the previous step) to construct the payment form with the following
input
elements:- billing-cc-number
- billing-cc-exp
- cvv
- billing-first-name
- billing-last-name
- billing-address1
- billing-city
- billing-state
- billing-postal
- billing-country
- billing-phone
- billing-email
- Example:
- Example:
- Notes: the URL of this payment form should be HTTPS
- Notes: the length of the input fields should be less than 99 characters
- Validate all of the fields in the form using JavaScript (do not use server-side validation). Then, the payment form will be submitted directly to the payment gateway and the user will be redirected to the receipt page, which specified in the previous step.
- The redirect URL will contains the token-id query parameter. But the method, queryAndPersistPaymentStatus will extract the parameter on your behalf, therefore, just pass in the request object to the method.
- Use the order ID that returned by the method, queryAndPersistPaymentStatus to get the payment status in the Interface table. In certain scenarios, NMI will not return the order ID.
- The content of the receipt page is depends on the result of payment.
- done.
Generate the form action URL¶
Generates the form
action URL which is needed in the self-hosted payment form.
Method Signature:
public static String getFormActionUrl(String orderId, String orderDescription, BigDecimal orderAmount, String returnUrl)
Input Parameters¶
- orderId - the unique ID for the order
- orderDescription - a simple description of the order
- orderAmount - the settlement amount of the order in 2 decimal places, e.g. 12.34
- returnUrl - the receipt URL
Output Parameters¶
Returns a form
action URL
Code Snippets¶
String orderId = request.getParameter("order-id"); String orderDescription = request.getParameter("order-description"); BigDecimal orderAmount = new BigDecimal(request.getParameter("order-amount")); String returnUrl = request.getParameter("return-url"); String formUrl = PaymentUtils.getFormActionUrl(orderId, orderDescription, orderAmount, returnUrl);
Payment Status Callback¶
Queries the payment status using the token ID
that returned by NMI. After obtained the payment status, update the particular record in the Interface table.
Important: This method is supposed to be placed and invoked in the very beginning of the receipt page, (a.k.a. the returnUrl
that specified in Generate form action URL).
Method Signature:
public static String queryAndPersistPaymentStatus(Connection dbConnection, HttpServletRequest servletRequest)
Input Parameters¶
- dbConnection - an established database connection
- servletRequest -
HttpServletRequest
object which will be used to obtain the request parameter,token-id
Output Parameters¶
the order ID
that used in the particular payment transaction
Code Snippets¶
Connection connection = createDbConnection("java:/DB2DS_USA"); String orderId = ""; try { orderId = PaymentUtils.queryAndPersistPaymentStatus(connection, request); } finally { if (connection != null) { connection.close(); } }
Updated by chin-yeh about 13 years ago · 20 revisions