Home > Java Client > API for the Java SDK


API for the Java SDK

This section describes the classes and class members that you use to send and receive CyberSource requests and replies. For information about all the classes in the SDK, see the Javadoc found in the doc directory of the SDK.

ICSClient

Declaration

public class ICSClient

extends java.lang.Object

implements java.io.Serializable

Description

The ICSClient class sends the application request to CyberSource for processing.

Using Multiple Merchant IDs

You can use one instance of ICSClient to send multiple requests that use different merchant IDs (for example, you might have a different merchant ID for each currency you use).

In previous versions of the SDK, you had to destroy the ICSClient object and instantiate a new one to use a different merchant ID. Starting with version 3.7.1, you need only one ICSClient instance, and you specify the merchant ID in the request itself.

Adding Properties to the Request

Each request requires basic properties, such as your certificate and private key. You can add the properties to the request in different ways, depending on your preference. Each ICSClient constructor adds the properties to the request differently.

Starting with version 3.7.1 of the SDK, all properties in the ICSClient.props file are optional and act as default values for some of the request fields. If you do not include values for these fields in the properties file, then you must include values in the request itself, or accept the default values.

For more information, see Setting Properties in ICSClient.props.

Constructors

ICSClient()

public ICSClient()

The default constructor creates an instance with no default properties. Use this constructor when you want to supply all necessary information in the request message itself.

Throws

ICSConfigException — when a problem occurs with any of the property values

ICSClient(String)

public ICSClient(String propsFilename)

This constructor loads the properties file from the specified properties filename.

Parameter

propsFilename — the properties filename

Throws

ICSConfigException — when a problem occurs with any of the property values

ICSClient(Properties)

public ICSClient(Properties properties)

This constructor takes a Properties object for initialization. The Properties object must contain the properties listed in ICSClient.props.

Parameter

properties — the properties object containing the properties from the ICSClient.props file

Throws

ICSConfigException — when a problem occurs with any of the property values

The following examples illustrate two ways to use this constructor:

Example      loading properties from the ICSClient.props file

Properties props = new Properties();

props.load(new FileInputStream(newFile("/opt/java_sdk_ics_n.n.n/

    ics_n.n.n/properties/ICSClient.props")));

ICSClient client = new ICSClient(props);

Example      setting properties in code

Properties props = new Properties();

props.setProperty("myPrivateKey", "/home/icsuser/keys/

    MyMerchant.pvt");

props.setProperty("myCert", "/home/icsuser/keys/MyMerchant.crt");

props.setProperty("serverCert", "home/icsuser/keys/

    CyberSource_SJC_US.crt");

props.setProperty("merchantID", "MyMerchant");

props.setProperty("serverName", "CyberSource_SJC_US");

ICSClient client = new ICSClient(props);

ICSClient includes two additional constructors that are not recommended for use because they prevent the use of other default parameters, such as timeout and retry_enabled.

Method

send(ICSClientRequest)

public ICSReply send(ICSClientRequest request)

Sends the request to the CyberSource server and returns the reply in the form of an ICSReply object.

Parameter

request — the request

Throws

ICSConfigException — when a problem occurs with any of the property values

RequestMessageException — when an error occurs when creating or sending the request

ICSMessageParseException — when an error occurs when parsing the request data

ReplyMessageException — when an error occurs when decrypting or reading the reply

For more details about these exceptions, see Handling Exceptions.

Three of the four exceptions have subclasses that provide greater detail to help troubleshoot where in the code the error occurs. See the Javadoc in the doc/ directory of the SDK for more information.

Example      sending a request to the CyberSource server

ICSReply reply = client.send(request);

ICSClientRequest

Declaration

public class ICSClientRequest

extends ICSRequest (which extends ICSMessage)

implements java.io.Serializable

Description

The ICSClientRequest class stores all the information in a request.

Constructor

ICSClientRequest()

public ICSClientRequest()

Use the default constructor to create an ICSClientRequest object.

Throws

ICSException — the base class for all CyberSource exceptions

Methods

 

The ICSClientRequest convenience methods have been deprecated. Use the setField method instead.

setField(String, String)

public void setField(String name, String value)

Use the setField(String, String) method (inherited from the ICSRequest class) to assign values to the fields in the request.

Parameters

nname — name of the request field

nvalue — value for the request field

Example      setting fields in the request

request.setField("ics_applications", "ics_auth");

addOffer(ICSOffer)

public void addOffer(ICSOffer i)

Use the addOffer(ICSOffer) method (inherited from the ICSRequest class) to add an offer to a request message.

Parameter

i — the offer

Example      adding an offer to the request

request.addOffer(offer);

ICSClientOffer

Declaration

public class ICSClientOffer

extends ICSOffer (which extends ICSMessage)

Description

The ICSClientOffer class stores all the information in an offer, such as the product name, quantity, and cost.

Constructor

ICSClientOffer()

public ICSClientOffer()

Use the default constructor to create an ICSClientOffer object.

Method

 

The ICSClientOffer convenience methods have been deprecated. Use the setField method instead.

setField(String, String)

public void setField(String name, String value)

Use the setField(String, String) method (inherited from the ICSMessage class) to assign values to the fields in the offer.

Parameters

nname — name of the offer field

nvalue — value of the offer field

Example      Setting Fields in an Offer

offer.setField("amount", "14.95");

ICSReply

Declaration

public class ICSReply

extends ICSMessage

implements java.lang.Cloneable

Description

The ICSReply class stores the reply information you receive after the request is sent to CyberSource.

Example      using an ICSReply object to receive a reply

ICSReply reply = client.send(request);

Method

getField(String)

public String getField(String field)

This method (inherited from ICSMessage) returns the value of the specified field. Use it to evaluate the fields contained in the reply.

Parameter

field — the field name

Example      getting the value of the reply flag

String rflag = reply.getField("ics_rflag");