From Intrannuity
Download Source File
#include "stdafx.h"
using namespace System;
using namespace System::Collections::Generic;
using namespace iBilling::Client;
int Scenario1(array<System::String ^> ^args)
{
//Set up clients' settings;
Dictionary<String^, Object^>^ config = gcnew Dictionary<String^, Object^>();
config[SessionConnection::PROCESSOR_HOST] = "http://server.ibillingclient.org/ibilling/xmlhttps";
//Amount to be used for test transactions that are processed to validate new payment options; optional;
config[SessionConnection::PAYMENT_OPTION_VERIFICATION_AMOUNT] = 99;
//Set the value to true to view XML exchanged between your client and the server;
config[SessionConnection::DEBUG] = true;
//Data for increased fraud protection, all of these values are optional;
//Domain name of user's e-mail (user on behalf of whom the transaction is processed);
config[SessionConnection::CLIENT_EMAIL_DOMAIN] = "hotmail.com";
//IP Address of the user's machine (user on behalf of whom the transaction is processed);
config[SessionConnection::CLIENT_IP_ADDRESS] = "145.21.0.1";
//Full e-mail address of the user as MD5 (user on behalf of whom the transaction is processed);
config[SessionConnection::CLIENT_EMAIL_ENCODED] = "8d89c3087cc6cb98793ab7c0f5658c56";
//Full user name of the user as MD5 (user on behalf of whom the transaction is processed);
config[SessionConnection::CLIENT_USER_NAME_ENCODED] = "435e0648d634175c46bd40ac366545a8";
//Password of the user as MD5 (user on behalf of whom the transaction is processed);
config[SessionConnection::CLIENT_PASSWORD_ENCODED] = "5f4dcc3b5aa765d61d8327deb882cf99";
//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 = "cpp.ca-1";
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 = "Honolulu";
customerAccount->State = "CA";
customerAccount->ZipCode = "31904";
//Create payment option;
PaymentOption^ paymentOption = customerAccount->CreatePaymentOption();
//code is optinal; if you specify the value, make sure the code is unique;
paymentOption->Code = "cpp.po-1";
paymentOption->HolderName = "John Smith";
paymentOption->Number = "4111111111111111";
//expiration date;
paymentOption->Accessory = "1209";
paymentOption->Street1 = "233 12th Street";
paymentOption->City = "Honolulu";
paymentOption->State = "CA";
paymentOption->ZipCode = "31904";
//Create payment plan;
PaymentPlan^ paymentPlan = customerAccount->CreatePaymentPlan();
//code is optinal; if you specify the value, make sure the code is unique;
paymentPlan->Code = "cpp.pp-1";
//all amounts are in cents;
paymentPlan->Amount = 5000;
//Item Codes must be setup in portal prior to being used;
paymentPlan->ItemCode = "Membership";
paymentPlan->Type = PaymentPlanTypes::Fixed;
//Billing Cycle codes must be setup in portal prior to being used;
paymentPlan->BillingCycleCode = "M03";
//Specify desired billing date; if nothing specified, next billing date of the selected cycle assumed.
//paymentPlan.FirstBillingDate = <DateTime>;
paymentPlan->Add(0, 12, false);
// Create invoice for downpayment;
RevenueTransaction^ revenueTransaction = customerAccount->CreateRevenueTransaction();
//code is optinal; if you specify the value, make sure the code is unique;
revenueTransaction->Code = "cpp.rt-1";
//all amounts are in cents;
revenueTransaction->Amount = 10000;
//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 = "cpp.at-1";
//all amounts are in cents;
transaction->Amount = 10000;
transaction->TransactionType = AssetTransactionTypes::Cash;
transaction->AccountActivityType = AccountActivityTypes::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;
Console::WriteLine(ex->Message);
return 0;
}
//Get info from customer account;
Console::WriteLine(customerAccount->Code);
Console::WriteLine(customerAccount->FirstName);
Console::WriteLine(customerAccount->LastName);
//Get info from payment option;
Console::WriteLine(paymentOption->Code);
Console::WriteLine(paymentOption->Accessory);
Console::WriteLine(paymentOption->Number);
//Get info from payment plan;
Console::WriteLine(paymentPlan->Code);
Console::WriteLine(paymentPlan->FirstBillingDate);
Console::WriteLine(paymentPlan->BillingCycleCode);
//Get info from revenue transaction;
Console::WriteLine(revenueTransaction->Code);
Console::WriteLine(revenueTransaction->Amount);
Console::WriteLine(revenueTransaction->AccountActivityType);
//Get info from asset transaction;
Console::WriteLine(transaction->Code);
Console::WriteLine(transaction->Amount);
Console::WriteLine(transaction->AccountActivityType);
//logout;
session->Logout();
return 0;
}