Scenario 1: CFScript

From Intrannuity

Jump to: navigation, search

Download Source File

<cfscript>
	// Create Session component
	session = CreateObject( 'component', 'Session' );
	// Login
	session.login(2000, "password", "http://server.ibillingclient.org/ibilling/xmlhttps");
	// Create customer account
	customerAccount  = session.createCustomerAccount();
	// code is optinal; if you specify the value, make sure the code is unique
	customerAccount.setCode("cfs.ca-1");
	customerAccount.setMerchantAccountCode(2001);
	customerAccount.setFirstName("John");
	customerAccount.setLastName("Smith");
	customerAccount.setType(session.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  = customerAccount.createPaymentOption();
	// code is optinal; if you specify the value, make sure the code is unique
	paymentOption.setCode("cfs.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  = customerAccount.createPaymentPlan();
	// code is optinal; if you specify the value, make sure the code is unique
	paymentPlan.setCode("cfs.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(session.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(<Date>);
	paymentPlan.add(0, 12, false);
	//  Create invoice for downpayment
	revenueTransaction  = customerAccount.createRevenueTransaction();
	// code is optinal; if you specify the value, make sure the code is unique
	revenueTransaction.setCode("cfs.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(session.AccountActivityType().Invoice());
	// Create payment for downpayment
	transaction  = customerAccount.createAssetTransaction();
	// code is optinal; if you specify the value, make sure the code is unique
	transaction.setCode("cfs.at-1");
	// all amounts are in cents
	transaction.setAmount(10000);
	transaction.setTransactionType(session.AssetTransactionType().Cash());
	transaction.setAccountActivityType(session.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
		WriteOutput(ex.message);
		return ;
	}
	// Get info from customer account
	WriteOutput(customerAccount.getCode());
	WriteOutput(customerAccount.getFirstName());
	WriteOutput(customerAccount.getLastName());
	// Get info from payment option
	WriteOutput(paymentOption.getCode());
	WriteOutput(paymentOption.getAccessory());
	WriteOutput(paymentOption.getNumber());
	// Get info from payment plan
	WriteOutput(paymentPlan.getCode());
	WriteOutput(paymentPlan.getFirstBillingDate());
	WriteOutput(paymentPlan.getBillingCycleCode());
	// Get info from revenue transaction
	WriteOutput(revenueTransaction.getCode());
	WriteOutput(revenueTransaction.getAmount());
	WriteOutput(revenueTransaction.getAccountActivityType());
	// Get info from asset transaction
	WriteOutput(transaction.getCode());
	WriteOutput(transaction.getAmount());
	WriteOutput(transaction.getAccountActivityType());
	// logout
	session.logout();
 
 
</cfscript>

Download Source File

Personal tools