Home > Java Client


Java Client

 

The SCMP API clients are supported on 32-bit operating systems only.

Basic Java Program Example

Create a Java program to access CyberSource services. The example below shows the basic code required to send a request for credit card authorization and process the reply.

import com.cybersource.ics.client.*;

import com.cybersource.ics.client.message.*;

import com.cybersource.ics.base.message.*;

import com.cybersource.ics.base.exception.*;

import java.io.*;

import java.util.Properties;

 

public class CCAuthExample

{

public static void main(String[] args)

throws IOException, ICSException

{

// load basic properties from ICSClient.props file

Properties props = new Properties();

 

String propsfile = "/home/icsuser/CyberSource/ics_n.n.n/

properties/ICSClient.props";

props.load(new FileInputStream(new File(propsfile)));

 

// create a client for CyberSource to send requests

ICSClient client = new ICSClient(props);

 

 

// create a request to hold customer information

ICSClientRequest request = new ICSClientRequest();

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

request.setField("customer_cc_number", "411111111111111");

request.setField("customer_cc_expmo", "12");

request.setField("customer_cc_expyr", "05");// set more fields as necessary

// (not all required fields shown here)

// create an offer to hold product information

ICSClientOffer offer = new ICSClientOffer();

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

offer.setField("quantity", "1");

request.addOffer(offer);

// send the request to CyberSource and receive the reply

ICSReply reply = client.send(request);

 

// get and handle the reply code and reply flag

int rcode = reply.getReplyCode();

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

if (rcode < 0) {

// Error occurred;

// Notify customer that an error occurred,

// and ask customer to try again.

}

else if (rcode == 0) {

// Request declined

// Evaluate reply flag for reason why request was declined

if ("DINVALIDDATA".equals(rflag)) {

// Notify customer that request included invalid data;

// Ask to correct error and resubmit request.

}

else if ("DCARDREFUSED".equals(rflag)) {

// For cards declined by the bank.

// Notify customer unable to process order.

}

else {

// Handle remaining possible declined reply flags here.

// Write error handler to process

// new reply flags created by CyberSource.

}

}

else {

// Successful transaction;

// perform any local processing, and

// notify customer of success.

}

}

}