Article | Date posted : 19 June, 2014 | Updated on : 28 January, 2015

How to use Google Wallet for Digital Goods with PHP

Sponsored Links

In this tutorial I will explain how to integrate Google Wallet for Digital Goods with your PHP website using the sandbox for testing purposes, which we will later change over to a live working payment gateway. In this example we will be using a library to encode and decode our product data.

Remember this example is only for Digital Goods, physical goods can not be purchased with this payment gateway.

Step 1 : Register a sandbox account



The sandbox as the word suggest is an environment for you to play in, in this play ground no real payments can be made and are for development purposes only.

We first need to register ourselves a sandbox account. Once you have registered yourself a new account we need to find our Seller Identifier and Seller Secret key. These details are found on the sandbox settings page.

Step 2 : Upload quick guide for digital goods

The next step is to upload the library with a quick start sample, the files are available for download from github.

Unzip and upload all it’s contents to ether a predefined include path or anywhere on your server. I recommend you to place the folder outside of your domain root. This to ensure that your secret key can not be accidentally seen by outsiders.

For this tutorial we will assume you have uploaded your contents to a folder named google-wallet

Step 3 : Setting the Merchant ID and Secret Key

Open up seller_info.php and change the info inside the class SellerInfo

Step 4 : Setting up our first payment option

Open up the file named generate_token.php, inside this file you will be able to ether generate dynamic payment options or static options using your php skills.

Inside the file you will find a predefined option, for each option you need to use the following variables

Step 5 : Including the payment button

Including all files and elements into your php document to enable all functionality. Lets say you have a file named mynewproduct.php

Inside this document we will want to include the following necessary elements.

Step 6 : Testing out the button



When clicking on the button we have to be aware that we can not purchase from ourselves, so you need to register yourself another Google account to do a test payment.

If you have done everything correctly, you will get a popup with Google Wallet payment, to test out the Buy button you can use a Visa test card 4111 1111 1111 1111 using any expiry and any CVV/CVC code.

You should now see a successful transaction.

Step 7 : Setting up a payment postback



Setting up your postback is very easy, simply add a secret url to the postback URL: inside your sandbox settings.

We will now create the folder location and insert a index.php file.

What Google requires is a response of the order id, this id can be decoded from the postback google provides. The example below will show you what the basic requirements are, which is to echo out the order id.

To get all of the other data you can check where it is located by using print_r($decodedJWT);

For example if you want to get your own sellerData you get this via

Now you can insert all the data into your database to update the users settings.

Step 8 : Changing over to the live payment gateway

  • To enable Google Wallet to work in a live environment you need to register yourself an Google Wallet Account
  • Get your secret key and seller id, and setup your postback url from your Google Wallet Settings Page.
  • Update your seller_info.php file
  • Change the javascript from the sandbox to the live version

If you need any help or have questions please comment below or use our contact form.

[contact-form][contact-field label=’Name’ type=’name’ required=’1’/][contact-field label=’Email’ type=’email’ required=’1’/][contact-field label=’Website’ type=’url’/][contact-field label=’Comment’ type=’textarea’ required=’1’/][/contact-form]

Sponsored Links


Leave a Reply

Your email address will not be published. Required fields are marked *

Follow me on Google+

Google Shopping Data Feed Generator

Sponsored Links

Hire Me