Wednesday, February 4, 2009

Postgresql Spatial Database (GIS) using PostGIS

Postgresql is a open source database that has an add-on module named PostGIS.
PostGis adds support for geographic objects. It allows you to spatial enable your databases.
With the onset of websites like Google maps, having the ability to map locations, map routes, etc, is becoming common place.
With PostGis, I am able to quickly and easily determine distances between 2 locations. I can retrieve longitude and latitude values.

Installing PostGIS

I am using Fedora 8, so I needed to install PostGis from source.

Install from Source Method
1) download, configure, make proj (version 4.6.1)
notes: yum installs files to /usr/share/pgsql/contrib/lwpostgis.sql, postgis_comments.sql, spatial_ref_sys.sql,
from source files get installed to /usr/share/lwpostgis.sql, lwpostgis_upgrade.sql, spatial_ref_sys.sql

2) After compiling proj from source,
a) edit /etc/ld.so.conf
add /usr/local/lib
b) ldconfig
c) recompile PostGis ( if previously installed)

3) Compiling PostGis from source,
a) just run ./configure (without options)
b) then: make
c) make install
4) createlang plpgsql [yourdatabase]
5) psql -d [yourdatabase] -f lwpostgis.sql
6) psql -d [yourdatabase] -f spatial_ref_sys.sql
PostGis is found at http://postgis.refractions.net

Amazon Flexible Payments Service Part 3, Co-branded Flow

In a typical website, you want your customer to have a payment link that starts the process of them paying for services/products that your site has provided to them via Amazon. This typical process end to end is called Co-Branded UI process in Amazon's FPS documentation.
There are 3 roles in the process: Sender, Caller, and Recipient. The sender is the entity sending money. The Caller is the entity calling the Amazon FPS Api. The recipient is the entity who will receives the payment. Amazon uses tokens to provide secure handle to payment instructions.
In this process 3 tokens are used a Caller token, Recipient token, and Sender token. Your web application will need to create a Caller Token, and Recipient Token.
In the Co-Branded UI process , once you customer chooses a product/service and payment amount, they get redirected to Amazon's FPS website where they log in using their Amazon account, select their payment method. It is here in this part of the process on the Amazon site where the Sender token is created. After confirming their payment method, and amount on the Amazon site, the user gets redirect back to you site. When they are redirected back to your site, Amazon passes back to your site the Sender token. Your site will need to acquire this sender token information, and then your site will need to formally request/submit a payment authorization to Amazon FPS Webservice.
Amazon can then notify you when payment was successful either via a scheduled job that you create that queries Amazon FPS, or via Instant Payment Notification which requires you to setup a Web Service that Amazon calls when payment is successful. One of the undocumented Payment Transaction Statuses that I found is "Initiated". In their WSDL file they only define: "Success", "Failure". This can cause issues if you are not expecting to receive this status of "Initiated", and are only expecting to the 2 values of "Success" or "Failure".
The best way to get comfortable with Amazon FPS in my humble opinion is to review and work thru the examples and sample applications.

Amazon Flexible Payments Service Part 2, Setup

In order to use Amazon FPS, you will need to create an aws developer account (Amazon Web Services Account) and sign up for Amazon FPS sandbox account.
Follow the steps in the Amazon FPS Getting Started Guide, http://developer.amazonwebservices.com/connect/entry.jspa?externalID=913&categoryID=125
After completing these steps, you should setup you local development environment, and work thru some of sample applications.
I ended up working thru the Java sample applications and rewriting them in C# to get a solid understanding of Amazon FPS.
It is important know what your requirements for you payment application are ahead of time, so that you can pick which features of Amazon FPS you want use. Do you want to retrieve your payment notification from Amazon in a scheduled job or Do you want know instantly when a payment transaction is completed?
If you want to know instantly when a payment transaction is completed and don't want have to deal with creating a scheduled job, then use Amazon's IPN feature (Instant Payment Notification). IPN requires that you setup a Web Service on your web server that Amazon FPS can access to notify you of payments. If you don't want to setup a Web Service for IPN, you will need to go the scheduled job route.