Skip to content

Commit

Permalink
Support v8 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanhan101 authored Nov 2, 2022
1 parent 1146cff commit c5c885b
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_VERSION := v1.1.0
PKG_VERSION := v1.2.0
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null || true)
BUILD_DATE := $(shell date -u +%Y-%m-%dT%T 2> /dev/null)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func main() {
log.Fatal(err)
}

client, err := veryfi.NewClientV7(&veryfi.Options{
client, err := veryfi.NewClientV8(&veryfi.Options{
ClientID: "YOUR_CLIENT_ID",
Username: "YOUR_USERNAME",
APIKey: "YOUR_API_KEY",
Expand Down
8 changes: 4 additions & 4 deletions veryfi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Client struct {
pkgVersion string
}

// NewClientV7 returns a new instance of a client for v7 API.
func NewClientV7(opts *Options) (*Client, error) {
// NewClientV8 returns a new instance of a client for v8 API.
func NewClientV8(opts *Options) (*Client, error) {
c, err := createClient(opts)
if err != nil {
return nil, errors.Wrap(err, "fail to create a client")
Expand All @@ -42,8 +42,8 @@ func NewClientV7(opts *Options) (*Client, error) {
return &Client{
options: opts,
client: c,
apiVersion: "v7",
pkgVersion: "1.1.0",
apiVersion: "v8",
pkgVersion: "1.2.0",
}, nil
}

Expand Down
16 changes: 8 additions & 8 deletions veryfi/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func cleanUp(t *testing.T, documentID int) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: os.Getenv("USERNAME"),
Expand All @@ -25,7 +25,7 @@ func cleanUp(t *testing.T, documentID int) {
}

func TestIntegrationFailNoAuth(t *testing.T) {
client, err := NewClientV7(&Options{})
client, err := NewClientV8(&Options{})
assert.NotNil(t, client)
assert.NoError(t, err)

Expand All @@ -37,7 +37,7 @@ func TestIntegrationFailNoAuth(t *testing.T) {
}

func TestIntegrationFailInvalidClientID(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: "foo",
ClientSecret: "bar",
Username: os.Getenv("USERNAME"),
Expand All @@ -54,7 +54,7 @@ func TestIntegrationFailInvalidClientID(t *testing.T) {
}

func TestIntegrationFailInvalidUsername(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: "foo",
Expand All @@ -71,7 +71,7 @@ func TestIntegrationFailInvalidUsername(t *testing.T) {
}

func TestIntegrationFailInvalidAPIKey(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: os.Getenv("USERNAME"),
Expand All @@ -88,7 +88,7 @@ func TestIntegrationFailInvalidAPIKey(t *testing.T) {
}

func TestIntegrationFailInvalidDocument(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: os.Getenv("USERNAME"),
Expand All @@ -105,7 +105,7 @@ func TestIntegrationFailInvalidDocument(t *testing.T) {
}

func TestIntegrationSuccessProcessDocumentURL(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: os.Getenv("USERNAME"),
Expand All @@ -126,7 +126,7 @@ func TestIntegrationSuccessProcessDocumentURL(t *testing.T) {
}

func TestIntegrationSuccessProcessDocumentUpload(t *testing.T) {
client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
ClientID: os.Getenv("CLIENT_ID"),
ClientSecret: os.Getenv("CLIENT_SECRET"),
Username: os.Getenv("USERNAME"),
Expand Down
28 changes: 14 additions & 14 deletions veryfi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func setUp(t *testing.T) (test.HTTPServer, *Client, string, *scheme.Document) {
assert.NoError(t, err)

mockRespStr := string(mockResp)
server.Serve(t, "/api/v7/partner/documents/36966934/", 200, mockRespStr)
server.Serve(t, "/api/v7/partner/documents/", 200, mockRespStr)
server.Serve(t, "/api/v8/partner/documents/36966934/", 200, mockRespStr)
server.Serve(t, "/api/v8/partner/documents/", 200, mockRespStr)

expected := &scheme.Document{
Created: "2021-06-22 20:11:10",
Expand Down Expand Up @@ -60,14 +60,14 @@ func setUp(t *testing.T) (test.HTTPServer, *Client, string, *scheme.Document) {
Total: 97.66,
Updated: "2021-06-22 20:11:11",
Vendor: scheme.Vendor{
Name: "In-N-Out Burger",
RawName: "In-N-Out Burger",
VendorLogo: "https://cdn.veryfi.com/logos/us/949103001.png",
VendorType: "Restaurant",
Name: "In-N-Out Burger",
RawName: "In-N-Out Burger",
Logo: "",
Type: "",
},
}

client, err := NewClientV7(&Options{
client, err := NewClientV8(&Options{
EnvironmentURL: server.URL,
ClientID: "testClientID",
Username: "testUsername",
Expand All @@ -80,14 +80,14 @@ func setUp(t *testing.T) (test.HTTPServer, *Client, string, *scheme.Document) {
return server, client, mockReceiptPath, expected
}

func TestUnitNewClientV7_NilConfig(t *testing.T) {
client, err := NewClientV7(nil)
func TestUnitNewClientV8_NilConfig(t *testing.T) {
client, err := NewClientV8(nil)
assert.Nil(t, client)
assert.Error(t, err)
}

func TestUnitNewClientV7_Config(t *testing.T) {
client, err := NewClientV7(&Options{
func TestUnitNewClientV8_Config(t *testing.T) {
client, err := NewClientV8(&Options{
ClientID: "testClientID",
Username: "testUsername",
APIKey: "testAPIKey",
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestUnitNewClientV7_Config(t *testing.T) {
assert.Equal(t, expected, resp)
}

func TestUnitClientV7_GetDocument(t *testing.T) {
func TestUnitClientV8_GetDocument(t *testing.T) {
server, client, _, expected := setUp(t)
defer server.Close()

Expand All @@ -134,7 +134,7 @@ func TestUnitClientV7_GetDocument(t *testing.T) {
assert.Equal(t, expected, resp)
}

func TestUnitClientV7_ProcessDocumentUpload(t *testing.T) {
func TestUnitClientV8_ProcessDocumentUpload(t *testing.T) {
server, client, mockReceiptPath, expected := setUp(t)
defer server.Close()

Expand All @@ -146,7 +146,7 @@ func TestUnitClientV7_ProcessDocumentUpload(t *testing.T) {
assert.Equal(t, expected, resp)
}

func TestUnitClientV7_ProcessDocumentURL(t *testing.T) {
func TestUnitClientV8_ProcessDocumentURL(t *testing.T) {
server, client, _, expected := setUp(t)
defer server.Close()

Expand Down
26 changes: 11 additions & 15 deletions veryfi/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func ExampleClient_processDocument() {
log.Fatal(err)
}

// Initialize a Veryfi Client for v7 API.
client, err := veryfi.NewClientV7(&veryfi.Options{
// Initialize a Veryfi Client for v8 API.
client, err := veryfi.NewClientV8(&veryfi.Options{
ClientID: "YOUR_CLIENT_ID",
Username: "YOUR_USERNAME",
APIKey: "YOUR_API_KEY",
Expand Down Expand Up @@ -66,8 +66,8 @@ func ExampleClient_manageDocument() {
log.Fatal(err)
}

// Initialize a Veryfi Client for v7 API.
client, err := veryfi.NewClientV7(&veryfi.Options{
// Initialize a Veryfi Client for v8 API.
client, err := veryfi.NewClientV8(&veryfi.Options{
ClientID: "YOUR_CLIENT_ID",
Username: "YOUR_USERNAME",
APIKey: "YOUR_API_KEY",
Expand All @@ -87,9 +87,7 @@ func ExampleClient_manageDocument() {
deleteDocumentID := "YOUR_DOCUMENT_ID"

// Update a document.
resp, err := client.UpdateDocument(documentID, scheme.DocumentUpdateOptions{
BillToName: "Hoanh An",
BillToAddress: "NY",
_, err = client.UpdateDocument(documentID, scheme.DocumentUpdateOptions{
Vendor: scheme.VendorUpdateOptions{
Name: "Hoanh An",
Address: "NY",
Expand All @@ -98,7 +96,6 @@ func ExampleClient_manageDocument() {
if err != nil {
log.Fatal(err)
}
fmt.Printf("ID: %v\tBill To Name: %v\n", resp.ID, resp.BillToName)

// Search documents.
docs, err := client.SearchDocuments(scheme.DocumentSearchOptions{
Expand All @@ -108,17 +105,16 @@ func ExampleClient_manageDocument() {
log.Fatal(err)
}
for _, doc := range *docs {
fmt.Printf("ID: %v\tBill To Name: %v\n", doc.ID, doc.BillToName)
fmt.Println(doc)
}

// Get a document.
resp, err = client.GetDocument(documentID, scheme.DocumentGetOptions{
_, err = client.GetDocument(documentID, scheme.DocumentGetOptions{
ReturnAuditTrail: "1",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("ID: %v\tBill To Name: %v\n", resp.ID, resp.BillToName)

// Delete a document.
err = client.DeleteDocument(deleteDocumentID)
Expand All @@ -133,8 +129,8 @@ func ExampleClient_manageLineItem() {
log.Fatal(err)
}

// Initialize a Veryfi Client for v7 API.
client, err := veryfi.NewClientV7(&veryfi.Options{
// Initialize a Veryfi Client for v8 API.
client, err := veryfi.NewClientV8(&veryfi.Options{
ClientID: "YOUR_CLIENT_ID",
Username: "YOUR_USERNAME",
APIKey: "YOUR_API_KEY",
Expand Down Expand Up @@ -206,8 +202,8 @@ func ExampleClient_manageTag() {
log.Fatal(err)
}

// Initialize a Veryfi Client for v7 API.
client, err := veryfi.NewClientV7(&veryfi.Options{
// Initialize a Veryfi Client for v8 API.
client, err := veryfi.NewClientV8(&veryfi.Options{
ClientID: "YOUR_CLIENT_ID",
Username: "YOUR_USERNAME",
APIKey: "YOUR_API_KEY",
Expand Down
Loading

0 comments on commit c5c885b

Please sign in to comment.