Jaslabs: High performance Software

High Performance Software

Archive for June, 2006

Connecting to Authorize.net with PHP

By Justin Silverton

What is authorize.net?

The Authorize.Net Payment Gateway is a secure Internet bridge between merchant businesses and the credit card and electronic check payment processing networks. We provide merchants with fast, reliable and secure passage for transaction data via a 128-bit Secure Sockets Layer (SSL) Internet Protocol (IP) connection, and manage the complex routing of payment information to the appropriate credit card processors. See a diagram that illustrates a typical Authorize.Net credit card transaction.

The Authorize.Net Payment Gateway is available to merchants seven days a week, 24 hours a day. The payment gateway offers many features and options that can be tailored to specific merchant business models.

Where do I start?

The first thing that you need to do, is signup with a test account. This will allow you to test out transactions to make sure your scripts are interfacing properly with their API. Here is the URL for getting your account:

http://developer.authorize.net/testaccount

API documentation can also be found here:

http://www.authorize.net/support/AIM_guide.pdf

after signing up, you should receive your new account info within 48 hours.

The Code

I have a library available here: (URL). It is originally written by Micah Carrick and is under the GPL/GNU public license. I have made some important additions to the main library, which are needed for it to function properly.

you can get it here: http://www.electronicfiles.net/files/1773/authorize_lib.zip

Requirements: PHP version 4 and above with the CURL extensions enabled

The following 3 files are contained in the above .zip download:

authorizenet.class.php - main class library for connecting to the authorize.net gateway
demo.php - an example driver file that shows how to use the library file. A test transaction is made to the main gateway.
ca-bundle.crt - main certificate file required by CURL for SSL transactions (windows users can place this in c:\windows\system32)

Important Variables that you need to change

Location: authorizenet.class.php

curl_setopt ($ch, CURLOPT_CAINFO,”c:\\windows\\system32\\ca-bundle.crt”);
curl_setopt ($ch,CURLOPT_CAPATH,”c:\\windows\\system32\\ca-bundle.crt”);

change the 3rd parameter “c:\\windows\\system32\\ca-bundle.crt” to the location of your CRT file.

Location: authorizenet.class.php

var $gateway_url = “https://test.authorize.net/gateway/transact.dll”;

it currently points to the authorize.net gateway for test accounts. If you have an account that is performing real transactions, change this variable to the following value: “”https://secure.authorize.net/gateway/transact.dll”

Location: demo.php

$a->add_field(’x_login’, ‘YOUR_USERID’);
$a->add_field(’x_password’, ‘YOUR_PASSWORD’);

change x_login to your Login ID (not partner ID)
and x_password to your password

You should have received both of these in an email from authorize.net

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
10 comments

Excel and php without activeX

By Justin Silverton

Introduction

Spreadsheet_Excel_writer is a PEAR component for creating Excel files without the need for COM components. The files generated are in the Excel 5 (BIFF5) format, so all functionality until that version of Excel (but not beyond) should be available.

Using

The most common use for Spreadsheet_Excel_Writer will be spitting out large (or not so large) amounts of information in the form of a spreadsheet, which is easy to manipulate with a fairly ubiquitous spreadsheet program such as Excel (or OpenOffice).

Example 1:

send(’test.xls’);

// Creating a worksheet
$worksheet =& $workbook-&gtaddWorksheet(’My first worksheet’);

// The actual data
$worksheet->write(0, 0, ‘Name’);
$worksheet->write(0, 1, ‘Age’);
$worksheet->write(1, 0, ‘John Smith’);
$worksheet->write(1, 1, 18);

// Let’s send the file
$workbook->close();
?>

The first thing you should notice, is that we created a workbook before any worksheets. All worksheets are contained within a workbook, and a workbook may contain several worksheets.

Another important thing, which you should have in mind when programming with Spreadsheet_Excel_Writer, is that ampersand sign (&) that appears when we created our worksheet. That ampersand means we are referencing a Worksheet object instead of copying it. If you don’t know what that means, don’t worry, all you have to remember is to always use ampersands when calling addWorksheet() for creating a worksheet, or addFormat() for creating a format.
Saving to a regular file

You may have noticed also the following line:

// sending HTTP headers
$workbook->send(’test.xls’);

What that means is that we are sending our spreadsheet to a browser. But what if we just want to save the spreadsheet in our machine? Well, you just have to omit that line and give a valid file path to the workbook constructor.

For example, if we wanted to save the same spreadsheet we created in our first example to a file named ‘test.xls’, we would do it like so:

Example 2:

addWorksheet(’test worksheet’);

$worksheet->write(0, 0, ‘Name’);
$worksheet->write(0, 1, ‘Age’);
$worksheet->write(1, 0, ‘John Smith’);
$worksheet->write(1, 1, 10);

// We still need to explicitly close the workbook
$workbook->close();
?>

More info and documentation on this component can be found here

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati
2 comments