developer:soap-1.2:howto:javajaxrpc

Java JAX-RPC Howto

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).

Downloads

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

Prerequisites

To follow this guide you must have:

To utilize the JAR you must have:

Installing Jax-RPC Plugin

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.

  • Select “Plugins” from the “Tools” menu
  • Search for “jax”
  • Select the Jax Plugin:

  • Click “Install”
  • Follow the prompts in the Installer

Step 1: Adding USAePay.jar to Project

  • Right click on “Libraries” within your project and choose “Add JAR/Folder”

  • Select the “USAePay.jar” file that was downloaded from one of the above packages
  • You should now have USAePay listed under your libraries

Step 2: Add Jax-RPC Library

  • Right click on “Libraries within your project and choose “Add Library”

  • Select “JAX-RPC (JWSDP 1.6)” and click “Add Library”

  • You should now have several Jax-Rpc jar files in your Libraries folder:

Step 3: Import com.usaepay.api Classes

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.*;

Step 4: Instantiate client Object

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");

Step 5: Generate Security Token

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) {
 
}

Step 6: Calling Soap Method

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());

Complete Example

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());
        }
 
 
    }
 
}
developer/soap-1.2/howto/javajaxrpc.txt · Last modified: 2010/06/01 11:39 by hmcgowan

Page Tools