martivic / dialogflow-transactions-nodejs

A sample of the Transactions APIs in Actions on Google

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  1. Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
  2. Click Skip, located on the top right to skip over category selection menu.
  3. On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s).
  4. Select Custom intent, click BUILD. This will open a Dialogflow console. Click CREATE.
  5. Click on the gear icon to see the project settings.
  6. Select Export and Import.
  7. Select Restore from zip. Follow the directions to restore from the Transactions.zip file in this repo.
  8. Deploy the fulfillment webhook provided in the functions folder using Google Cloud Functions for Firebase:
    1. 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.
    2. Run firebase deploy --only functions and take note of the endpoint where the fulfillment webhook has been published. It should look like Function URL (transactions): https://${REGION}-${PROJECT}.cloudfunctions.net/transactions
  9. Go back to the Dialogflow console and select Fulfillment from the left navigation menu.
  10. Enable Webhook, set the value of URL to the Function URL from the previous step, then click Save.
  11. 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.
  12. On the left navigation menu under DEPLOY, click on Directory Infomration.
  13. Add your App info, including images, a contact email and privacy policy. This information can all be edited before submitting for review.
  14. Check the box at the bottom to indicate this app uses Transactions under Additional Information. Click Save.
  15. Set up a payment method for your account in the Google Assistant settings on your phone if you haven't set one up already.
  16. Return Actions on Google Console, on the left navigation menu under Test, click on Simulator.
  17. Click Start Testing and select the latest version (VERSION - Draft).
  18. Type Talk to my test app in the simulator, or say OK Google, talk to my test app to any Actions on Google enabled device signed into your developer account.
  19. Follow the instructions below to test a transaction.
  20. 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.

To test a transaction

  1. Determine a unique Order ID for the transaction you want to test, and replace the <UNIQUE_ORDER_ID> in the transaction_decision_action and transaction_decision_complete intent handlers. You may need to change this and redeploy your webhook each time you want to test a transaction confirmation.
  2. 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 and transaction_decision_complete intent handlers in index.js.
  3. 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.
  4. (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.
  5. To confirm the transaction, simply say/type confirm transaction. Here, the transaction_decision_action intent will be handled in index.js.
  6. You should see a transaction receipt, and a final confirmation of the order.

Troubleshooting

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> in index.js, and replace it each time you test the app.
  • The full transactions flow may only be testable on a phone.

To use the Order Update module (order-update.js),

  1. Visit the Google Cloud console for the project used in the Actions console.
  2. Navigate to the API Library.
  3. Search for and enable the Google Actions API.
  4. Navigate to the Credentials page in the API manager. You may need to enable access.
  5. Click Create credentials > Service Account Key
  6. Click the Select box under Service Account and click New Service Account
  7. Give the Service Account a name (like "PROJECT_NAME-order-update") and the role of Project Owner
  8. Select the JSON key type
  9. Click Create
  10. A JSON service account key will be downloaded to the local machine.
  11. In order-update.js, insert the file path to your key.
  12. In order-update.js, replace the <UNIQUE_ORDER_ID> placeholder string assigned to actionOrderId with the ID of the order you wish to update.
  13. Run the script to send an order update by opening a terminal and running the following command: node order-update.js.

References and How to report bugs

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.

About

A sample of the Transactions APIs in Actions on Google

License:Apache License 2.0


Languages

Language:JavaScript 100.0%