Actions on Google: Transactions Sample using Node.js
This sample shows everything you need to facilitate transactions for your app.
It includes the main checkout flows, including checking for transaction
requirements, getting the user's delivery address, and confirming the
transaction. There is also an order update module (order-update.js
) that can
be used to asynchronously update order status at any time.
This sample provides examples of transaction payment configurations for
action provided payments and transactions without payment, but the Actions on
Google library also offers functionality for Google provided payment by
providing tokenization parameters from your payment processor. There are
comments in index.js
demonstrating this behavior.
Setup Instructions
Steps
- Use the Actions on Google Console to add a new project with a name of your choosing.
- Click Use API.AI and then Create Actions on API.AI.
- Click Save to save the project.
- Click on the gear icon to see the project settings.
- Select Export and Import.
- Select Restore from zip. Follow the directions to restore from the Transactions.zip file in this repo.
- Deploy the fulfillment webhook provided in the functions folder using Google Cloud Functions for Firebase:
- Follow the instructions to set up and initialize Firebase SDK for Cloud Functions. Make sure to select the project that you have previously generated in the Actions on Google Console and to reply
N
when asked to overwrite existing files by the Firebase CLI. - Run
firebase deploy --only functions
and take note of the endpoint where the fulfillment webhook has been published. It should look likeFunction URL (transactions): https://${REGION}-${PROJECT}.cloudfunctions.net/transactions
- Follow the instructions to set up and initialize Firebase SDK for Cloud Functions. Make sure to select the project that you have previously generated in the Actions on Google Console and to reply
- Go back to the API.AI console and select Fulfillment from the left navigation menu.
- Enable Webhook, set the value of URL to the
Function URL
from the previous step, then click Save. - Open API.AI's Integrations page, open the Settings menu for Actions on Google, click Authorize if needed, then click Update.
- Click Visit Console to return to the Actions console, and set up your App info, including images, a contact email, and privacy policy. This information can all be edited before submitting for review.
- Check the box at the bottom to indicate this app uses Transactions.
- Set up a payment method for your account in the Google Assistant settings on your phone if you haven't set one up already.
- Return to your App overview, and hit Test.
- In the left panel, click Simulator.
- Type
Talk to my test app
in the simulator, or sayOK Google, talk to my test app
to any Actions on Google enabled device signed into your developer account. - Follow the instructions from the app to test transactions.
- To test payment when confirming transaction, uncheck the box in the Actions console simulator indicating testing in Sandbox mode.
For more detailed information on deployment, see the documentation.
order-update.js
),
To use the Order Update module (- Visit the Google Cloud console for the project used in the Actions console.
- Navigate to the Credentials page in the API manager. You may need to enable access.
- Click Create credentials > Service Account Key
- Click the Select box under Service Account and click New Service Account
- Give the Service Account a name (like "PROJECT_NAME-order-update") and the role of Project Owner
- Select the JSON key type
- Click Create
- A JSON service account key will be downloaded to the local machine.
- In
order-update.js
, insert the file path to your key.
References and How to report bugs
- Actions on Google documentation: https://developers.google.com/actions/.
- If you find any issues, please open a bug here on GitHub.
- Questions are answered on StackOverflow.
How to make contributions?
Please read and follow the steps in the CONTRIBUTING.md.
License
See LICENSE.md.
Terms
Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.
Google+
Actions on Google Developers Community on Google+ https://g.co/actionsdev.