Facebook Developer Garage Dhaka – Open Stream API

The first ever “Facebook Developer Garage” took place in Dhaka, Bangladesh and I am proud to be a part of it. I was one of the speakers of this spectacular event organized by Facebook and IBT bangladesh. I spoke about the recently released Open Stream API from Facebook. It was more of an overview rather than a detail one. Here goes the slides:

I have created a quick start example which outlines both Facebook Connect and the Open Stream API. You can check that here. A blog post covering the steps is coming soon in 3-4 days.

Stay tuned if you have interest in them.

Cheers

phpXperts ’09 seminar

At last the phpXperts seminar on “Current Web Trends” have taken place and I was one of the speakers there. Among all the topics, mine was a bit suggestive and naturally a bit less exciting. I spoke about how to become a PHP ninja – what are the characteristics they posses, what are the tools they use, what are the paths they follow etc. It’s actually a follow-up of one of my blog posts: “Becoming a kick-ass PHP ninja“.

Here goes the slides:

All the other slides, pictures, and videos are available here.

Enjoy!

A Workshop on “Freelancing IT Jobs – How to Make Yourself Ready”

Today I facilitated this workshop on Freelancing, organized by BDjobs.com. The primary focus of the workshop was to introduce the concept of freelancing to the attendee’s as well as to provide them with a general hands-on path on how to start freelancing. The total workshop covered a variety of sections starting from freelancing overview, freelance site reviews, tips on building a professional profile, the bidding process, tips on successful bidding, client management techniques, payment pitfalls, payment methods, etc.

You can download the presentation file here in two formats: PDF and Powerpoint.

The full workshop description is provided below. If you’re interested in attending the next workshop on April, get in touch with BDjobs.com.

(more…)

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

Update: This library has gone through full re-write and the uploaded version can be found here.

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
No download available for this version.

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)

Snippet 1

1// Include the paypal library
2include_once ('Paypal.php');
3
4// Create an instance of the paypal library
5$myPaypal = new Paypal();
6
7// Specify your paypal email
8$myPaypal->addField('business', 'YOUR_PAYPAL_EMAIL');
9
10// Specify the currency
11$myPaypal->addField('currency_code', 'USD');
12
13// Specify the url where paypal will send the user on success/failure
14$myPaypal->addField('return', 'http://YOUR_HOST/payment/paypal_success.php');
15$myPaypal->addField('cancel_return', 'http://YOUR_HOST/payment/paypal_failure.php');
16
17// Specify the url where paypal will send the IPN
18$myPaypal->addField('notify_url', 'http://YOUR_HOST/payment/paypal_ipn.php');
19
20// Specify the product information
21$myPaypal->addField('item_name', 'T-Shirt');
22$myPaypal->addField('amount', '9.99');
23$myPaypal->addField('item_number', '001');
24
25// Specify any custom value
26$myPaypal->addField('custom', 'muri-khao');
27
28// Enable test mode if needed
29$myPaypal->enableTestMode();
30
31// Let's start the train!
32$myPaypal->submitPayment();

Snippet 2

1// Include the paypal library
2include_once ('Paypal.php');
3
4// Create an instance of the paypal library
5$myPaypal = new Paypal();
6
7// Log the IPN results
8$myPaypal->ipnLog = TRUE;
9
10// Enable test mode if needed
11$myPaypal->enableTestMode();
12
13// Check validity and write down it
14if ($myPaypal->validateIpn()) {
15 if ($myPaypal->ipnData['payment_status'] == 'Completed') {
16 file_put_contents('paypal.txt', 'SUCCESS');
17 }
18} else {
19 file_put_contents('paypal.txt', "FAILURE\n\n" . $myPaypal->ipnData);
20}

Authorize.net

In order to process payments using Authorize.net, you’ll need to follow these steps:

1. Send the required information to Authorize.net(snippet 3). Be sure to specify your Authorize.net login and secret key, the success/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/failure page where Authorize.net will send your customer after payment.

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

4. In order to set the secret key, log into your authorize.net merchant account. Go to “MD5 Hash” menu and set a secret word to desired values and use that in the “setUserInfo” function showed in the example.

Snippet 3

1<!--?php </p-->
2
3// Include the paypal library
4include_once ('Authorize.php');
5
6// Create an instance of the authorize.net library
7$myAuthorize = new Authorize();
8
9// Specify your authorize.net login and secret
10$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_SECRET_KEY');
11
12// Specify the url where authorize.net will send the user on success/failure
13$myAuthorize->addField('x_Receipt_Link_URL', 'http://YOUR_HOST/payment/authorize_success.php');
14
15// Specify the url where authorize.net will send the IPN
16$myAuthorize->addField('x_Relay_URL', 'http://YOUR_HOST/payment/authorize_ipn.php');
17
18// Specify the product information
19$myAuthorize->addField('x_Description', 'T-Shirt');
20$myAuthorize->addField('x_Amount', '9.99');
21$myAuthorize->addField('x_Invoice_num', rand(1, 100));
22$myAuthorize->addField('x_Cust_ID', 'muri-khao');
23
24// Enable test mode if needed
25$myAuthorize->enableTestMode();
26
27// Let's start the train!
28$myAuthorize->submitPayment();

Snippet 4

1<!--?php </p-->
2
3// Include the paypal library
4include_once ('Authorize.php');
5
6// Create an instance of the authorize.net library
7$myAuthorize = new Authorize();
8
9// Log the IPN results
10$myAuthorize->ipnLog = TRUE;
11
12// Specify your authorize login and secret
13$myAuthorize->setUserInfo('YOUR_LOGIN', 'YOUR_SECRET_KEY');
14
15// Enable test mode if needed
16$myAuthorize->enableTestMode();
17
18// Check validity and write down it
19if ($myAuthorize->validateIpn()) {
20 file_put_contents('authorize.txt', 'SUCCESS');
21} else {
22 file_put_contents('authorize.txt', "FAILURE\n\n" . $myPaypal->ipnData);
23}

2Checkout

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

1. Send the required information to 2Checkout(snippet 5). Be sure to specify your 2Checkout vendor id, the return page, and the product information. Please note that 2Checkout does not send IPN in the background, so you will need to handle the payment data in the return page. The example has the test mode ON, which you will not need in real scenario.

2. Create a return page where 2Checkout will send your customer after payment. This is also where you will need to retrieve and use the payment data. Make sure you use/remove the test mode in conjunction with step 1. (snippet 6)

3. In order to set the secret key, log into your 2checkout.com account and go to “Look and Feel” section. At the bottom enter the “Secret Word” and use it in the IPN verification process as shown in the example.

Snippet 5

1<!--?php </p-->
2
3// Include the paypal library
4include_once ('TwoCo.php');
5
6// Create an instance of the authorize.net library
7$my2CO = new TwoCo();
8
9// Specify your 2CheckOut vendor id
10$my2CO->addField('sid', 'YOUR_VENDOR_ID');
11
12// Specify the order information
13$my2CO->addField('cart_order_id', rand(1, 100));
14$my2CO->addField('total', '9.99');
15
16// Specify the url where authorize.net will send the IPN
17$my2CO->addField('x_Receipt_Link_URL', 'http://YOUR_HOST/payment/twoco_ipn.php');
18$my2CO->addField('tco_currency', 'USD');
19$my2CO->addField('custom', 'muri-khao');
20
21// Enable test mode if needed
22$my2CO->enableTestMode();
23
24// Let's start the train!
25$my2CO->submitPayment();

Snippet 6

1<!--?php </p-->
2
3// Include the paypal library
4include_once ('TwoCo.php');
5
6// Create an instance of the authorize.net library
7$my2CO = new TwoCo();
8
9// Log the IPN results
10$my2CO->ipnLog = TRUE;
11
12// Specify your authorize login and secret
13$my2CO->setSecret('YOUR_SECRET_KEY');
14
15// Enable test mode if needed
16$my2CO->enableTestMode();
17
18// Check validity and write down it
19if ($my2CO->validateIpn()) {
20 file_put_contents('2co.txt', 'SUCCESS');
21} else {
22 file_put_contents('2co.txt', "FAILURE\n\n" . $my2CO->ipnData);
23}

Hope this will help you integrate the payment gateways in an easy manner. If you have any questions, or find any bug, have a suggestion, feel free to post them as comment here. Btw, this library is released under the MIT license.

Cheers!

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!