Thursday, November 12, 2009

Google Checkout Using PHP

Using Google Checkout....

Google requires the page that is used to monitor the notifications returned from Google is https. If you donot have https on your server, you cannot monitor the notifications from Google. However, you can still use Google Checkout with PHP-KeyCodes but it will work slightly different.

Using PHP-Keycodes without https

When a customer clicks on the Google checkout button, the next licence code is read from the database, and the database is updated to remove that licence code.

The customer then makes a purchase through Google Checkout and if the credit card is correctly authorised, the customer will see the purchased licence code in their Google Checkout account. The customer can also see the licence code at any time by logging back into their Google Checkout account and going to Purchase History.

If the customer fails to make the purchase, the licence code is not displayed to the customer. Also, because there is no notification back to your site, PHP-KeyCodes does not know that there has not been a purchase and hence the database will contain the licence codes, less the one that she attempted to purchase.

Using PHP-Keycodes with https

When a customer clicks on the Google checkout button, the next licence code is read from the database, but the database is not updated to remove that licence code at this point.

When the customer makes a purchase through Google Checkout and the credit card is correctly authorised, the customer will see the purchased licence code in their Google Checkout account and going to Purchase History. The customer can see the licence code at any time by logging back into their Google Checkout account. At this point, Google sends a notification back to your web site and this is used by PHP-KeyCodes to remove the licence code from the database. Only when the applcation receives the correct notification from Google will the database be updated to reflect the purchase.

If the customer fails to make the purchase, the licence code is not displayed to the customer and the database still contains the purchase code that she attempted to purchase.
The Google responsehandler.php

The Google reponse handler is located in the folder 'google_response_handler'

The url of the responsehandler is :
https://www.yoursite.com/phpkeycodes/google_response_handler/responsehandler.php

which assumes that the application has been installed in the phpkeycodes folder.

NOTES :

If do not get call backs with responsehandler.php first check what happens if actually enter :
https://www.yoursite.com/phpkeycodes/google_response_handler/responsehandler.php

in your browser. You should get the page asking for a username / password. If you get an internal server configuration error try moving the response handler to a separate folder.
Log file testing of responsehandler.php notifications

A handy way of testing the notification messages from Google is by logging the notifications into a text file on your server.

To do this, open /google_response_handler/responsehandler.php in a text editor and find the following :
//---------------------------------
//Added to log data
//A file called log.txt will appear at the root of the application folder
// $f = fopen(dirname(FILE)."/log.txt", "a+"); fwrite($f, "\nROOT:\n".$root."\nData:\n".print_r($data, true)); fclose($f);
//---------------------------------

Uncomment the $f line

Don't forget to change permissions to 777 on the folder to get the log files.
Creating a Google Account

If you have not created a Google account go to :

http://www.google.com/accounts/

and create a new account which will be used by you to sell items.

Go to your account at https://checkout.google.com/sell/orders

After signing in, click on the Settings tab. Then click on the Integration link on the left side of the page. Your 10- or 15-digit Merchant ID and your Merchant Key will both be listed under the Account information header. You need both of these codes which you enter in the Google Setup admin section of PHP-KeyCodes. Also, you need to tick the check box to identify if you are using SSL which is on the same admin page.

In the Settings tab ensure that the tick box 'Shopping trolly post security' is ticked (this is ticked by default).

PHP-KeyCodes can operate with out SSL (called Level 1 integration by Google) or with SSL (called Level 2 integration by Google) which provides the ability for your site to be notified of new orders that you receive.

If you have an SSL certification, you have to set up the url of the response handler which is done as follows :

* Click on 'My Sales' in the top left hand corner of your google account.
* Click on the Settings tab.
* Click on the Integration link
* Enter the API callback URL and a call back method of XML.

The url of the responsehandler is
https://www.yoursite.com/phpkeycodes/google_response_handler/responsehandler.php

which assumes that the application has been installed in a folder called phpkeycodes.
Creating a Sandbox Google Account

PHP-Keycodes is able to use the Google sandbox system for testing.

First create a buyer account at http://sandbox.google.com/checkout, using a credit card of 4111-1111-1111-1111.

Then create your merchant, seller accout at http://sandbox.google.com/checkout/sell/ again using a credit card of 4111-1111-1111-1111.

You should find your 10- or 15-digit Merchant ID and your Merchant Key listed under the Account information header. You will need these when you do testing in the PHP-Keycodes admin pages.

If you are using SSL, don't forget to add in your integration responsehander url in the same way as for your live account.
Testing with Google Sandbox

To do a sandbox test with Google, you have to enter the Merchant ID and Merchant Key into the Google set up admin page of PHP-Keycodes replacing the live key codes. You also have to tick the checkbox to say show that you are using the sandbox system.
Digital delivery buyer expericence :

You may find this link helpful in understanding some of Google concepts
Google notifications

Google says :

Before you ship the item in an order, you should ensure that you have already received the 'new order notification' for the order, the 'risk information notification' for the order and an 'order state change notification' informing you that the order's financial state has been updated to CHARGEABLE.

This means that the credit card has the facility to be Charged and when you log in to your account you click on CHARGE for that item and the credit card amount is processed.

PHP-KeyCodes monitors these notifications from Google and only when the above are received correctly will it process the transaction.
Issues to do with currency and Google Checkout

Google Checkout is currently designed to process transactions in either U.S. Dollars or Pounds Sterling. If your business address is in the U.S., your customers will be charged in USD; if you're located in the U.K., your customers will be charged in GBP.

Customers in all countries where Google Checkout is available can purchase from your site. While their purchases will always be processed in the currency matched to your address, the buyers' credit cards will usually provide seamless currency conversion. You can check the 'Location' drop-down menu on the sign-up page, located at https://www.google.com/accounts/NewAccount

No comments:

Post a Comment