During the past two years I’ve constantly been frustrated with the Authorize.net API wrappers that exist, so when I started to rebuild NACHI.TV I decided I would write the one I always hoped for. The code is just a two days old, so I’m sure there are all sorts of gaping holes in it, but I thought I’d release this first version to get some feedback from others who are as frustrated as I am.
Here’s a basic example of how you might use the wrapper:
$gateway = new Galahad_Gateway_AuthorizeNet($login, $tranKey);
$card = new Galahad_CreditCard('4222222222222', 4, 10);
$transaction = new Galahad_Gateway_Transaction(null, 2.00, $card, 'Description of $2 purchase');
$response = $gateway->capture($transaction, true);
if ($response->isApproved()) {
echo '<h1>Approved</h1>';
} else {
echo '<h1>Declined</h1>';
}
The code is (obviously) PHP5 only, and requires cURL and OpenSSL. Most of the code is gateway-agnostic (right now the only gateway supported is Authorize.net) so it’s written in a way that you should be able to use any gateway with a little bit of work. I plan on writing a PayPal implementation at some point in the near future.
In the future I’d like to add a GatewayResponse object and a GatewayResponseException to standardize some of the response data and error handling (so that you can check if the transaction was accepted or declined, etc, without having to know about the specific gateway), and I plan on cleaning up a lot of the code. I would HIGHLY recommend not using this in a production site yet.
Right now the Authorize.net gateway supports authorize, capture, and authorize+capture. In the future I will add support for refund and void. The plan is to standardize those 4 actions, and then let each gateway support whatever additional functionality it wants to. I might add recurring billing and data storage to that list in the future, but I don’t know how well other gateways support those functions.
Please take a look at the code and let me know if you have any suggestions. I wouldn’t be surprised if the class structure changes significantly over the next few weeks, so don’t hesitate to suggest major changes. The code is released under GPL3.
Update (3/10 6:20 PM): Major restructuring of code already started. Switching to a Zend Framework layout. Also, ditching the GatewayResponseException and returning only a Response object either way.
Update (3/11 10:00 AM): Changed the code to match the Zend Framework structure and made a bunch of updates. Sample code above now reflects basic flow.
Project Page: Galahad Payment Layer