Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# QuickBooks API Credentials
QB_CLIENT_ID=your_client_id_here
QB_CLIENT_SECRET=your_client_secret_here
QB_REALM_ID=your_realm_id_here

# For Authorization Flow Test
QB_AUTH_CODE=your_auth_code_here

# For Token Reuse Test
QB_REFRESH_TOKEN=your_refresh_token_here
QB_ACCESS_TOKEN=your_access_token_here
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# IntelliJ
.idea
CLAUDE.md
.claude
.env
16 changes: 12 additions & 4 deletions examples/auth_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ package examples

import (
"fmt"
"os"
"testing"

"github.com/joho/godotenv"
"github.com/rwestlund/quickbooks-go"
"github.com/stretchr/testify/require"
)

func TestAuthorizationFlow(t *testing.T) {
clientId := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId := "<realm-id>"
_ = godotenv.Load("../.env") // Load .env file if it exists

clientId := os.Getenv("QB_CLIENT_ID")
clientSecret := os.Getenv("QB_CLIENT_SECRET")
realmId := os.Getenv("QB_REALM_ID")
authorizationCode := os.Getenv("QB_AUTH_CODE")

if clientId == "" || clientSecret == "" || realmId == "" || authorizationCode == "" {
t.Skip("Skipping TestAuthorizationFlow; QB_CLIENT_ID, QB_CLIENT_SECRET, QB_REALM_ID, or QB_AUTH_CODE not set")
}

qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", nil)
require.NoError(t, err)

// To do first when you receive the authorization code from quickbooks callback
authorizationCode := "<received-from-callback>"
redirectURI := "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl"
bearerToken, err := qbClient.RetrieveBearerToken(authorizationCode, redirectURI)
require.NoError(t, err)
Expand Down
20 changes: 15 additions & 5 deletions examples/reuse_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ package examples

import (
"fmt"
"os"
"testing"

"github.com/joho/godotenv"
"github.com/rwestlund/quickbooks-go"
"github.com/stretchr/testify/require"
)

func TestReuseToken(t *testing.T) {
clientId := "<your-client-id>"
clientSecret := "<your-client-secret>"
realmId := "<realm-id>"
_ = godotenv.Load("../.env") // Load .env file if it exists

clientId := os.Getenv("QB_CLIENT_ID")
clientSecret := os.Getenv("QB_CLIENT_SECRET")
realmId := os.Getenv("QB_REALM_ID")
refreshToken := os.Getenv("QB_REFRESH_TOKEN")
accessToken := os.Getenv("QB_ACCESS_TOKEN")

if clientId == "" || clientSecret == "" || realmId == "" || refreshToken == "" || accessToken == "" {
t.Skip("Skipping TestReuseToken; required environment variables not set")
}

token := quickbooks.BearerToken{
RefreshToken: "<saved-refresh-token>",
AccessToken: "<saved-access-token>",
RefreshToken: refreshToken,
AccessToken: accessToken,
}

qbClient, err := quickbooks.NewClient(clientId, clientSecret, realmId, false, "", &token)
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/rwestlund/quickbooks-go

go 1.20
go 1.25

require (
github.com/stretchr/testify v1.9.0
golang.org/x/oauth2 v0.19.0
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.11.1
golang.org/x/oauth2 v0.35.0
gopkg.in/guregu/null.v4 v4.0.0
)

Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/oauth2 v0.35.0 h1:Mv2mzuHuZuY2+bkyWXIHMfhNdJAdwW3FuWeCPYN5GVQ=
golang.org/x/oauth2 v0.35.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
Expand Down