Recent Comments
  • Kazi Mohammad Ekram: this was nice presentation. It inspired me to make a present...
  • Kazi Mohammad Ekram: this was nice presentation. It inspired me to make a present...
  • Lenin: Great work :)...
  • Ron: Hi Emran,Great job on this! I was testing it out and...
  • Lenin: Great work :)...
  • Ron: Hi Emran,Great job on this! I was testing it out and...
  • ariful: very helpful and nice extended class. thanks emran vai...

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

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.

You can straight-away download the package 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 entry »

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Seven Things

Well, this seven unknown things internet meme has been circulating in the web for a while and I am joining after seeing this in a few blogs I follow. However, haven’t seen this in my blogger network from Bangladesh so hope it will make a few laughs.

So here goes seven random (weird) things about me:

1. The veins in my left eyes are dried up, so I practically use my right eye for everything…pirate king!

2. The real break in my programming life came when I went to a programming contest with a team and was declined to participate. We had our rights and they later let us in, but gave us a almost broken PC. We cracked three out of 5 problems straight in DOS edit as the compiler would hardly run :)

3. I do not watch TV programs for the last 5 years. DVDs and downloaded movies/TV series are the only source of entertainment. My most fav TV series is The X Files.

4. When I was a kid, I was damn fond of toys. I had a whole collection of figures from HE-MAN, J.I.JOE, Thundercats, Transformers, and a few others.

5. I was present only in 48% classes in my second year in college, whereas the rule of thumb was a minimum of 85%. After the test exams, I was given a punishment of attending to library from 8am to 5pm for 26 days where the only thing allowed is study (textbook only). No friends, no gossip, no newspaper.

However, I convinced my father that this punishment was imposed to me as one teacher did not like my attitude in his class; i made my father to the principal with an application where its mentioned that I cannot attend this due to medical condition. Principal had to agree and I only had to do it for 2hrs for the sake of records ;)

6. The first program I wrote for money was a file copying & renaming program in VB6 for $20. It would transfer some old mail server (don’t rem the name) files from an old server to a new one and would rename their extension to match Microsoft Exchange. Exchange was smart enough to read & convert automatically, so it looked as if the program did the conversion. Heh heh.

The fun part is, later another company was somehow convinced that it’s a huge work and went into a partnership with me where I received a down payment of $1500 and a 30% profit sharing with the same application plus a few UI improvement. Not bad ;)

7. I never studied Computer Science nor did any programming classes. I have been in business studies concentration since school and did my bachelors in Business Administration (BBA). Currently I’m pursuing my masters in Business Administration (MBA) as well.

Here are the seven people I’m tagging:

1. Hasin Hayder
2. Anis Uddin Ahmad
3. NHM Tanveer Hossain Khan
4. Omi Azad
5. Trivuz
6. M.M.H Masud
7. Suhreed Sarkar

And here goes the rules:

- Link your original tagger(s), and list these rules on your blog.
- Share seven facts about yourself in the post – some random, some weird.
- Tag seven people at the end of your post by leaving their names and the links to their blogs.
- Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

Enjoy!

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr

Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport)

Greetings to all the readers of my blog.

Many of you have been writing to me in the last couple days when I took the site down. The main objective was to add the new theme and push a few code updates of the existing libraries. I really appreciate your concern and would like to reassure you that the site is up and will be up as usual :) Now, besides the slightly customized theme from Elegant Themes, I have put a few code updates. They are detailed below:

Extended Model for CodeIgniter

The original version of the Extended Model for CodeIgniter has been serving many people well. Although most users loved the nifty functions of the Model, many (including me) didn’t like the hacking of CI core to get this functionality. With the release of CodeIgniter 1.7, we can avoid that as we can now overload the Model class of CI like the other libraries. Follow this instruction:

1. Download the updated version from here
2. Put it in your application/libraries folder
3. In your model files, use it this way: class Product extends MY_Model
4. Everything else is same just like the original one

HTTP Class

There is not much update in this class except for a few bug fixes (thanks to you guys). Also, I have included a license file in the package as many of you have asked. It’s released under the MIT license. The original post is here for reference.

Download the update from here and the API reference is here.

Cross-domain AJAX calls using PHP

A minor bug fix in the code. Thanks to a few of you who pointed them out. Original post is here. Download the update from here.

I have accelerated plans for the blog in 2009 so stay tuned for some worthy posts in this month. And do write to me if you feel you have any questions/ideas/suggestions.

Cheers!

Share and Enjoy:
  • Digg
  • DZone
  • Twitter
  • Posterous
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Simpy
  • Ping.fm
  • Tumblr