Scenario 2: Ruby

From Intrannuity

Jump to: navigation, search

Download Source File

require "lib/iBilling"
 
	#Set up clients' settings
	config = Map.new
	config.put(SessionConnection::PROCESSOR_HOST, "http://server.ibillingclient.org/ibilling/xmlhttps")
	config.put(SessionConnection::PAYMENT_OPTION_VERIFICATION_AMOUNT, 99)
	config.put("debug", true)
	#Login
	session = Session::login(2000, "welcome", config)
	#Create customer account
	customerAccount = session.createCustomerAccount()
	#code is optinal; if you specify the value, make sure the code is unique
	customerAccount.code = "rb.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
	paymentOption = customerAccount.createPaymentOption()
	#code is optinal; if you specify the value, make sure the code is unique
	paymentOption.code = "rb.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
	paymentPlan = customerAccount.createPaymentPlan()
	#code is optinal; if you specify the value, make sure the code is unique
	paymentPlan.code = "rb.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
	revenueTransaction = customerAccount.createRevenueTransaction()
	#code is optinal; if you specify the value, make sure the code is unique
	revenueTransaction.code = "rb.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
	transaction = customerAccount.createAssetTransaction()
	#code is optinal; if you specify the value, make sure the code is unique
	transaction.code = "rb.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
	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
	begin
		session.synchronize()
	rescue Exception => ex
		#Be sure to properly handle exception, this is just a sample solution
		puts(ex.message)
		return 
	end
	#Get info from customer account
	puts(customerAccount.code)
	puts(customerAccount.firstName)
	puts(customerAccount.lastName)
	puts(customerAccount.createDate)
	#Get info from payment option
	puts(paymentOption.code)
	puts(paymentOption.accessory)
	puts(paymentOption.number)
	puts(paymentOption.createDate)
	#Get info from payment plan
	puts(paymentPlan.code)
	puts(paymentPlan.firstBillingDate)
	puts(paymentPlan.billingCycleCode)
	puts(paymentPlan.createDate)
	#Get info from revenue transaction
	puts(revenueTransaction.code)
	puts(revenueTransaction.amount)
	puts(revenueTransaction.accountActivityType)
	puts(revenueTransaction.createDate)
	#Get info from asset transaction
	puts(transaction.code)
	puts(transaction.accessory)
	puts(transaction.accountNumber)
	puts(transaction.createDate)
	#Get info from capture info
	puts(captureInfo.returnType)
	puts(captureInfo.approvalCode)
	puts(captureInfo.referenceNumber)
	#logout
	session.logout()


Download Source File

Personal tools