HerbIgniter User Guide Version 1.7.2


"Biz" Helper

The Biz Helper file contains functions that assist in working with CyberSource's Authorize.net and PayPal. For currency exchange functions, see the Country Helper.

The function authorize_net() is the only function required for that method.

We do not fully document the PayPal API, we merely have provided its functionality wrapped into HerbIgniter. To understand how this works, visit PayPal.

Loading this Helper

This helper is loaded using the following code:

$this->load->helper('biz');

The following functions are available:

authorize_net(card_num, exp_date, invoice_num, description,
amount, cust_id, first_name, last_name, company, address, city, state, zip, country, phone, fax, email,
ship_to_first_name, ship_to_last_name, ship_to_company, ship_to_address, ship_to_city, ship_to_state, ship_to_zip, ship_to_country,
tax, duty, freight, tax_exempt, po_num)

Makes an authorization request for a sale to Authorize.net. This is the final step in the process before returning a success or failure notice that is contained inside an Authorize.net-specific array. You should visit Authorize.net's developer's section

The array that it returns contains the following elements:

Example:

// Prepare the operation with Authorize.net, or auto-approve freebie purchases

$x_card_num = preg_replace('/([^0-9]+)/','',$order['AccountNumber']);
$x_exp_date = $order['Month'].'/'.$order['Year'];

$x_description = 'Order from ' . $this->config->item('site_name') .': '. $order_id;
$x_amount = $order['total'];
$x_first_name = $order['First_Name'];
$x_last_name = $order['Last_Name'];
$x_address = $order['Billing_Address'];
$x_city = $order['City'];
$x_state = $order['State'];
$x_zip = $order['ZIP'];

$x_invoice_num = $order_id . '/' . $order['id'];
$x_cust_id = $this->customer_id;

$x_tax_exempt = '';
$x_po_num = '';
$x_company = '';
$x_country = $order['Country'];
$x_phone = $order['Phone'];
$x_fax = $order['Fax'];
$x_email = $order['Email_Address'];

$x_ship_to_first_name = '';
$x_ship_to_last_name = '';
$x_ship_to_company = '';
$x_ship_to_address = '';
$x_ship_to_city = '';
$x_ship_to_state = '';
$x_ship_to_zip = '';
$x_ship_to_country = '';

$x_tax = $order['tax'];
$x_duty = 0;
$x_freight = $order['shipping'];

if ($order['total'] == 0) { // Process Freebies
$authorize_response=array();
$authorize_response['Response_Code'] = 'Approved';
$authorize_response['Response_Subcode'] = '';
$authorize_response['Response_Reason_Code'] = '';
$authorize_response['Response_Reason_Text'] = '';
$authorize_response['Approval_Code'] = '';
$authorize_response['AVS_Result_Code'] = '';
$authorize_response['Transaction_ID'] = '';
$authorize_response['Invoice_Number'] = '';
$authorize_response['Description'] = 'Free';
$authorize_response['Amount'] = 0;
$authorize_response['Method'] = '';
$authorize_response['Transaction_Type'] = 'No Total';
$authorize_response['MD5_Hash'] = '';
$authorize_response['Card_Code_Response'] = '';
} else {
//////////////////
$authorize_response = authorize_net($x_card_num, $x_exp_date, $x_invoice_num, $x_description, $x_amount, $x_cust_id, $x_first_name, $x_last_name, $x_company, $x_address, $x_city, $x_state, $x_zip, $x_country, $x_phone, $x_fax, $x_email, $x_ship_to_first_name, $x_ship_to_last_name, $x_ship_to_company, $x_ship_to_address, $x_ship_to_city, $x_ship_to_state, $x_ship_to_zip, $x_ship_to_country, $x_tax, $x_duty, $x_freight, $x_tax_exempt, $x_po_num);
//////////////////
}

PayPal_Button( payer_email, item_name, amount, currency,
alt='default', image='default',
type_titles=NULL, types=NULL, default=NULL, options=NULL, extra='<br>' )

A function which generates the entire range of PayPal buttons, including ones with custom images and item options like sizes, colors, etc. You can have multiple types and multiple options. The extra parameter is the HTML between the <SELECT> tags.

// Simple PayPal Button "buy it now"
$page->append_body( PayPal_Button( "my@email.com", "Blue Prada Boots", 340.0, "USD" );

// PayPal Button with Color and Size options
$page->append_body(
PayPal_Button( "my@email.com", "Prada Boots", 340.0, "USD",
array( "Colors:", "Sizes:" ),
array( "color", "size" ),
array( array( "Blue"=>5, "Red"=>6, "Turquoise"=>7 ), array( "Small"=>"S", "Medium"=>"M" ) ),
array( "5", "M" ), '<!--none-->' )
) ;

DoMassPayRequest( paypal_credentials, emailSubject, emailAddress, currency, payees, environment='beta-sandbox', ignore=false )

This function implements PayPal's MassPay API to request multiple payouts from a single PayPal account. According to PayPal, this is the preferred way of paying people ("pay your payroll!"). You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.
$payees = array(
array( 'email'=>'john@doe.com', 'amount'=>'45.00', 'id'=>'Unique Paycheck Number', 'note'=> 'Here is your pay for September 2009' ),
array( 'email'=>'mary@smith.com', 'amount'=>'67.00', 'id'=>'Another Unique PayCheck Number', 'note'=>'Mary, thanks for the fish tank!' )
);

$response = DoMassPayRequest( $credentials, "You have been paid via MassPay!", "referenceme@someemail.com", "USD", $payees, 'beta-sandbox' );
if("SUCCESS" == strtoupper($response["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($response["ACK"])) return true;
return false;

DoAuthorize( paypal_credentials, transactionID, amount, currency, environment='beta-sandbox', ignore=false )

This function implements the Authorization step of the PayPal API. You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. This is a request or 'sale' which is made to the PayPal account you are trying to collect money from.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// The response contains the new authorization id.

$response = DoAuthorize( $credentials, "2314", "22.42", "USD", 'beta-sandbox' );

DoReauthorization( paypal_credentials, auth_id, amount, currency, environment='beta-sandbox', ignore=false )

Reauthorizes a previously authorized transaction. You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = DoReauthorization( $credentials, $auth_id, "22.42", "USD", 'beta-sandbox' );

DoVoid( paypal_credentials, auth_id, note, environment='beta-sandbox', ignore=false )

Voids a prior authorization (cancels it). You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = DoVoid( $credentials, $auth_id, "Refund for out of stock item", 'beta-sandbox' );

DoCapture( paypal_credentials, auth_id, amount, currency, invoice_id, note, environment='beta-sandbox', ignore=false )

You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = DoCapture( $credentials, $auth_id, "22.42", "USD", "Some ID", 'beta-sandbox' );

GetBalance( paypal_credentials, $environment='beta-sandbox', ignore=false )

Gets the balance of your PayPal account (not recipient ones). You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = GetBalance( $credentials, 'beta-sandbox' );

DoRefund( paypal_credentials, transactionID, refundType='Full', currency='USD', amount=NULL, memo=NULL, env='beta-sandbox', ignore=false )

You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = DoRefund( $credentials, $transaction_id, 'Partial', 'USD', '21.50', 'Partial refund for damaged item.', 'sandbox' );

GetTransactions( paypal_credentials, transactionID, startDateStr=NULL, endDateStr=NULL, environment='beta-sandbox', ignore=false )

In the PayPal API this is referred to as "TransactionSearch". You must set the environment variable appropriate to the current environment you are operating in ('beta-sandbox', 'sandbox' or 'live'). Like all of these PayPal API functions here in the Biz Helper, if you set the ignore parameter to true it will return a positive (true) on "SUCCESS" or "SUCCESSWITHWARNING" response codes. If you are doing multiple currencies, you will need to convert it all to the same currency using the Country Helper, which is provided as a parameter.

// Assign some PayPal credentials:

$credentials['username'] = "my@paypal.com";
$credentials['password'] = "abcdefg";
$credentials['signature'] = "signature";

// In this example, we only have two recipients.

$response = GetTransactions( $credentials, $transaction_id, strototime("-2 days"), strtotime("now"), 'live' );