Skip to content

Commit

Permalink
Add QueryCustomerByName method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Westlund committed Feb 10, 2022
1 parent a669272 commit 0c49d03
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"

null "gopkg.in/guregu/null.v4"
)
Expand Down Expand Up @@ -80,6 +81,32 @@ func (c Customer) GetPrimaryEmail() string {
return ""
}

// QueryCustomerByName gets a customer with a given name.
func (c *Client) QueryCustomerByName(name string) (*Customer, error) {

var r struct {
QueryResponse struct {
Customer []Customer
TotalCount int
}
}
err := c.query("SELECT * FROM Customer WHERE DisplayName = '"+
strings.Replace(name, "'", "''", -1)+"'", &r)
if err != nil {
return nil, err
}

// var customers = make([]Customer, 0, r.QueryResponse.TotalCount)
// for i := 0; i < r.QueryResponse.TotalCount; i += queryPageSize {
// var page, err = c.fetchCustomerPage(i + 1)
// if err != nil {
// return nil, err
// }
// customers = append(customers, page...)
// }
return &r.QueryResponse.Customer[0], nil
}

// FetchCustomers gets the full list of Customers in the QuickBooks account.
func (c *Client) FetchCustomers() ([]Customer, error) {

Expand Down

0 comments on commit 0c49d03

Please sign in to comment.