The following guide demonstrates how to use the USAePay-jaxrpc.jar package. This package contains a helper class for easily generating security tokens, classes for all USAePay soap objects and a client service class for calling soap methods. The package requires Jax-RPC (see prerequisites). In this guide we include instructions on how to implement the jar using the NetBeans IDE. You can still use the jar without NetBeans but you will need to satisfy the Jax-RPC dependancy (see troubleshooting).
File | Version | Release Date | Description |
---|---|---|---|
usaepayapi-jaxrpc-1.2.0.zip | 1.2.0 | 8/25/09 | Zip containing the USAePay.jar and an example NetBeans project |
usaepay-jaxrpc-1.2.0.jar.zip | 1.2.0 | 8/25/09 | USAePay.jar by itself |
main.java.zip | - | 8/25/09 | Example use of USAePay.jar |
To follow this guide you must have:
To utilize the JAR you must have:
To utilize the RPC/Encoded version of the USAePay wsdl, which is the default version, you need to install the Jax-RPC plugin for NetBeans.
In classes that are going to use the USAePay soap methods or object, you need to import the appropriate classes from com.usaepay.api package. The following will import all usaepay objects at once:
import com.usaepay.api.*;
All calls to the USAePay soap servers are handled by a “client” object of type “UeSoapServerPortType”. There are two ways to instantiate the client object. To instantiate a client for use with the main production servers:
// Instantiate client for production UeSoapServerPortType client = usaepay.getClient();
Alternately, you can specify a server hostname, which will allow you to setup a connection to the sandbox server for testing or a backup datacenter (see the high availability programming guide).
// Instantiate client for sandbox UeSoapServerPortType client = usaepay.getClient("sandbox.usaepay.com");
A “token” object (of type UeSecurityToken) is required by all soap methods in the USAePay API. It is used to identify the merchant.
// Create security token try{ String SourceKey="YourKeyGoesHere"; String Pin ="YourPinGoesHere"; String ClientIP="10.10.10.10"; UeSecurityToken token = usaepay.getToken(SourceKey, Pin, ClientIP); } catch(Exception e) { }
Soap methods are called using the client object. Below is an example for calling the runSale method. For further examples see the soap api documentation.
TransactionRequestObject request = new TransactionRequestObject(); request.setAccountHolder("Tester John"); TransactionDetail details = new TransactionDetail(); details.setAmount(12.30); details.setDescription("Example Sale"); request.setDetails(details); CreditCardData ccdata = new CreditCardData(); ccdata.setAvsStreet("1234 Main"); ccdata.setAvsZip("12345"); ccdata.setCardNumber("4444555566667779"); ccdata.setCardExpiration("0909"); request.setCreditCardData(ccdata); TransactionResponse response; response = client.runSale(token, request); System.out.println("Response: " + response.getResult() + " RefNum: " + response.getRefNum());
The following is a example class that puts together all of the steps above.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package example; import com.usaepay.api.*; /** * * @author Administrator */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here // Instantiate client for production UeSoapServerPortType client = usaepay.getClient(); // Create security token try{ String SourceKey="YourKeyGoesHere"; String Pin ="YourPinGoesHere"; String ClientIP="10.10.10.10"; UeSecurityToken token = usaepay.getToken(SourceKey, Pin, ClientIP); TransactionRequestObject request = new TransactionRequestObject(); request.setAccountHolder("Tester John"); TransactionDetail details = new TransactionDetail(); details.setAmount(12.30); details.setDescription("Example Sale"); request.setDetails(details); CreditCardData ccdata = new CreditCardData(); ccdata.setAvsStreet("1234 Main"); ccdata.setAvsZip("12345"); ccdata.setCardNumber("4444555566667779"); ccdata.setCardExpiration("0909"); request.setCreditCardData(ccdata); TransactionResponse response; response = client.runSale(token, request); System.out.println("Response: " + response.getResult() + " RefNum: " + response.getRefNum()); } catch(Exception e) { System.out.println("Received exception: "+ e.getMessage()); } } }