Scenario 2: Java

From Intrannuity

Jump to: navigation, search

Download Source File

<code> import ibilling.client.*
import java.util.*

public class Scenario1 {

  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");
    //Amount to be used for test transactions that are processed to validate new payment options; optional
    config.put(SessionConnection.PAYMENT_OPTION_VERIFICATION_AMOUNT, 99);
    //Set the value to true to view XML exchanged between your client and the server
    config.put(SessionConnection.DEBUG, true);
    //Data for increased fraud protection, all of these values are optional
    //Domain name of user's e-mail (user on behalf of whom the transaction is processed)
    config.put(SessionConnection.CLIENT_EMAIL_DOMAIN, "hotmail.com");
    //IP Address of the user's machine (user on behalf of whom the transaction is processed)
    config.put(SessionConnection.CLIENT_IP_ADDRESS, "145.21.0.1");
    //Full e-mail address of the user as MD5 (user on behalf of whom the transaction is processed)
    config.put(SessionConnection.CLIENT_EMAIL_ENCODED, "8d89c3087cc6cb98793ab7c0f5658c56");
    //Full user name of the user as MD5 (user on behalf of whom the transaction is processed)
    config.put(SessionConnection.CLIENT_USER_NAME_ENCODED, "435e0648d634175c46bd40ac366545a8");
    //Password of the user as MD5 (user on behalf of whom the transaction is processed)
    config.put(SessionConnection.CLIENT_PASSWORD_ENCODED, "5f4dcc3b5aa765d61d8327deb882cf99");
    //Login
    Session session  = Session.login(2000"welcome", config);
    //Create customer account
    CustomerAccount customerAccount  = session.createCustomerAccount();
    //code is optinal; if you specify the value, make sure the code is unique
    customerAccount.setCode("java.ca-1");
    customerAccount.setMerchantAccountCode(2001);
    customerAccount.setFirstName("John");
    customerAccount.setLastName("Smith");
    customerAccount.setType(CustomerAccountType.Male);
    customerAccount.setHomePhone("2129856472");
    customerAccount.setEmail("test@yahoo.com");
    customerAccount.setStreet1("233 12th Street");
    customerAccount.setCity("Honolulu");
    customerAccount.setState("CA");
    customerAccount.setZipCode("31904");
    //Create payment option
    PaymentOption paymentOption  = customerAccount.createPaymentOption();
    //code is optinal; if you specify the value, make sure the code is unique
    paymentOption.setCode("java.po-1");
    paymentOption.setHolderName("John Smith");
    paymentOption.setNumber("4111111111111111");
    //expiration date
    paymentOption.setAccessory("1209");
    paymentOption.setStreet1("233 12th Street");
    paymentOption.setCity("Honolulu");
    paymentOption.setState("CA");
    paymentOption.setZipCode("31904");
    //Create payment plan
    PaymentPlan paymentPlan  = customerAccount.createPaymentPlan();
    //code is optinal; if you specify the value, make sure the code is unique
    paymentPlan.setCode("java.pp-1");
    //all amounts are in cents
    paymentPlan.setAmount(5000);
    //Item Codes must be setup in portal prior to being used
    paymentPlan.setItemCode("Membership");
    paymentPlan.setType(PaymentPlanType.Fixed);
    //Billing Cycle codes must be setup in portal prior to being used
    paymentPlan.setBillingCycleCode("M03");
    //Specify desired billing date; if nothing specified, next billing date of the selected cycle assumed.
    //paymentPlan.setFirstBillingDate(<java.util.Date>);
    paymentPlan.add(012false);
    // Create invoice for downpayment
    RevenueTransaction revenueTransaction  = customerAccount.createRevenueTransaction();
    //code is optinal; if you specify the value, make sure the code is unique
    revenueTransaction.setCode("java.rt-1");
    //all amounts are in cents
    revenueTransaction.setAmount(10000);
    //Item Codes must be setup in portal prior to being used
    revenueTransaction.setItemCode("Membership");
    //Type of transaction
    revenueTransaction.setAccountActivityType(AccountActivityType.Invoice);
    //Create payment for downpayment
    AssetTransaction transaction  = customerAccount.createAssetTransaction();
    //code is optinal; if you specify the value, make sure the code is unique
    transaction.setCode("java.at-1");
    //all amounts are in cents
    transaction.setAmount(10000);
    transaction.setTransactionType(AssetTransactionType.Cash);
    transaction.setAccountActivityType(AccountActivityType.Payment);
    //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;    }
    //Get info from customer account
    System.out.println(customerAccount.getCode());
    System.out.println(customerAccount.getFirstName());
    System.out.println(customerAccount.getLastName());
    //Get info from payment option
    System.out.println(paymentOption.getCode());
    System.out.println(paymentOption.getAccessory());
    System.out.println(paymentOption.getNumber());
    //Get info from payment plan
    System.out.println(paymentPlan.getCode());
    System.out.println(paymentPlan.getFirstBillingDate());
    System.out.println(paymentPlan.getBillingCycleCode());
    //Get info from revenue transaction
    System.out.println(revenueTransaction.getCode());
    System.out.println(revenueTransaction.getAmount());
    System.out.println(revenueTransaction.getAccountActivityType());
    //Get info from asset transaction
    System.out.println(transaction.getCode());
    System.out.println(transaction.getAmount());
    System.out.println(transaction.getAccountActivityType());
    //logout
    session.logout();

  }

}

Download Source File

Personal tools