Google Checkout integration for PHP

Source: Internet
Author: User
Tags configuration settings cryptographically secure php server php sample code
What is payment gateway integration?

A payment gateway can be defined as a third party service, which is a combination of hardware and software that provides an interface to the bank credit card processing network. the credit card information is collected and is transferred over the Internet to the credit card processors in the encrypted format for transaction purpose. some well-known payment methods are authorizenet, Google Checkout, usaepay, Verisign and PayPal.

What is Google Checkout?

  • Using Google Checkout buying from stores into ss the Web becomes simple and also facilitates you to keep track of all the orders.
  • The Google Checkout's fraud protection policy protects you against all the unauthorized purchases made via Google Checkout. Another advantage is that the Google Checkout does not share the history of the purchasers with other sellers.
  • With Google Checkout your email is well protected and is kept confidential. Tracking down your purchase history list is also simple.

Methods To integrate with Google Checkout:

Google Checkout provides three different types of Integration Methods

  • Buy now buttons (provided by Google Checkout)
  • Valid e-commerce partners
  • Google Checkout API (Code integration with Google Checkout)

1) Buy now buttons

If you do not require the shopping card functionality, you can simply integrate with Google Checkout using the Google Checkout buy now buttons. you can have these buttons be displayed next to the products you are selling by just adding the Google Checkout's HTML code to your website. visitors/buyers who click this button will be automatically directed to the secure Google Checkout page where they can complete their purchase.

Integration requirements:You have a working knowledge of your website's html

2) E-commerce partners

If your shopping card application is being provided by one of the Google Checkout's partners, you can simply integrate your shopping cart and order processing functionalities with Google Checkout.

Integration requirements:You have a shopping cart provided by an valid e-commerce partner.

3) Google Checkout API

Integrating our website which has shopping cart and order processing system via the Google Checkout API (sample codes) is a simple process.
The Google Checkout API is available in the following codes:

  1. ASP (Active Server Pages)
  2. . Net (Visual Studio. NET)
  3. PHP (Hypertext Preprocessor)
  4. In Java 1.5
  5. In Java 1.4

Integrating with Google Checkout by using the Google Checkout API with PHP can be seen in the sample code. you can download the sample code provided by the Google Checkout API (PHP) from here» PHP sample code

**Before going to use the sample code provided by Google Checkout you need to check the following configuration settings are available in your php server.

1)PHP version-PHP v4.3.0 or later(But not greater or equal to PhP 5.0, because current Google Checkout API codes supports only the lower versions of PHP 5.0 ).

2)Curl-libcurl v7.9.0 or laterLibcurl is an implementation of curl (PHP supports libcurl, that allows you to connect and communicate to divide different types of servers by using different protocols. libcurl currently supports the HTTP, https, FTP, Gopher, telnet, dict, file, and LDAP protocols ), which allows you to send XML over HTTPS using server-to-Server http post requests.

3)Libxml-2.4.14 or later.Libxml installa Dom XML library (this Dom XML library is used to parse and construct the XML messages ).

Some important PHP library files provided by the Google Checkout

  • Globalapifunctions. php-This library contains functions that are used to communicate with multiple Google Checkout APIs.
    Some important functions are

    1. Getmerchantid-The getmerchantid function returns your Google Checkout merchant ID (you can get this merchant ID by registering as a merchant with the Google Checkout ).
    2. Getmerchantkey-The getmerchantkey function returns your Google Checkout merchant key (you can get this merchant key by registering as a merchant with the Google Checkout)
    3. Calchmacsha1-The calchmacsha1 function uses a checkout shopping cart XML file, which contains information about an order, and your merchant key to compute a cryptographically secure HMAC-SHA1 Value
    4. Sendrequest-The sendrequest function verifies that you have provided values for all of the parameters needed to send a Google Checkout or order processing API request.
  • Responsehandlerapifunctions. php-This library contains functions that handle synchronous responses that Google Checkout sends in response to your API requests. Some important functions are

    1. Processxmldata-The processxmldata function creates a DOM object representation of the XML document stored ed from Google Checkout
    2. Processrequestreceivedresponse-The processrequestreceivedresponse function has es a synchronous Google Checkout response to an API request originating from your site.
    3. Processerrorresponse-The processerrorresponse function has es a synchronous Google Checkout response to an API request originating from your site.
  • Checkoutapifunctions. php-This library contains functions for systematically building XML documents that can be encoded in Google Checkout checkout API requests some important functions are

    1. Createitem-The createitem function constructs the XML for a single In a shopping cart (here we have to list our each products as a item ).
    2. Createshoppingcart-The createshoppingcart function constructs the XML for Element in a checkout API request.
    3. Createcheckoutshoppingcart-The createcheckoutshoppingcart function returns XML structure, which contains all of the items and checkout-related information for an order.

The screen shots for the Google Checkout integration for an online event registration

1) your cart
2) sign in to Google Checkout
3) Review & place your order
4) Thanks page

A sample Shoping cart with Google Checkout button

Your sample cart page

Return top

After pressing the Google Checkout button, you will get the following sign in page

Sign in to Google Checkout

In this below page you can view two different items
1) the event name (the event which you need to book online)
2) the service charge (the service charge amount for the participates event ticket)
In this page if you are an already existing user, you will given your email address as user name and your password to login into the Review & place the order page.
Else you will have a provision to enter your credit card details and need to create an account with the Google Checkout.

Return top

After successful register/sign up you will get the following page

Review & place your order

In thisReview & place order pageYou will confirm your order details and place your order. after the successful placement of order, a copy of your order will be emailed to the merchant and also a copy to the person who place the order.
An additional feature available in the Google Checkout is an copy will be stored in your purchase history list.

Return top

Thanks page

After pressing the place order button you will get the following page

Return top

Vital informations needed to configure the Google Checkout**

  1. PHP version-PHP v4.3.0 or later
  2. Curl-libcurl v7.9.0 or later
  3. Libxml-2.4.14 or later.
  4. SSL Certificate **-if you are an merchant, and needed to calculate the order status after the order placement means you need to install SSL Certificate (Secure Socket Layer, this is a certificate which is installed on a secure server. it is used to identify the merchant using it and to encrypt the credit card) in your server and place a PHP file to capture the response from the Google Checkout.

Sample merchant calculation coding to capture the response acknowledgement from the Google Checkout for the every order.

// Retrieve the XML sent in the http post request to the responsehandler
$ Xml_response = $ http_raw_post_data;
Get rid of PHP's magical escaping of quotes
If (get_magic_quotes_gpc ()){
$ Xml_response = stripslashes ($ xml_response );
// Capture the return response XML from the Google Checkout.
Fnwritexml ($ xml_response );
}
Function fnwritexml ($ string ){
$ File = "ssl_return.txt ";
If (file_exists ($ file )){
$ Fileid = fopen ($ file, "");
$ Strmsg = "";
$ Strmsg. = "************************************** * ************/R/N ";
$ Strmsg. = $ string;
$ Strmsg. = "/R/n ********************************** * ****************/R/N ";
Fwrite ($ fileid, $ strmsg );
Fclose ($ fileid );
} Else {
$ Fileid = fopen ($ file, "");
$ Strmsg = $ string;
Fwrite ($ fileid, $ strmsg );
Fclose ($ fileid );
}
}

By downloading the file ssl_return.txt you will get the response XML from the Google Checkout. parse the response XML, according to your needs and manipulate the merchant calculation codings.

Functional definitions:

Stripslashes-Returns a string with backslashes stripped off. (/'becomes' and so on.) Double backslashes are made into a single backslash.

Get_magic_quotes_gpc ()-Gets the current active Configuration Setting of magic quotes.

Fopen-This key word is used to open the specified file in the specified server path
If the open fails, the function returns false.
For example: fopen ("sample.txt", "");
Here the first argument is the file name and the second one is the file open mode type. some of the file open mode types are ('r'-read only, 'r + '-Reading & writing, 'w'-writing only, 'W + '-Reading & writing, 'a'-append writing only, 'a +'-Reading & append writing only)

File_exists-Returns true if the file specified by filename exists; else it returns false.
* This function will not work on remote files;

Fwrite-It writes the contents of string to the file stream pointed to by FP. if the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.

Fclose-The file pointed to by FP is closed. returns true on success, false on failure.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.