Skip to content

Commit

Permalink
Merge pull request #1 from sendlovebox/bills
Browse files Browse the repository at this point in the history
Bills
  • Loading branch information
odetolataiwo authored Jul 24, 2023
2 parents 26e46ce + 299654f commit 21fa89f
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 25 deletions.
12 changes: 12 additions & 0 deletions api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ func (c *Call) GetVirtualAccountTransaction(ctx context.Context, txID string) (*
}
return response, err
}

// GetAccunts makes the request to get a virtual account transaction on by its ID
func (c *Call) GetAccounts(ctx context.Context, txID string) (*model.Transaction, error) {
response := &model.Transaction{}

//path := fmt.Sprintf("/virtual-accounts/transactions/%s", txID)
err := c.makeRequest(ctx, http.MethodGet, "/accounts\n", nil, response)
if err != nil {
return nil, err
}
return response, err
}
10 changes: 10 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ type RemoteCalls interface {
GetVirtualAccountByRef(ctx context.Context, reference string) (*model.VirtualAccount, error)
GetVirtualAccountByBVN(ctx context.Context, bvn string) (*model.VirtualAccount, error)
GetVirtualAccountTransaction(ctx context.Context, txID string) (*model.Transaction, error)

GetBillVendors(ctx context.Context, category string) (*[]model.Vendor, error)
GetBillVendorByID(ctx context.Context, vendorID string) (*model.Vendor, error)
GetBillProducts(ctx context.Context, vendorID, category *string) (*[]model.Product, error)
GetBillProductByID(ctx context.Context, productID string) (*model.Product, error)
RunCustomerLookup(ctx context.Context, customerID string, productID string) (*model.Product, error)
CreateBill(ctx context.Context, request model.CreateBillRequest) (*model.CreateBillResponse, error)
GetBillByID(ctx context.Context, id string) (*model.BillData, error)
GetBillByReference(ctx context.Context, reference string) (*model.BillData, error)
GetAllBills(ctx context.Context, request model.GetAllBillsRequest) (*[]model.BillData, error)
}

// Call object
Expand Down
188 changes: 188 additions & 0 deletions api/bill.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package api

import (
"context"
"fmt"
"net/http"
"net/url"

"github.com/sendlovebox/go-lenco/model"
)

// GetBillVendors makes the request to get bill vendors
func (c *Call) GetBillVendors(ctx context.Context, category string) (*[]model.Vendor, error) {
response := &[]model.Vendor{}

path := "/bills/vendors"

params := url.Values{}
params.Set("categories[]", category)

requestPath := fmt.Sprintf("%s?%s", path, params.Encode())

err := c.makeRequest(ctx, http.MethodGet, requestPath, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// GetBillVendorByID makes the request to get a bill vendor by its ID
func (c *Call) GetBillVendorByID(ctx context.Context, vendorID string) (*model.Vendor, error) {
response := &model.Vendor{}
path := fmt.Sprintf("/bills/vendors/%s", vendorID)

err := c.makeRequest(ctx, http.MethodGet, path, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// GetBillProducts makes the request to get products
func (c *Call) GetBillProducts(ctx context.Context, vendorID, category *string) (*[]model.Product, error) {
response := &[]model.Product{}

path := "/bills/products"
params := url.Values{}

if vendorID != nil {
params.Set("vendorIds[]", *vendorID)
}

if category != nil {
params.Set("categories[]", *category)
}

requestPath := fmt.Sprintf("%s?%s", path, params.Encode())

err := c.makeRequest(ctx, http.MethodGet, requestPath, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// GetBillProductByID makes the request to get a product by its ID
func (c *Call) GetBillProductByID(ctx context.Context, productID string) (*model.Product, error) {
response := &model.Product{}
path := fmt.Sprintf("/bills/products/%s", productID)

err := c.makeRequest(ctx, http.MethodGet, path, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// RunCustomerLookup makes the request to run customer look up for a bill
func (c *Call) RunCustomerLookup(ctx context.Context, customerID string, productID string) (*model.Product, error) {
response := &model.Product{}

path := fmt.Sprintf("/bills/lookup-account?customerId=%s&productId=%s", customerID, productID)

err := c.makeRequest(ctx, http.MethodGet, path, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// CreateBill makes the request to create a bill
func (c *Call) CreateBill(ctx context.Context, request model.CreateBillRequest) (*model.CreateBillResponse, error) {

response := &model.CreateBillResponse{}

err := c.makeRequest(ctx, http.MethodPost, "/bills", request, response)
if err != nil {
return nil, err
}

return response, err
}

// GetBillByID makes the request to get a specific bill
func (c *Call) GetBillByID(ctx context.Context, id string) (*model.BillData, error) {

response := &model.BillData{}

path := fmt.Sprintf("/bills/%s", id)

err := c.makeRequest(ctx, http.MethodGet, path, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// GetBillByReference makes the request to get a specific bill
func (c *Call) GetBillByReference(ctx context.Context, reference string) (*model.BillData, error) {

response := &model.BillData{}

path := fmt.Sprintf("/bills/by-reference/%s", reference)

err := c.makeRequest(ctx, http.MethodGet, path, nil, response)
if err != nil {
return nil, err
}

return response, err
}

// GetAllBills makes the request to get all bills
func (c *Call) GetAllBills(ctx context.Context, request model.GetAllBillsRequest) (*[]model.BillData, error) {

response := &[]model.BillData{}

path := "/bills"

params := url.Values{}

if request.VendorID != nil {
params.Set("vendorIds[]", *request.VendorID)
}

if request.ProductID != nil {
params.Set("vendorIds[]", *request.VendorID)
}

if request.CustomerID != nil {
params.Set("customerId", *request.CustomerID)
}

if request.Status != nil {
params.Set("status", *request.Status)
}

if request.Category != nil {
params.Set("categories[]", string(*request.Category))
}

if request.Page != nil {
params.Set("page", *request.Page)
}

if request.Start != nil {
params.Set("start", *request.Start)
}

if request.End != nil {
params.Set("end", *request.End)
}

requestPath := fmt.Sprintf("%s?%s", path, params.Encode())

err := c.makeRequest(ctx, http.MethodGet, requestPath, nil, response)
if err != nil {
return nil, err
}

return response, err
}
2 changes: 1 addition & 1 deletion api/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"

"github.com/go-resty/resty/v2"

"github.com/mitchellh/mapstructure"

"github.com/sendlovebox/go-lenco/model"
)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
)

require (
github.com/google/uuid v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
Expand Down
Loading

0 comments on commit 21fa89f

Please sign in to comment.