SampleApp-Webhooks-Java
Welcome to the Intuit Developer's Webhooks Java Sample App.
This sample app is meant to provide working examples of how to integrate your app with the Intuit Small Business ecosystem. Specifically, this sample application demonstrates the following:
- Implementing webhooks endpoint to receive event notifications.
- Best practices to be followed while processing the event notifications.
- Sample code using QuickBooks Online SDK to call CDC API to sync data between the app and the QuickBooks Online company.
Please note that while these examples work, features not called out above are not intended to be taken and used in production business applications. In other words, this is not a seed project to be taken cart blanche and deployed to your production environment.
For example, certain concerns are not addressed at all in our samples (e.g. security, privacy, scalability). In our sample apps, we strive to strike a balance between clarity, maintainability, and performance where we can. However, clarity is ultimately the most important quality in a sample app.
Therefore there are certain instances where we might forgo a more complicated implementation (e.g. caching a frequently used value, robust error handling, more generic domain model structure) in favor of code that is easier to read. In that light, we welcome any feedback that makes our samples apps easier to learn from.
- Requirements
- First Use Instructions
- Running the code
- Configuring the endpoint
- Project Structure
- Reset the App
In order to successfully run this sample app you need a few things:
- Java 1.8
- A developer.intuit.com account
- An app on developer.intuit.com and the associated app token, consumer key, and consumer secret.
- QuickBooks Java SDK (already included in the
lib
folder) - Two sandbox companies, connect both companies with your app and generate the oauth tokens.
- Clone the GitHub repo to your computer
- Fill in the
application.properties
file values (app token, consumer key, consumer secret) by copying over from the keys section for your app. - Fill in the
application.properties
file values (realmId, access token key, access token secret) with the oauth tokens generated while connecting with the company. - Also add webhooks subscribed entities and webhooks verifier token that was generated when you subscribed for webhoooks event.
Once the sample app code is on your computer, you can do the following steps to run the app:
- cd to the project directory
- Run the command:
./gradlew bootRun
(Mac OS) orgradlew.bat bootRun
(Windows) - Wait until the terminal output displays the "Started Application in xxx seconds" message.
- Open your browser and go to http://localhost:8080/companyConfigs - This will list the companies in the repository for which you have subscribed event notification.
- The webhooks endpoint in the sample app is http://localhost:8080/webhooks
- Once an event notification is received and processed, you can perform step 4 to see that the last updated timestamp has been updated for the realmId for which notification was received.
- To run the code on a different port, uncomment and update server.port property in application.properties
Webhooks requires your enpoint to be exposed over the internet. The easiest way to do that while you are still developing your code locally is to use ngrok. Here are the steps to configure ngrok
- Download and install ngrok
- Expose your localhost by running "./ngrok http 8080" on the command line.
- You will then get a forwarding url that looks something like this:
Forwarding https://cb063e9f.ngrok.io -> localhost:8080
(Remember to use only https url and not the http url for webhooks) This will expose localhost:8080 to the Internet. Your endpoint url will now be https://cb063e9f.ngrok.io/webhooks Copy this url and use it for setting up webhooks on developer.intuit.com for your app.
-
Standard Java coding structure is used for the sample app
-
Java code is located in the
src.main.java
directory- Controller classes are in under the controller folder:
- Queue implementation and processing classes are in under the service/queue folder:
- Encryption and payload validation implementation class is in the service/security folder:
- QBO API Service calls are implemented in the service/qbo folder:
-
Property files are located in the
src.main.resources
directory -
JUnit test files are located in the
src.test.java
directory
This app uses an in-memory temporary H2 database. The tables are loaded during startup with realmId and oauth tokens. The table is read and updated when webhooks notification is processed. Stopping the server will delete the records. The oauth tokens are encrypted and stored in the database. There is a sample encryption implementation provided using fake keys. For production use real keys, this can be updated in application.properties