In-App Payments Service

This service is currently available to Chrome users on the dev channel.

Description: Use the In-App Payments Service to sell digital and virtual goods within a Chrome app.
Availability: Chrome 29
Sample: in-app-payments
Learn more: Google Wallet;
Google Wallet for Digital Goods

Overview

You can use the In-App Payments Service to sell digital and virtual goods within your app. When you use the In-App Payments Service, the Chrome Wallet App, which is embedded in Chrome, communicates with the Google Wallet servers and handles all the required checkout details, so your app does not have to process any financial transactions. The In-App Payments Service requires you to package a JavaScript file, buy.js, with your app to trigger the purchase flow.

Purchase flow

When a customer clicks a "Buy" button in your app to make a purchase, the Chrome Wallet App displays a payment processing window on top of your application window:

screenshot: in-app-payments review dialog

When the user clicks the "Buy" button in the payment processing window, the Google Wallet server processes the payment and displays a purchase confirmation dialog to the user, as shown below. The success or failure callback in your app is invoked appropriately.

screenshot: in-app-payments confirmation dialog

If the user is not signed up for Google Wallet, the Chrome Wallet App takes the user through the sign-up flow:

screenshot: Google wallet set up dialog

Sample code

The following code snippet illustrates how to initiate the purchase flow in an app. The parameters for the buy() method are described below.

google.payments.inapp.buy({
  parameters: {},
  jwt: 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNDIwNDk' +
       '1MzA5NDM1MjE2ODU3MSIsImF1ZCI6Ikdvb2dsZSI' +
       'sInR5cCI6Imdvb2dsZS9wYXltZW50cy9pbmFwcC9' +
       'zdWJzY3JpcHRpb24vdjEiLCJpYXQiOjEzNTg0NTc' +
       'yNjksImV4cCI6MjM1ODQxMjMzNDMsInJlcXVlc3Q' +
       'iOnsiaW5pdGlhbFBheW1lbnQiOnsicHJpY2UiOiI' +
       'xMC41MCIsImN1cnJlbmN5Q29kZSI6IlVTRCIsInB' +
       'heW1lbnRUeXBlIjoicHJvcmF0ZWQifSwicmVjdXJ' +
       'yZW5jZSI6eyJwcmljZSI6IjQuOTkiLCJjdXJyZW5' +
       'jeUNvZGUiOiJVU0QiLCJzdGFydERhdGUiOiIxMzU' +
       '4NDYzMjY5IiwiZnJlcXVlbmN5IjoibW9udGhseSI' +
       'sIm51bVJlY3VycmVuY2VzIjoiMTIifSwibmFtZSI' +
       '6IlBpZWNlIG9mIENha2UiLCJkZXNjcmlwdGlvbiI' +
       '6IkEgZGVsaWNpb3VzIHBpZWNlIG9mIHZpcnR1YWw' +
       'gY2FrZSIsInNlbGxlckRhdGEiOiJZb3VyIERhdGE' +
       'gSGVyZSJ9fQ.sXd39R7MNNfDFa-jnlTNu2C2te-_' +
       'x9--87Phfdr5GrE',
  success: logSuccess,
  failure: logFailure
});

How to use the Service

Using the In-App Payments Service in an app is similar to using the Google Wallet for Digital Goods API in a web site. The integration steps below are based on the Google Wallet for Digital Goods Tutorial, but there are a few key differences for Apps. These differences are summarized below and described in detail in the integration steps.

Follow these steps to use the In-App Payments Service in your app:

  1. Generate a JSON Web Token (JWT) for each item to be purchased.
    You can generate JWTs using a server, or you can pre-generate JWTs for use in your app.

    Note: If you use pre-generated JWTs, you should generate the JWTs outside of your app, and include the generated tokens in your app. NEVER include the Seller secret you use to generate tokens in your app. If you need to generate JWTs dynamically, you should use a server.

  2. Include buy.js in your app.
    Due to the security restrictions in the Content Security Policy for Chrome apps, you cannot include the buy.js library from an external location. Instead, you must package the library with your app, and load it from the packaged location.
  3. Create success and failure callback handlers.
    Success and failure callback handlers let your app react to the purchase flow's completion.
  4. Call buy().
    When a customer clicks a "Buy" button in your app, call buy() to initiate the purchase flow.

    For Apps, you must call buy() with an extra parameter called parameters. This parameter currently has one field, env, which specifies the environment in which to process a payment. You can set this field to either prod (production server that accepts real credit cards), or sandbox (test server that accepts test credit cards to simulate transactions). The default setting is sandbox.

  5. (Optional) Acknowledge purchase notification.
    You can specify a postback URL to make sure that the customer has paid for an item.
  6. Get set up as a seller on Google Wallet.
    You must sign up for Google Wallet for digital goods in order to use the In-App Payments Service.
  7. Switch to the production server.
    Switch from the sandbox server to the production server and test your app using real credit cards.

Recurring billing

The In-App Payments Service supports automated recurring billing. To set up recurring billing, follow the instructions for setting up subscriptions for the Google Wallet for Digital Goods API, but note again the differences described above (you can use pre-generated JWT tokens; you must package buy.js with your app; and you must specify an additional parameter in the call to buy()).

Sample app

For a simple app that demonstrates how to use the In-App Payments Service, see:

  • source code
  • published app (requires Chrome 29 or higher)
  • You can install and run the published app from the Chrome Web Store to try out the in-app payment purchase flow. The app has options to use either the production server or the sandbox server. When testing with the sandbox server, use these test credit card numbers, which pass basic checks by the Google Wallet for Digital Goods system.