Scenario 10: PHP

From Intrannuity

Jump to: navigation, search

Download Source File

<?php
 
 
require_once "lib/iBilling.php";
 
	//Set up clients' settings
	$config = new HashMap();
	$config->put(SessionConnection::PROCESSOR_HOST, "http://server.ibillingclient.org/ibilling/xmlhttps");
	$config->put("debug", true);
	//Login
	$session = Session::login(2000, "welcome", $config);
	//Find customer account
	$customerAccount = $session->loadCustomerAccount("php.ca-1");
	//Create invoice for downpayment
	$revenueTransaction = $customerAccount->createRevenueTransaction();
	//code is optinal; if you specify the value, make sure the code is unique
	$revenueTransaction->setCode("php.rt-10");
	//all amounts are in cents
	$revenueTransaction->setAmount(5000);
	//Item Codes must be setup in portal prior to being used
	$revenueTransaction->setItemCode("NutritionPack");
	//Type of transaction
	$revenueTransaction->setAccountActivityType(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("php.at-10");
	//all amounts are in cents
	$transaction->setAmount(5000);
	$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
		print($ex->getMessage());
		return ;
	}
	//logout
	$session->logout();
 
 
 
?>
Personal tools