An easy way to interact with the QuickBooks API in your NestJS applications.
- Authorization workflow
- Company's info
- Items
- Invoices
- Payments
- Customers
- Vendors
npm i --save @recursyve/nestjs-quickbooks
import { QuickBooksModule, QuickBooksScopes } from "@recursyve/nestjs-quickbooks";
@Module({
imports: [
QuickBooksModule.forRoot({
config: {
mode: "sandbox",
clientId: "clientId",
clientSecret: "clientSecret",
scopes: [QuickBooksScopes.Accounting],
serverUri: "http://localhost:3000",
redirection: {
successUrl: "http://localhost:3000/success",
errorUrl: "http://localhost:3000/error"
}
}
})
]
})
export class AppModule {}You can set the config in the QuicksBooksModule forRoot function. You can also set the configuration with environment variable.
| configuration | Environment variable | Definition |
|---|---|---|
| mode | QUICKBOOKS_MODE | QuickBooks mode (sandbox or production) |
| clientId | QUICKBOOKS_CLIENT_ID | Your Quickbooks application client id |
| clientSecret | QUICKBOOKS_CLIENT_SECRET | Your Quickbooks application client secret |
| scopes | QUICKBOOKS_CLIENT_SCOPES | Quickbooks API scopes |
| serverUri | QUICKBOOKS_SERVER_URI | Your NestJS application URI |
| redirection.successUrl | QUICKBOOKS_REDIRECT_SUCCESS | Redirection URL after authorization success |
| redirection.errorUrl | QUICKBOOKS_REDIRECT_ERROR | Redirection URL after authorization error |
The Authorization workflow is embedded in the library. Two routes are provided.
- /quickbooks/auth: Redirects to quickbooks for authorization
- /quickbooks/auth/return: The redirection uri, you need to set this uri in your QuickBooks application
The result of an authorization is stored in the QuickBooksStore. By default the LocalStore is used, which means that the tokens and realm are saved localy.
You can override the QuickBooksStore with your own Store implementation.
import { QuickBooksModule, QuickBooksStore } from "@recursyve/nestjs-quickbooks";
@Module({
imports: [
QuickBooksModule.forRoot({
imports: [MyStoreImplementationModule],
store: {
provide: QuickBooksStore,
useClass: MyStoreImplementation
}
})
]
})
export class AppModule {}QuickbooksWebhooksModule registers a route-scoped JSON body parser on POST /quickbooks/webhook that:
- Accepts
application/json,application/cloudevents+json, andapplication/cloudevents-batch+json(Intuit’s CloudEvents types use the latter two). - Sets
req.rawBodyin the parserverifycallback soQuickBooksWebhooksGuardcan HMAC the same bytes Intuit signed.