Java JAX-WS

The following guide demonstrates how to use the Swipebox-jaxws.jar package. This package contains a helper class for easily generating security tokens, classes for all Swipebox soap objects and a client service class for calling soap methods.

Downloads

File Version Release Date Description
usaepayapi-jaxws-1.6.4.zip 1.6.4 6/2/15 Library .jar and example .java
usaepayapi-jaxws-1.6.4.jar.zip 1.6.4 6/2/15 USAePayAPI-jaxws-1.6.jar only

Using Library

Step 1: Import com.Swipebox.api.jaxws Classes

In classes that are going to use the Swipebox soap methods or object, you need to import the appropriate classes from com.Swipebox.api.jaxws package. The following will import all Swipebox objects at once:

<span class="hljs-attribute">:::java</span>
import com.Swipebox.api.jaxws.<span class="hljs-strong">*;
</span>

Step 2: Instantiate client Object

All calls to the Swipebox 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:

<span class="hljs-attribute">:::java</span>
<span class="hljs-comment">// Instantiate client for production</span>
UeSoapServerPortType client = Swipebox.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).

<span class="hljs-attribute">:::java</span>
<span class="hljs-comment">// Instantiate client for sandbox</span>
UeSoapServerPortType client = Swipebox.getClient("sandbox.Swipebox.io");

Step 3: Generate Security Token

A "token" object (of type UeSecurityToken) is required by all soap methods in the Swipebox API. It is used to identify the merchant.

:::java
UeSecurityToken token = Swipebox.getToken(
"_Z0ji6VHHIzMR99PMgaf91FZxwC630mp", // source key. Make sure to <span class="hljs-operator"><span class="hljs-keyword">use</span> your source <span class="hljs-keyword">key</span> here
<span class="hljs-string">"1234"</span>, // source pin  (<span class="hljs-keyword">if</span> assigned <span class="hljs-keyword">by</span> merchant)
<span class="hljs-string">"127.0.0.1"</span>  // IP address <span class="hljs-keyword">of</span> <span class="hljs-keyword">end</span> client (<span class="hljs-keyword">if</span> applicable)
);</span>

Step 4: Calling a 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.

:::java
// instantiate TransactionRequestObject
TransactionRequestObject params = new TransactionRequestObject();

// <span class="hljs-built_in">set</span> card holder name
params.<span class="hljs-built_in">set</span>AccountHolder(<span class="hljs-string">"Test Joe"</span>);

// instantiate and populate transaction details
TransactionDetail details = new TransactionDetail();
details.<span class="hljs-built_in">set</span>Amount(<span class="hljs-number">22.34</span>);
details.<span class="hljs-built_in">set</span>Description(<span class="hljs-string">"My Test Sale"</span>);
details.<span class="hljs-built_in">set</span>Invoice(<span class="hljs-string">"119891"</span>);
params.<span class="hljs-built_in">set</span>Details(details);

// instantiate and populate credit card data
CreditCardData ccdata = new CreditCardData();
ccdata.<span class="hljs-built_in">set</span>CardNumber(<span class="hljs-string">"4111111111111111"</span>);
ccdata.<span class="hljs-built_in">set</span>CardExpiration(<span class="hljs-string">"0919"</span>);
params.<span class="hljs-built_in">set</span>CreditCardData(ccdata);

// instantiate and populate CustomFileds
// This example shows how <span class="hljs-keyword">to</span> <span class="hljs-built_in">set</span> gateway timeout
FieldValueArray FieldArray = new FieldValueArray();
FieldValue field1 = new FieldValue();
field1.<span class="hljs-built_in">set</span>Field(<span class="hljs-string">"UMtimeout"</span>);
field1.<span class="hljs-built_in">set</span>Value(<span class="hljs-string">"1"</span>);
FieldArray.getFieldValue().add(field1);
params.<span class="hljs-built_in">set</span>CustomFields(FieldArray);

// instantiate and populate LineItem
LineItemArray itemArray = new LineItemArray();
LineItem item1 = new LineItem();
item1.<span class="hljs-built_in">set</span>ProductName(<span class="hljs-string">"test"</span>);
item1.<span class="hljs-built_in">set</span>Description(<span class="hljs-string">"testdesc"</span>);
item1.<span class="hljs-built_in">set</span>SKU(<span class="hljs-string">"4214124"</span>);
item1.<span class="hljs-built_in">set</span>UnitPrice(<span class="hljs-string">"2"</span>);
item1.<span class="hljs-built_in">set</span>Qty(<span class="hljs-string">"5"</span>);
itemArray.getItem().add(item1);

LineItem item2 = new LineItem();
item2.<span class="hljs-built_in">set</span>ProductName(<span class="hljs-string">"test2"</span>);
item2.<span class="hljs-built_in">set</span>Description(<span class="hljs-string">"testdesc2"</span>);
item2.<span class="hljs-built_in">set</span>SKU(<span class="hljs-string">"5326236"</span>);
item2.<span class="hljs-built_in">set</span>UnitPrice(<span class="hljs-string">"3"</span>);
item2.<span class="hljs-built_in">set</span>Qty(<span class="hljs-string">"5"</span>);
itemArray.getItem().add(item2);

params.<span class="hljs-built_in">set</span>LineItems(itemArray);

// Create response object
TransactionResponse response;

// run sale
response = client.runSale(token, params);

// Display response
System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"Response: "</span> + response.getResult() + <span class="hljs-string">" RefNum: "</span> + response.getRefNum()
+ <span class="hljs-string">" Error: "</span> + response.getError());

} catch (Exception e) {

System.<span class="hljs-keyword">out</span>.println(<span class="hljs-string">"Soap Exception: "</span> + e.getMessage());

Additional Documentation

For additional documentation please see the main Soap API v1.6 Documentation. It includes a description of all methods and their parameters as well as examples for the java library.

For questions please email mailto:devsupport@swipebox.io

 

For inquiries contact us at (720) 277-0648