kiranpatil353 / google-checkout-php-sample-code

Automatically exported from code.google.com/p/google-checkout-php-sample-code
0 stars 0 forks source link

Sample PHP code for integration of Google Checkout with the merchant site v1.3.2

         File structure and function
        ----------------------------

Note: You now need to specify your CA cert bundle to secure the server to server API requests. The typical default path on a linux machine is /etc/ssl/certs/ca-certificates.crt.

For more information about generating a cert bundle or for Windows information please review http://curl.haxx.se/docs/sslcerts.html

To extract CA certs from mozilla.org please review the following page: http://curl.haxx.se/docs/caextract.html

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. You must specify your certificate path so cURL can verify the SSL certificate. The default path is "/etc/ssl/certs/ca-certificates.crt";

    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 You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

    d) basicapiresponsehandlerdemo.php:

    This is an implementation of the latest Basic API for Google Checkout. It combines a few notifications to create a simpler order processing flow. http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Processing.html You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

    e) lineitemshipping.php:

    This demo showcases the ability to ship individual line items in an order. http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Processing.html#order_processing_api You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

    f) merchantsubscriptionrecurrencedemo.php:

    This is an implementation of merchant initiated recurrences for subscriptions. http://code.google.com/apis/checkout/developer/Google_Checkout_Beta_Subscriptions.html You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

    g) pollingdemo.php

    This is a demo of the beta Polling API that polls for notifications. http://code.google.com/apis/checkout/developer/Google_Checkout_Beta_Polling_API.html You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

    h) subscriptiondemo.php: This is an implementation of the beta subscriptions API that allows you to create order which automatically recur. http://code.google.com/apis/checkout/developer/Google_Checkout_Beta_Subscriptions.html You must specify your certificate path so cURL can verify the SSL certificate.
    The default path is: "/etc/ssl/certs/ca-certificates.crt";

  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) googlenotificationhistory.php:

    This class handles notification history requests which are used with the Basic API to pull notifications based on order ID.

    k) googlesubscription.php:

    This class represents a subscription request.

    l) htmlSignatureGen.php:

    This class allows you to generate a signature for signed HTML API requests.

    m) "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.