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.
- Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
- Click Skip, located on the top right to skip over category selection menu.
- On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s).
- Select Custom intent, click BUILD. This will open a Dialogflow console. Click CREATE.
- 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 Dialogflow 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. - Select Integrations from the left navigation menu and open the Integration Settings menu for Actions on Google. Click Manage Assistant App, which will take you to the Actions on Google Console.
- On the left navigation menu under DEPLOY, click on Directory Infomration.
- Add 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 under Additional Information. Click Save.
- 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 Actions on Google Console, on the left navigation menu under Test, click on Simulator.
- Click Start Testing and select the latest version (VERSION - Draft).
- 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 below to test a transaction.
- 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.
- Determine a unique Order ID for the transaction you want to test, and
replace the
<UNIQUE_ORDER_ID>
in thetransaction_decision_action
andtransaction_decision_complete
intent handlers. You may need to change this and redeploy your webhook each time you want to test a transaction confirmation. - Determine the payment method
you wish to accept in the app. The app uses action provided payment by default.
If you want to use a Google-provided payment instrument, uncomment the annotated
code in the
transaction_decision_action
andtransaction_decision_complete
intent handlers inindex.js
. - It must be confirmed that the user can transact.
To check this, say/type either
check transaction with Google payment
- to check requirements for a transaction where the user pays with an Google-provided payment instrument stored under their account.check transaction with action payment
- to check requirements for a transaction where the user will pay with a payment instrument that you are providing.
- (Optional) The user's delivery address can then be acquired by saying/typing
get delivery address
. This will present the user with a flow to select from an available delivery address. - To confirm the transaction, simply say/type
confirm transaction
. Here, thetransaction_decision_action
intent will be handled inindex.js
. - You should see a transaction receipt, and a final confirmation of the order.
If the app isn't working, try the following:
- Make sure your Actions console project has filled App Information section, including name, images, email address, etc. This is required for testing transactions. After changing this, you may need to re-enable testing in the Actions console.
- Make sure your Actions console project indicates that it is using Transactions using the checkbox at the bottom of App Information
- Make sure you've replaced the
<UNIQUE_ORDER_ID>
inindex.js
, and replace it each time you test the app. - The full transactions flow may only be testable on a phone.
- Visit the Google Cloud console for the project used in the Actions console.
- Navigate to the API Library.
- Search for and enable the Google Actions API.
- 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. - In
order-update.js
, replace the<UNIQUE_ORDER_ID>
placeholder string assigned to actionOrderId with the ID of the order you wish to update. - Run the script to send an order update by opening a terminal and running the following command:
node order-update.js
.
- 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.
Please read and follow the steps in the CONTRIBUTING.md.
See LICENSE.md.
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.
Actions on Google Developers Community on Google+ https://g.co/actionsdev.