Scenario 2: C

From Intrannuity

Jump to: navigation, search

Download Source File

using System;
using System.Collections.Generic;
 
using iBilling.Client;
 
namespace iBilling.Samples
{
 
public class Scenario2
{
 
	public  static void Main(string[] args){
	//Set up clients' settings;
	Dictionary<string, object> config = new Dictionary<string, object>();
	config[SessionConnection.PROCESSOR_HOST] = "http://server.ibillingclient.org/ibilling/xmlhttps";
	config[SessionConnection.PAYMENT_OPTION_VERIFICATION_AMOUNT] = 99;
	config["debug"] = true;
	//Login;
	Session session = Session.Login(2000, "welcome", config);
	//Create customer account;
	CustomerAccount customerAccount = session.CreateCustomerAccount();
	//code is optinal; if you specify the value, make sure the code is unique;
	customerAccount.Code = "csharp.ca-2";
	customerAccount.MerchantAccountCode = 2001;
	customerAccount.FirstName = "John";
	customerAccount.LastName = "Smith";
	customerAccount.Type = CustomerAccountTypes.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 paymentOption = customerAccount.CreatePaymentOption();
	//code is optinal; if you specify the value, make sure the code is unique;
	paymentOption.Code = "csharp.po-2";
	paymentOption.HolderName = "John Smith";
	paymentOption.Number = "1000121279381";
	//routing number;
	paymentOption.Accessory = "610000227";
	paymentOption.Type = PaymentOptionTypes.Checking;
	paymentOption.Street1 = "233 12th Street";
	paymentOption.City = "Columbus";
	paymentOption.State = "CA";
	paymentOption.ZipCode = "31909";
	//Create payment plan;
	PaymentPlan paymentPlan = customerAccount.CreatePaymentPlan();
	//code is optinal; if you specify the value, make sure the code is unique;
	paymentPlan.Code = "csharp.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 = PaymentPlanTypes.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 = <DateTime>;
	paymentPlan.PaymentOption = paymentOption;
	//Create invoice for downpayment;
	RevenueTransaction revenueTransaction = customerAccount.CreateRevenueTransaction();
	//code is optinal; if you specify the value, make sure the code is unique;
	revenueTransaction.Code = "csharp.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 = AccountActivityTypes.Invoice;
	//Create payment for downpayment;
	AssetTransaction transaction = customerAccount.CreateAssetTransaction();
	//code is optinal; if you specify the value, make sure the code is unique;
	transaction.Code = "csharp.at-2";
	//all amounts are in cents;
	transaction.Amount = 5000;
	transaction.TransactionType = AssetTransactionTypes.Visa;
	//Credit card number to charge;
	transaction.AccountNumber = "4111111111111111";
	//Credit card expiration date;
	transaction.Accessory = "1209";
	//Type of transaction;
	transaction.AccountActivityType = AccountActivityTypes.Payment;
	//Add processing specific info (for better qualification rates;
	CaptureInfo 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;
		Console.WriteLine(ex.Message);
		return ;
	}
	//Get info from customer account;
	Console.WriteLine(customerAccount.Code);
	Console.WriteLine(customerAccount.FirstName);
	Console.WriteLine(customerAccount.LastName);
	Console.WriteLine(customerAccount.CreateDate);
	//Get info from payment option;
	Console.WriteLine(paymentOption.Code);
	Console.WriteLine(paymentOption.Accessory);
	Console.WriteLine(paymentOption.Number);
	Console.WriteLine(paymentOption.CreateDate);
	//Get info from payment plan;
	Console.WriteLine(paymentPlan.Code);
	Console.WriteLine(paymentPlan.FirstBillingDate);
	Console.WriteLine(paymentPlan.BillingCycleCode);
	Console.WriteLine(paymentPlan.CreateDate);
	//Get info from revenue transaction;
	Console.WriteLine(revenueTransaction.Code);
	Console.WriteLine(revenueTransaction.Amount);
	Console.WriteLine(revenueTransaction.AccountActivityType);
	Console.WriteLine(revenueTransaction.CreateDate);
	//Get info from asset transaction;
	Console.WriteLine(transaction.Code);
	Console.WriteLine(transaction.Accessory);
	Console.WriteLine(transaction.AccountNumber);
	Console.WriteLine(transaction.CreateDate);
	//Get info from capture info;
	Console.WriteLine(captureInfo.ReturnType);
	Console.WriteLine(captureInfo.ApprovalCode);
	Console.WriteLine(captureInfo.ReferenceNumber);
	//logout;
	session.Logout();
	}
}
}
Personal tools