Scenario 9: Java
From Intrannuity
import ibilling.client.*
import java.util.*
public class Scenario9 {
public static void main(String[] args) {
//Set up clients' settings
Map<String, Object> config = new HashMap<String, Object>();
config.put(SessionConnection.PROCESSOR_HOST, "http://server.ibillingclient.org/ibilling/xmlhttps");
config.put("debug", true);
//Login
Session session = Session.login(2000, "welcome", config);
//Find customer account
CustomerAccount customerAccount = session.loadCustomerAccount("java.ca-2");
//Create invoice1
RevenueTransaction invoice1 = customerAccount.createRevenueTransaction();
//code is optinal; if you specify the value, make sure the code is unique
invoice1.setCode("java.rt-9-1");
//all amounts are in cents
invoice1.setAmount(2000);
//Item Codes must be setup in portal prior to being used
invoice1.setItemCode("T-Shirt");
//Type of transaction
invoice1.setAccountActivityType(AccountActivityType.Invoice);
//Create payment1
AssetTransaction payment1 = customerAccount.createAssetTransaction();
//code is optinal; if you specify the value, make sure the code is unique
payment1.setCode("java.at-9-1");
//all amounts are in cents
payment1.setAmount(2000);
payment1.setTransactionType(AssetTransactionType.Visa);
payment1.setAccountActivityType(AccountActivityType.Payment);
//Credit card number to charge
payment1.setAccountNumber("4111111111111111");
//Credit card expiration date
payment1.setAccessory("1209");
//Add processing specific info (for better qualification rates)
CaptureInfo captureInfo1 = payment1.getCaptureInfo();
captureInfo1.setHolderName("John Smith");
captureInfo1.setCity("Columbus");
captureInfo1.setState("CA");
captureInfo1.setStreet("233 12th Street");
captureInfo1.setZipCode("31909");
captureInfo1.setPhone("2129856472");
captureInfo1.setEmail("test@yahoo.com");
captureInfo1.setCvv2("999");
//Create invoice2
RevenueTransaction invoice2 = customerAccount.createRevenueTransaction();
//code is optinal; if you specify the value, make sure the code is unique
invoice2.setCode("java.rt-9-2");
//all amounts are in cents
invoice2.setAmount(1500);
//Item Codes must be setup in portal prior to being used
invoice2.setItemCode("T-Shirt");
//Type of transaction
invoice2.setAccountActivityType(AccountActivityType.Invoice);
//Create payment2
AssetTransaction payment2 = customerAccount.createAssetTransaction();
//code is optinal; if you specify the value, make sure the code is unique
payment2.setCode("java.at-9-2");
///all amounts are in cents
payment2.setAmount(1500);
payment2.setTransactionType(AssetTransactionType.Visa);
payment2.setAccountActivityType(AccountActivityType.Payment);
//Credit card number to charge
payment2.setAccountNumber("4111111111111111");
//Credit card expiration date
payment2.setAccessory("1209");
//Add processing specific info (for better qualification rates)
CaptureInfo captureInfo2 = payment2.getCaptureInfo();
captureInfo2.setHolderName("John Smith");
captureInfo2.setCity("Columbus");
captureInfo2.setState("CA");
captureInfo2.setStreet("233 12th Street");
captureInfo2.setZipCode("31909");
captureInfo2.setPhone("2129856472");
captureInfo2.setEmail("test@yahoo.com");
captureInfo2.setCvv2("999");
//Mark object for persistence
session.save(customerAccount);
//Synchronize changes with the server
try{
session.synchronize();
}
catch(Exception ex){
//Be sure to properly handle exception, this is just a sample solution
System.out.println(ex.getMessage());
return; }
//Logout
session.logout();
}
}
