1 <h1>Google Wallet for Digital Goods
</h1>
5 <td><strong>Description:
</strong></td>
6 <td>Use Google Wallet for digital goods to sell digital and virtual goods within a Chrome app.
</td>
9 <td><strong>Availability:
</strong></td>
13 <td><strong>Sample:
</strong></td>
14 <td><a href=
"https://github.com/GoogleChrome/chrome-app-samples/tree/master/in-app-payments">in-app-payments
</a></td>
17 <td><strong>Learn more:
</strong></td>
19 <a href=
"https://support.google.com/chrome_webstore/answer/1053354">Google Wallet
</a><br>
20 <a href=
"https://developers.google.com/commerce/wallet/digital/docs/">Google Wallet for Digital Goods
</a><br>
21 <a href=
"http://www.youtube.com/watch?v=Z3jryGggMCs">How-to Video
</a></td>
25 <h2 id=
"overview">Overview
</h2>
28 You can use Google Wallet for digital goods to sell digital and virtual goods within your app.
29 The Google Wallet for digital goods client app, which is embedded in Chrome, communicates with the
30 <a href=
"https://support.google.com/chrome_webstore/answer/1053354">Google Wallet
</a>
31 servers and handles all the required checkout details, so your app does not have to process any financial transactions.
32 Google Wallet for digital goods requires you to package a JavaScript file,
33 <a href=
"https://raw.github.com/GoogleChrome/chrome-app-samples/master/in-app-payments/buy.js">buy.js
</a>,
34 with your app to trigger the purchase flow.
37 <h2 id=
"flow">Purchase flow
</h2>
40 When a customer clicks a
"Buy" button in your app to make a purchase, Google Wallet for digital goods displays a payment processing window
41 on top of your application window:
44 <img src=
"{{static}}/images/wallet-review.png"
46 alt=
"screenshot: Google Wallet review dialog">
49 When the user clicks the
"Buy" button in the payment processing window, the Google Wallet server processes the payment
50 and displays a purchase confirmation dialog to the user, as shown below.
51 The success or failure callback in your app is invoked appropriately.
54 <img src=
"{{static}}/images/wallet-confirmation.png"
56 alt=
"screenshot: Google Wallet confirmation dialog">
59 If the user is not signed up for Google Wallet, Google Wallet for digital goods takes the user through the sign-up flow:
62 <img src=
"{{static}}/images/wallet-set-up.png"
64 alt=
"screenshot: Google Wallet set up dialog">
66 <h2 id=
"sample-code">Sample code
</h2>
69 The following code snippet illustrates how to initiate the purchase flow in an app.
70 The parameters for the
<code>buy()
</code> method are described below.
74 google.payments.inapp.buy({
76 jwt: 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNDIwNDk' +
77 '
1MzA5NDM1MjE2ODU3MSIsImF1ZCI6Ikdvb2dsZSI' +
78 'sInR5cCI6Imdvb2dsZS9wYXltZW50cy9pbmFwcC9' +
79 'zdWJzY3JpcHRpb24vdjEiLCJpYXQiOjEzNTg0NTc' +
80 'yNjksImV4cCI6MjM1ODQxMjMzNDMsInJlcXVlc3Q' +
81 'iOnsiaW5pdGlhbFBheW1lbnQiOnsicHJpY2UiOiI' +
82 'xMC41MCIsImN1cnJlbmN5Q29kZSI6IlVTRCIsInB' +
83 'heW1lbnRUeXBlIjoicHJvcmF0ZWQifSwicmVjdXJ' +
84 'yZW5jZSI6eyJwcmljZSI6IjQuOTkiLCJjdXJyZW5' +
85 'jeUNvZGUiOiJVU0QiLCJzdGFydERhdGUiOiIxMzU' +
86 '
4NDYzMjY5IiwiZnJlcXVlbmN5IjoibW9udGhseSI' +
87 'sIm51bVJlY3VycmVuY2VzIjoiMTIifSwibmFtZSI' +
88 '
6IlBpZWNlIG9mIENha2UiLCJkZXNjcmlwdGlvbiI' +
89 '
6IkEgZGVsaWNpb3VzIHBpZWNlIG9mIHZpcnR1YWw' +
90 'gY2FrZSIsInNlbGxlckRhdGEiOiJZb3VyIERhdGE' +
91 'gSGVyZSJ9fQ.sXd39R7MNNfDFa-jnlTNu2C2te-_' +
98 <h2 id=
"how-to">How to use Google Wallet for digital goods
</h2>
100 <p>Using Google Wallet for digital goods in a Chrome App is similar to using the
101 <a href=
"https://developers.google.com/commerce/wallet/digital/docs/">Google Wallet for digital goods API
</a> in a web site.
102 The integration steps below are based on the
103 <a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial">Google Wallet for digital goods tutorial
</a>,
104 but there are a few key differences for apps. These differences are summarized below and described in detail in the
109 <li>You can use pre-generated JSON Web Tokens (JWTs) in your app, rather than using a server to generate the tokens.
</li>
111 <li>You must package the
<a href=
"https://raw.github.com/GoogleChrome/chrome-app-samples/master/in-app-payments/buy.js">buy.js
</a>
112 library with your app, and load the library from its location in your package.
</li>
114 <li>You must call the
<code>buy()
</code> method with an extra parameter called
<code>parameters
</code>.
</li>
116 <li>The UI to process payments is displayed in a separate window on top of your application window, rather than in an iframe.
</li>
119 <p>Follow these steps to use Google Wallet for digital goods in your app:
</p>
122 <li><a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#1">Generate a JSON Web Token (JWT) for each item to be purchased.
</a>
123 <div class=
"indent-small">
124 You can generate JWTs using a server, or you can pre-generate JWTs for use in your app.
126 Note: If you use pre-generated JWTs, you should generate the JWTs outside of your app, and include
127 the generated tokens in your app.
128 <strong>NEVER
</strong> include the Seller secret you use to generate tokens in your app.
129 If you need to generate JWTs dynamically, you should use a server.
134 <li>Include
<a href=
"https://raw.github.com/GoogleChrome/chrome-app-samples/master/in-app-payments/buy.js">buy.js
</a> in your app.
135 <div class=
"indent-small">
136 Due to the security restrictions in the
137 <a href=
"contentSecurityPolicy.html">Content Security Policy
</a> for Chrome Apps,
138 you cannot include the
<a href=
"https://raw.github.com/GoogleChrome/chrome-app-samples/master/in-app-payments/buy.js">buy.js
</a>
139 library from an external location. Instead, you must package the library with your app, and load it from the packaged location.
143 <li><a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#3">Create success and failure callback handlers.
</a>
144 <div class=
"indent-small">
145 Success and failure callback handlers let your app react to the purchase flow's completion.
149 <li><a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#4">Call buy().
</a>
150 <div class=
"indent-small">
151 When a customer clicks a
"Buy" button in your app, call
<code>buy()
</code> to initiate the purchase flow.
153 For Apps, you must call
<code>buy()
</code> with an extra parameter called
<code>parameters
</code>.
154 This parameter currently has one field,
<code>env
</code>, which specifies the environment in which to process a payment.
155 You can set this field to either
<code>prod
</code> (production server that accepts real credit cards), or
156 <code>sandbox
</code> (test server that accepts test credit cards to simulate transactions).
157 The default setting is
<code>sandbox
</code>.
162 <li>(Optional)
<a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#5">Acknowledge purchase notification.
</a>
163 <div class=
"indent-small">
164 You can specify a postback URL to make sure that the customer has paid for an item.
168 <li><a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#6">Get set up as a seller on Google Wallet.
</a>
169 <div class=
"indent-small">
170 You must sign up for Google Wallet in order to use Google Wallet for digital goods.
174 <li><a href=
"https://developers.google.com/commerce/wallet/digital/docs/tutorial#7">Switch to the production server.
</a>
175 <div class=
"indent-small">
176 Switch from the sandbox server to the production server and test your app using real credit cards.
181 <h2 id=
"recurring">Recurring billing
</h2>
183 <p>Google Wallet for digital goods supports automated recurring billing. To set up recurring billing, follow the
184 instructions for setting up
185 <a href=
"https://developers.google.com/commerce/wallet/digital/docs/subscriptions">subscriptions
</a>
186 for the Google Wallet for digital goods API,
187 but note again the differences described above (you can use pre-generated JWT tokens;
188 you must package
<a href=
"https://raw.github.com/GoogleChrome/chrome-app-samples/master/in-app-payments/buy.js">buy.js
</a>
189 with your app; and you must specify an additional parameter in the call to
<code>buy()
</code>).
191 <h2 id=
"sample-app">Sample app
</h2>
194 For a simple app that demonstrates how to use Google Wallet for digital goods, see:
198 <li><a href=
"https://github.com/GoogleChrome/chrome-app-samples/tree/master/in-app-payments">source code
</a></li>
199 <li><a href=
"https://chrome.google.com/webstore/detail/moldiohggmfllblgmikpeoagipenlcae">published app
</a> (requires Chrome
29 or higher)
</li>
203 You can install and run the published app from the Chrome Web Store to try out the in-app payment purchase flow.
204 The app has options to use either the production server or the sandbox server. When testing with the sandbox server,
205 use these
<a href=
"https://developers.google.com/commerce/wallet/digital/docs/testing">test credit card numbers
</a>,
206 which pass basic checks by the Google Wallet for digital goods system.