Scenario 5: Java

From Intrannuity

Jump to: navigation, search

Download Source File

import ibilling.client.*
import java.util.*

public class Scenario5 {

  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);
    //execute find payment plan
    PaymentPlan paymentPlan  = session.loadPaymentPlan("java.pp-3");
    Charge charge  = paymentPlan.getCharges().get(1);
    charge.setIsPrepaid(true);
    //get customer account
    CustomerAccount customerAccount  = paymentPlan.getCustomerAccount();
    //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-5");
    //all amounts are in cents
    transaction.setAmount(3000);
    //Type of transaction
    transaction.setAccountActivityType(AccountActivityType.Payment);
    transaction.setTransactionType(AssetTransactionType.Check);
    //check number
    transaction.setAccountNumber("10100125687");
    transaction.setIsPrepayment(true);
    transaction.setDueDate(charge.getBillingDate());
    //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();

  }

}


Download Source File

Personal tools