PHP Payment Library for Paypal, Authorize.net and 2Checkout

21/02/2009

If you are like me, whenever you need to work with a 3rd party API or a gateway, you’d first search in Google for a possible wrapper for it in PHP. When it comes to supporting payment gateways, you get bunch of libraries in the search results who are fundamentally different. Some of them are old PHP 3/4 ones, some are new, some may need PEAR, etc.

As they were not required together in one single project, I used them whenever needed. But in one project, I needed them all. I thoughts it’s a chance and decided to stop using them and wrote my own ones where I can use the same methods for all the gateways.

So, here is an abstract PaymentGateway library which is being extended to be used for three popular payment gateways (Paypal, Authorize.net, and 2Checkout) in order to provide you with a similar way of using them. Note that the libraries are for basic usage only and do not contain options for recurring payments. Without much babble, let’s see a few examples of how you can use them.

Download

You can straight-away download the Payment library with all the libraries, examples, and readme.

Paypal

In order to process payments using Paypal, you’ll need to follow these steps:

1. Send the required information to Paypal (snippet 1). Be sure to specify your Paypal email where you want to receive the funds, the success and failure pages, the IPN page, and the product information. The example has the test mode ON, which you will not need in real scenario.

2. Create a payment success page where Paypal will send your customer after payment.

3. Create a payment failure page where Paypal will send your customer after failed payment.

4. Create a IPN page where Paypal will send payment notification in the background. Make sure you use/remove the test mode in conjunction with step 1. (snippet 2)

<?php

// Include the paypal library
include_once ('Paypal.php');

// Create an instance of the paypal library
$myPaypal = new Paypal();

// Specify your paypal email
$myPaypal->addField('business', 'YOUR_PAYPAL_EMAIL');

// Specify the currency
$myPaypal->addField('currency_code', 'USD');

// Specify the url where paypal will send the user on success/failure
$myPaypal->addField('return', 'http://YOUR_HOST/payment/paypal_success.php');
$myPaypal->addField('cancel_return', 'http://YOUR_HOST/payment/paypal_failure.php');

// Specify the url where paypal will send the IPN
$myPaypal->addField('notify_url', 'http://YOUR_HOST/payment/paypal_ipn.php');

// Specify the product information
$myPaypal->addField('item_name', 'T-Shirt');
$myPaypal->addField('amount', '9.99');
$myPaypal->addField('item_number', '001');

// Specify any custom value
$myPaypal->addField('custom', 'muri-khao');

// Enable test mode if needed
$myPaypal->enableTestMode();

// Let's start the train!
$myPaypal->submitPayment();

Snippet 1
Read the rest of this article »

195 Comments

Nokia N81 8GB

10/12/2008

Today I bought a Nokia N81 8GB smartphone from my friend Nesar. This is an upgrade from my previous Nokia 6300, which I’ve been using for 1.5 year (thats the longest time I’ve used one model). The Nseries of Nokia has been attracting a lot of people lately, with their great music and photo capture features. One of my colleagues, Anis, also bought N73 just two months back.

Nokia N81 8GB
Nokia N81 8GB

Now, good points first. The N81boosts an extremely loud set of sterio speakers – combined with its Music Express, it delivers the highest quality of music I’ve ever purchased. Combined with the built-in FM radion, the dedicated music keys, and a multimedia menu – this is a music powerhouse, thanks to the all new Symbian 9.3 OS.

The Symbian OS is superb with all the applications and now has some stunning gameplay capabilities. The phone also has all kind of connectivity point you might need – GPRS, EDGE, Wifi, Bluetooth, WLAN, 3G. And don’t forget the built-in 8GB memory.

The only downside of this phone is the camera. It’s a 2 megapixel camera – which I don’t have any clue how got into a Nseries phone. If there is not enough light, the pictures are somewhat blurry. It has flash and a number of picture modes, so its a decent one – but nowhere in comparison with other Nseries 3.2mp and 5mp cameras.

All in all, here are the facts:

  • 2.4” QVGA main color display (320 x 240 pixels), up to 16.7 million colors
  • S60 3rd Edition Feature Pack 1 based on Symbian OS v9.2
  • Dedicated media keys for quick and easy access to music and video
  • WLAN IEEE802.11 b/g with UPnP (Universal Plug and Play) support
  • Bluetooth Specification 2.0 (profiles supported: DUN, OPP, FTP, HFP, GOEP, GAP, SPP, HSP, BIP, A2DP)
  • Micro USB 2.0 Full Speed (mass storage class)
  • Nokia AV Connector 3.5mm
  • Up to 2 megapixel (1600×1200 pixels) camera, MPEG-4 VGA video capture of up to 15fps
  • Zoom: digital up to 20x
  • Front camera (CIF)
  • Video call and video sharing support (WCDMA network services)
  • Integrated flash (modes: on, off, automatic, redeye reduction)
  • Rotating gallery with Navi wheel support
  • Nokia Nseries digital music player supports MP3 (VBR), AAC, eAAC+, AAC+, WMA/M4A, WAV
  • OMA DRM 1.x, 2.0, Windows Media DRM (OTI/OTA with Nokia Music Store*)
  • Synchronize music with Windows Media Player 11
  • Media keys (play/pause, stop, forward, rewind)
  • Stereo FM radio (87.5-108MHz /76-90MHz)

Let’s see how long it can serve my ever-growing thirst of technology :)

16 Comments

Preview release of Prothom Alo Blog

26/10/2008

Prothom Alo Blog

It’s my greatest pleasure to introduce another social community of Bangladesh, Prothom Alo Blog, to you all. The site has been made public for a beta period on Friday, 24th October, 2008. And it is expected to be fully released in public on the first week of November.

Me and Hasin has been working on it for a couple month, with occasional help from Anis and Jahed. We’ve tried all our means to make it as user-friendly as possible, without sacrificing functionality and robustness. The blog platform hosts most of the major features of a community blogging platform, along with a few key features which are unavailable in other similar platforms in Bangla.

The site is fully Unicode based, with support for embedded eot font for Internet Explorer. AJAX has been used spontaneously throughout the site to decrease initial load time of primary contents, and slowly fetching secondary contents. All the sidebars of the main pages and admin panels are widget ready and hosts a number of widgets as of now. In future, users will be able to add their widgets as well.

In this platform, we have separated the main site and the administration panel for users. This helps the bloggers as they get a centralized panel where they can mange their posts/comments/links/feeds/moderation/profile etc easily.

Besides the common functionality of community blog, the platform is different in one major context: Moderation. The content from the user’s blogs won’t be moderated. In order to allow this freedom, it’s been decided that no post will appear in front-page of main site categories, until promoted by the moderators. The aim is to provide a place where everybody has freedom of their own blog, but if they want to convey to others, they have to write in a way which actually adds value and abides by the common guideline.

Now that it’s open, we’d like everybody’s comments and suggestions for making it the largest social platform in Bangladesh. Although the registration is closed right now, you can still get into it using an invitation code. The site is OPEN now for public registration, go get one :) Please send me an email or Contact me using the Contact page if you need an invitation any information/help.

Thanks everybody!

9 Comments

Power situation in Bangladesh

27/04/2008

Nothing to say much, check the image below:

Utilizing boring time during load shedding hours

Power line in BD

8 Comments

Trippert, here I come!

6/11/2007

Trippert Inc

I am going to take some of my time out from my regular job as CTO of Right Brain Solution Ltd. and will work at Trippert, Inc. as Development Manager, starting from this month. My primary responsibilities will include software development and project management on various company projects.

I am very excited about working with Trippert as many of the developers there are known to me and I highly regard their work. Also, teaming up again with Hasin is a great thing (we worked together before in Somewhere in… and Pageflakes). I hope to enjoy this journey a lot !

Cheers!

No Comments