mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-11-02 00:57:32 -04:00
Sample PHP code for integration of Google Checkout with the merchant site v1.3.0
--------------------------------------------------------------------------
File structure and function
----------------------------
There are two folders and a log file in the top level directory of
google-checkout-php-sample.
1. "demo" directory:
a)cartdemo.php:
---------------
This file demonstrates the steps required to add items, shipping, taxes and
merchant-calculations to the cart before it is posted to the Checkout server.
There are three use case functions defined with different settings for
shipping and taxes along with different button usages.
Check new DigitalUsecase() in order to use the new Digital Delivery API and the
Server 2 Server API Checkout Request
Check CarrierCalcUsecase() for examples of Carrier Calculation Shipping
b)responsehandler.php:
----------------------
This file will be used to handle the notifications, callbacks and order
processing steps.
The path for this file must be specified in the merchant's API callback
URL in Settings->Integration of the merchant's seller account.
This file can be used as is and modified by the merchant as per their
business workflow details.
Some of the intial steps performed in this file include collecting the
XML response, request that has been received and get a parsed result in a
PHP associative array for easy accesibility
(For details of parse output refer xmlparser.php which has an
example of how an XML maps to the object).
Order processing can be done using the SendProcessOrder(..) type of
methods provided in googleresponse.php. Some sample order processing
command invocations have been provided as comments in the code
c)digitalCart.php:
-------------------
This is an implementation of the server2server API Checkout Request
http://code.google.com/apis/checkout/developer/index.html#alternate_technique
It also implements the latest digital delivery API
http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html
d)lineItemShipping.php:
----------------------
This provides an example to ship individual items in an order separately.
e)pollingdemo.php
---------------------
Demonstrates using the beta polling API. The polling API allows you to poll for notifications instead of
listening for a notification from the Checkout servers.
f)subscriptiondemo.php
-----------------------
Demonstrates using the beta subscription API. The API allows for 2 methods of charing a subscription,
merchant handled and Google Handled. With Google handled the merchant specifies the period and Google
automatically recurs the payment for the merchant. With Merchant handled, the merchant needs to send
a request using merchantsubscriptionrecurrencedemo.php to recur the subscription.
e)merchantsubscriptionrecurrencedemo.php
As described previously this recurs a subscription
g)basicapiresponsehandlerdemo.php
This php file provides a response handler for API V2.5 notifications. You'll need to specify the
path in your Integration settings to this file.
2. "library" directory:
This contains the classes defined to describe the API structure so as to easily
define and add XML entries by defining objects of these classes.
a) googlecart.php:
------------------
This is the main class which must be instantiated to post a cart.
It requires a merchant ID, Key, which server is to be used for the transactions
(Sandbox or Production), and currency.
It also has methods to add items, shipping options, tax options and
merchant-calculation details.
b) googleitem.php:
------------------
This class is instantiated for every item to be added to the cart.
It requires the item name, description, price and quantity to be specified.
c) googleshipping.php:
----------------------
These classes are used for shipping methods that will be added to the cart.
It requires the shipping name and price to be specified.
Other methods allow specification of the shipping restrictions.
d) googletax.php:
---------------------
These classes are used to define tax rules for the tax tables. These may be
rules for default or alternate tax tables. Methods have been provided to add
country codes and postal areas.
e) googleresponse.php:
----------------------
An instance of this class is created in the responsehandlerdemo.php.
This again requires the merchant ID and merchant Key to be specified.
All notifications are parsed and the merchant can take required action
when a particular notification is received.
f) googlerequest.php:
----------------------
An instance of this class is created in the responsehandlerdemo.php.
This again requires the merchant ID and merchant Key to be specified.
There are methods provided to send all the different order processing
commands.
g) googlelog.php:
----------------------
This Class provides all the loggin for the Notification sent and received from
the Google Checkout Integration. There are several log levels.
h) googleresult.php:
--------------------
This class is used for merchant-calculations and is invoked for
each result in the merchant-calculations-result sent from the
merchant in response to a callback.
i) googlemerchantcalculations.php:
----------------------------------
In order to process merchant calculations, an instance of this
class is created. It is used to aggregate merchant results and
respond with the XML response for the callback.
j) googlesubscription.php
-------------------------
This class handles the subscriptions for Google Checkout.
k) googlepoll.php
This class generates the polling requests.
l) googlenotificationhistory.php
This class generates the notification history requests.
l) "xml-processing" directory:
------------------------------
i) gc_xmlbuilder.php:
-----------------
This class generates XML and consists of "push" and "pop"
methods to add open and close tags respectively.
This is used internally by the library classes to generate
XML file for posting carts.
ii)gc_xmlparser.php:
-----------------
This class parses XML documents using the SAX parser and is
compatible with PHP v4 and 5. It converts them to DOM form
returning the XML data in a PHP associative array.
This is used internally by the library classes to parse
XML requests and responses that are received from the
Checkout server.
3. Log files:
a. googleerror.log:
The log file records all the errors in the integration with Google Checkout API
system
b. googlemessage.log:
The log file records all the notification and order processing commands that are
sent and received and can be useful information for debugging purposes.