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 |
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.
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:
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.
If the user is not signed up for Google Wallet, the Chrome Wallet App takes the user through the sign-up flow:
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
});
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.
buy() method with an extra parameter called parameters.Follow these steps to use the In-App Payments Service 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.
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.
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()).
For a simple app that demonstrates how to use the In-App Payments Service, see:
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.