RSS feed - Using POG with Flex
- Optimizing your web application
- Regenerating large objects
- PHP4 or PHP5
- New and Improved
- Evolution of a cube
- POG Museum
- POG 3.0 alpha
- Initial Performance results Part 2
- Initial performance results
- Proposal: POG 3.0 object model
- Suggest a feature
- A new year, A new POG release
- Many-Many relations
- POG 2.5 Released
- POG 2.5 beta
- Automatic table alignment
- New version: 2.1.2 released
- RSS should work well now
- RSS feed glitches
- What's new in 2.1.0
- PHP Objects 2.1.0 (preview)
- PHP Object relations FAQ
- PHP Object Relations
- Searching base64 encoded text
- How to debug POG-generated objects
- POG UI Tips
- Featuring Of Interest links
- PHP CRUD
- POG 2.0.1: A better code generator
- A look at the POG SOAP API
- POG 2.0.0 released
- Coming soon: Generate parent-child objects
- Generated abstraction v/s dynamic abstraction
- Zend Framework preview
- Coming soon: Generate Objects through SOAP
- Easily save images and files to a database
- PHP, Paypal & POG
- Five advanced Code Generator tips
- PHP Pagination using generated objects
- PHP Code Generator benchmarks
- Representing database objects using an AJAX Tree interface
- Using SETUP in a production environment
- Description of the generated object package
- Introducing PHP Object Generator version 1.6
- Using AJAX and PHP Object Generator
- When to use Object->SaveNew()
- Generating PHP objects in 2006
- Happy Holidays
- A short video of the POG Setup process
- A sneak peek at POG 1.6
- POG Tip: Field limits
- Previous versions.
- Searching the blog and tutorials sections
- Generating code with "Other" SQL data types
- Five general POG tips
- POG source code locations
- Microsoft SQL 2005 Express Edition
- Impatiently awaiting PHP 5.1 and PDO
- Php Object Generator goes open source
- POG generates PDO compatible code
- Oracle to offer free database
- POG Google group
- Database Wrappers and POG
- Revisions
- The generator blog
- An explanation of the 'Escape' function.
- Mirror, mirror
- Using POG to solve real world problems
- A php object-relational database tool
- A simple and flexible Object Oriented approach to PHP
Back to the Code Generator
The POG Google group
The POG tutorials/code samples
The POG mirror site
PHP, Paypal & POG
written 795 days agoA very common task a PHP programmer usually faces is creating a payment form which uses Paypal as payment gateway. For instance, let’s assume you have a payment form which needs to be filled by customers
The work-flow of such payment systems is usually:
- Collect the user contact information from your form.
- Validate and store the information provided by the user to your database
- Redirect the user to the payment gateway to process the payment. (in our case, Paypal)
- Use the automated merchant tools available to update your local record of the user once the payment goes through.
Implementing this work-flow is easy as POG makes step 2 and 4 somewhat easier.
Step 1:
Create a POG object to store the form information. We create a “Buyer” object with a bunch of attributes. You can take a look at the source code for this article at the end of the article.
Create your payment form.
Give your form inputs the same names as the corresponding Object attributes. In our case, we created a “Buyer” object and then created a payment form where the input names matched the attribute names of the buyer object. This will ease the way we assign the supplied information to the object, as shown further down.
Step2:
Once the user submits the form, we instantiate a ‘buyer’ object as follows and store the information. Because we the object attributes and form inputs match, we can use PHP variable variables to shorten the code:
$buyer = new Buyer();
$keys = array_keys($_POST);
foreach ($keys as $key => $value)
{
}
$buyer->SaveNew();
Step3:
The second thing we do is switch out the submit button and replace it with a paypal button that will redirect the user to Paypal.com so that they can complete the financial transaction. Your paypal button should look something like this.

To create your own paypal button, you can either adapt the button above or create your own from your Paypal account
The important things to note in the payment buttons are:
- The notify_url variable which should match the URL of the your back-end notifications script.
- The custom variable which you can use to pass any variable which is returned to you whenever there’s a notification from Paypal. Use your ‘Buyer’ object ID here since it’s a unique value from which you can retrieve the entire buyer object later on and update it with the paid status.
Step4:
Paypal allows you to setup up an Instant Payment Notification (IPN) service which is triggered whenever a transaction goes through successfully. More details can be found in Paypal’s integration guide

Essentially, in from your paypal account, you assign a URL which Paypal will notify whenever a payment transaction goes through.
Here is a sample PHP code which handles the IPN:
// post back to PayPal system to validate
$header .= “POST /cgi-bin/webscr HTTP/1.0\r\n”;
$header .= “Content-Type: application/x-www-form-urlencoded\r\n”;
$header .= “Content-Length: ” . strlen($req) . ”\r\n\r\n”;
$fp = fsockopen (‘www.paypal.com’, 80, $errno, $errstr, 30);
$custom = $_POST[‘custom’];
if (!$fp) {
// HTTP ERROR
echo “error”;
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, “VERIFIED”) == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$buyer = new Buyer();
$buyer->Get($custom);
$buyer->Paid = true;
$buyer->Save();
}
The important part of this script has been highlighted. After all checks and verifications have been made, we only need to update our buyer record so that it is marked as “PAID”. To achieve this, we simply use the custom variable we passed when the transaction was first initiated to retrieve the appropriate Buyer object. We then simply update the Paid attribute to true, and save the object back to the database.
We hope this tutorial will give you an idea how POG can be integrated with an existing payment system on your website. In our case, we used Paypal as an example since it is the most common payment gateway these days.
You can also download the source code for this article, which requires only a few modifications to be fully operational.
If you have any question about this article or can’t get the source code working, feel free to place a message on the POG Google group or simply add a comment to this blog.

first be indulgent about my english (i’m french) i’am looking for a php code that might be very easy for you, i’ve built a website with a shopping cart but now i want to integrate paypal to give my customer another way to pay.So when the customer is checking out he is asked to choose and option to pay his cart.when he click on “pay with paypal or credit cartd” i would like to find a way to dynamically build this button in function of the customer’s shopping cart button so that he would be using a single button to send informations about a multiple-items-shopping-cart to paypal
— franck Oct 4, 11:28 AM #
This is a weblog about the Php Object Generator (POG) project, OO PHP, databases and Php code generators in general.
Php Object Generator, (POG) is an open source PHP code generator which automatically generates clean & tested Object Oriented code for your PHP4/PHP5 application.
Subscribe to our RSS feed
Feedback, Feature Requests, Bugs to:
The POG Google group
Send us a Hello through email
I am using b2evolution for my blog, and have been trying unsuccessfully to post a message using the Buy Now button from PayPal. The message doesn’t like form or input variables, and in all honesty, I am not a programmer and don’t know very much about PHP at all. PayPal provides a developers kit for PHP, and I took a look at it, but it’s no different than picking up a book of Latin and making sense of it. If you have any suggestions, I’m more than listening. Thanks, Paula
— Paula St. Peter - Travis Nov 18, 12:12 AM #