A popular payment gateway service called PayFlow Pro is provided by VeriSign. PayFlow Pro's client-side component resides in the electronic storefront application. The client component interfaces with PayFlow Pro's servers owned by VeriSign. The PayFlow Pro client communicates with the PayFlow Pro servers, using HTTP
This example features a PayFlow Pro interface implemented with Java Servlets. On the client side, the PayFlow Pro Java object is wrapped into a Java Servlet. Figure 3-10 shows what the page looks like in the Web browser.
The following HTML code is from a sample HTML page that interfaces with the PayFlow Pro payment processing system and invokes the payment processing component:
<H1>Payment Gateway Interface</H1>
<p>
<form name=pfpro_form method=GET
action="https://payment.example.com/servlet/PFServlet/">
<table border=0>
<tr><td>Cart code</td><td><input type=text name=SHOPCART size=6></td></tr>
<tr><td>Credit Card number</td><td><input type=text name=CARDNUM size=16></td>
</tr>
<tr><td>Expiration date<br>(month/year)</td>
<td><input type=text name=EXPMONTH size=2>
<input type=text name=EXPYEAR size=2></td></tr>
</table>
<p><input type=submit value="Process payment">
</form>
The HTML page contains a form that invokes https://payment.example.com/servlet/PFServlet/. PFServlet invokes the PFPro Java object, which interfaces with the PayFlow Pro payment gateway. The HTML form accepts the following parameters:
|
Parameter |
Description |
|
SHOPCART |
Shopping cart code |
|
CARDNUM |
Customer's credit card number |
|
EXPMONTH |
Expiration month of credit card |
|
EXPYEAR |
Expiration year of credit card |
Each customer's shopping cart has a unique code associated with it. The PFServlet uses that code to process all the items in the shopping cart. Ideally, the shopping cart code is passed automatically to the payment processing system by the shopping cart session management system. The following is the code for the Java PFServlet.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.Signio.PFProAPI;
public class PFServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
PrintWrite rout;
PFProAPI pfObject = new PFProAPI();
String ver = pfObject.PNVersion();
// get HTML form parameters
String EXPMONTH = req.getParameter("EXPMONTH");
String EXPYEAR = req.getParameter("EXPYEAR");
String CARDNUM = req.getParameter("CARDNUM");
String SHOPCART = req.getParameter("SHOPCART");
String EXPDATE = EXPMONTH + EXPYEAR;
// calculate total amount from the shopping cart contents
String AMOUNT = CalculateTotalAmount(SHOPCART);
// Receive PayFlow Pro username and password credentials from
// a stored repository
String username = PFCredentials.getUserName();
String password = PFCredentials.getPassword();
// Server hosting PayFlowPro payment gateway
String HostAddress = "test.signio.com";
String HostPort = "443";
// Construct the parameter string to be passed to PayFlow Pro
String ParmList =
"TRXTYPE=S&TENDER=C&USER=" + username + "&PWD=" + password +
"&ACCT=" + CARDNUM + "&EXPDATE=" + EXPDATE + "&AMT=" + AMOUNT +
"&COMMENT1[10]=TestPay&INVNUM=1234567890&STREET=120+WIGGINS+ST
&ZIP=47907";
String Timeout = "30";
// Send request to process payment and receive a response
int rc = pfObject.ProcessTransaction(HostAddress, HostPort,
"", "", "", "", ParmList, Timeout);
// Write the result
res.setContentType("text/html");
out = res.getWriter();
// Customer response and receipt generation code goes here.
// At the very end, the transaction is written out to the database.
}
The com.signio.PFProAPI package provides the PayFlow Pro Java object API calls. This package is imported and placed within the PFServlet code.
Then the form parameters, described previously, passed to the PFServlet are
The next part of the code deals with setting up connection parameters for the payment gateway. First, the payment gateway credentials issued by PayFlow Pro to the merchant are retrieved from an internal repository. These credentials also can be hard-coded but doing so isn't good programming practice.
Next the server's IP address and port
The request for payment processing is then issued by the pfObject.ProcessTransaction() method. The variable "rc" stores the response code received from the PayFlow Pro's payment gateway server. Typically, all the processing—from the request to the response—occurs within a few seconds.
The rest of the servlet code generates the appropriate results based on the response code. If the payment is accepted, the servlet generates an order confirmation and a receipt and initiates the order fulfillment process. If the payment is