Exemplo n.º 1
0
func (c *Customer) ListCustomersByName(customerName string) (Customers, error) {

	filter := invdendpoint.NewFilter()
	filter.Set("name", customerName)

	customers, apiError := c.ListAll(filter, nil)

	if apiError != nil {
		return nil, apiError
	}

	return customers, nil

}
Exemplo n.º 2
0
func TestAddFilterSortToEndPointWithOnlyFilter(t *testing.T) {
	f := invdendpoint.NewFilter()
	f.Set("id", 121123)
	f.Set("address", 121123)

	endPoint := "https://www.do.com"

	value := addFilterSortToEndPoint(endPoint, f, nil)

	correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123"

	if value != correctValue {
		t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
	}

}
Exemplo n.º 3
0
func (c *Customer) ListCustomerByNumber(customerNumber string) (*Customer, error) {

	filter := invdendpoint.NewFilter()
	filter.Set("number", customerNumber)

	customers, apiError := c.ListAll(filter, nil)

	if apiError != nil {
		return nil, apiError
	}

	if len(customers) == 0 {
		return nil, nil
	}

	return customers[0], nil

}
Exemplo n.º 4
0
func (c *Invoice) ListInvoiceByNumber(invoiceNumber string) (*Invoice, error) {

	filter := invdendpoint.NewFilter()
	filter.Set("number", invoiceNumber)

	invoices, apiError := c.ListAll(filter, nil)

	if apiError != nil {
		return nil, apiError
	}

	if len(invoices) == 0 {
		return nil, nil
	}

	return invoices[0], nil

}
Exemplo n.º 5
0
func (c *Transaction) ListSuccessfulByInvoiceID(invoiceID int64) (Transactions, error) {

	invoiceIDString := strconv.FormatInt(invoiceID, 10)

	filter := invdendpoint.NewFilter()
	filter.Set("invoice", invoiceIDString)
	filter.Set("status", "succeeded")

	transactions, apiError := c.ListAll(filter, nil)

	if apiError != nil {
		return nil, apiError
	}

	if len(transactions) == 0 {
		return nil, nil
	}

	return transactions, nil

}
Exemplo n.º 6
0
func TestAddFilterSortToEndPointWithBothValues(t *testing.T) {
	f := invdendpoint.NewFilter()
	f.Set("id", 121123)
	f.Set("address", 121123)

	s := invdendpoint.NewSort()
	s.Set("name", invdendpoint.ASC)
	s.Set("age", invdendpoint.DESC)

	endPoint := "https://www.do.com"

	value := addFilterSortToEndPoint(endPoint, f, s)

	correctValue := "https://www.do.com?filter%5Baddress%5D=121123&filter%5Bid%5D=121123&sort=age+DESC%2Cname+ASC"

	if value != correctValue {
		t.Fatal("Error: resulting URL is incorrect it should be ", correctValue, " but instead got ", value)
	}

	// endpoint2 := "https://www.do.com?"

}