Scenario 2: Groovy

From Intrannuity

Jump to: navigation, search

Download Source File

import ibilling.client.*
 
class Scenario2 {
 
 static void main(args) {
			//Set up clients' settings
	def config  = [:]
	config[SessionConnection.PROCESSOR_HOST] = "http://server.ibillingclient.org/ibilling/xmlhttps"
	config[SessionConnection.PAYMENT_OPTION_VERIFICATION_AMOUNT] = 99
	config["debug"] = true
	//Login
	def session  = Session.login(2000, "welcome", config)
	//Create customer account
	def customerAccount  = session.createCustomerAccount()
	//code is optinal; if you specify the value, make sure the code is unique
	customerAccount.code = "groovy.ca-2"
	customerAccount.merchantAccountCode = 2001
	customerAccount.firstName = "John"
	customerAccount.lastName = "Smith"
	customerAccount.type = CustomerAccountType.Male
	customerAccount.homePhone = "2129856472"
	customerAccount.email = "test@yahoo.com"
	customerAccount.street1 = "233 12th Street"
	customerAccount.city = "Columbus"
	customerAccount.state = "NY"
	customerAccount.zipCode = "31909"
	//Create payment option
	def paymentOption  = customerAccount.createPaymentOption()
	//code is optinal; if you specify the value, make sure the code is unique
	paymentOption.code = "groovy.po-2"
	paymentOption.holderName = "John Smith"
	paymentOption.number = "1000121279381"
	//routing number
	paymentOption.accessory = "610000227"
	paymentOption.type = PaymentOptionType.Checking
	paymentOption.street1 = "233 12th Street"
	paymentOption.city = "Columbus"
	paymentOption.state = "CA"
	paymentOption.zipCode = "31909"
	//Create payment plan
	def paymentPlan  = customerAccount.createPaymentPlan()
	//code is optinal; if you specify the value, make sure the code is unique
	paymentPlan.code = "groovy.pp-2"
	//all amounts are in cents
	paymentPlan.amount = 1000
	//Item Codes must be setup in portal prior to being used
	paymentPlan.itemCode = "Membership"
	paymentPlan.type = PaymentPlanType.Perpetual
	//Billing Cycle codes must be setup in portal prior to being used
	paymentPlan.billingCycleCode = "W01"
	//Specify desired billing date; if nothing specified, next billing date of the selected cycle assumed.
	//paymentPlan.firstBillingDate = date
	paymentPlan.paymentOption = paymentOption
	//Create invoice for downpayment
	def revenueTransaction  = customerAccount.createRevenueTransaction()
	//code is optinal; if you specify the value, make sure the code is unique
	revenueTransaction.code = "groovy.rt-2"
	//ll amounts are in cents
	revenueTransaction.amount = 5000
	//Item Codes must be setup in portal prior to being used
	revenueTransaction.itemCode = "Membership"
	//Type of transaction
	revenueTransaction.accountActivityType = AccountActivityType.Invoice
	//Create payment for downpayment
	def transaction  = customerAccount.createAssetTransaction()
	//code is optinal; if you specify the value, make sure the code is unique
	transaction.code = "groovy.at-2"
	//all amounts are in cents
	transaction.amount = 5000
	transaction.transactionType = AssetTransactionType.Visa
	//Credit card number to charge
	transaction.accountNumber = "4111111111111111"
	//Credit card expiration date
	transaction.accessory = "1209"
	//Type of transaction
	transaction.accountActivityType = AccountActivityType.Payment
	//Add processing specific info (for better qualification rates
	def captureInfo  = transaction.captureInfo
	captureInfo.holderName = "John Smith"
	captureInfo.city = "Columbus"
	captureInfo.state = "CA"
	captureInfo.street = "233 12th Street"
	captureInfo.zipCode = "31909"
	captureInfo.phone = "2129856472"
	captureInfo.email = "test@yahoo.com"
	captureInfo.cvv2 = "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
		println(ex.message)
		return ;
	}
	//Get info from customer account
	println(customerAccount.code)
	println(customerAccount.firstName)
	println(customerAccount.lastName)
	println(customerAccount.createDate)
	//Get info from payment option
	println(paymentOption.code)
	println(paymentOption.accessory)
	println(paymentOption.number)
	println(paymentOption.createDate)
	//Get info from payment plan
	println(paymentPlan.code)
	println(paymentPlan.firstBillingDate)
	println(paymentPlan.billingCycleCode)
	println(paymentPlan.createDate)
	//Get info from revenue transaction
	println(revenueTransaction.code)
	println(revenueTransaction.amount)
	println(revenueTransaction.accountActivityType)
	println(revenueTransaction.createDate)
	//Get info from asset transaction
	println(transaction.code)
	println(transaction.accessory)
	println(transaction.accountNumber)
	println(transaction.createDate)
	//Get info from capture info
	println(captureInfo.returnType)
	println(captureInfo.approvalCode)
	println(captureInfo.referenceNumber)
	//logout
	session.logout()
 
	}
 
}