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
162 changes: 157 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ func (a *API) AddTransaction(t *Transaction) error {
return nil
}

// AddInvoicePayment
func (a *API) AddInvoicePayment(i *AddInvoicePaymentRequest) (r *AddInvoicePaymentResponse, err error) {

err = i.Error()
if err != nil {
return
}

body, err := a.Do("addinvoicepayment", i)
if err != nil {
err = fmt.Errorf("gowhmcs addinvoicepayment error: %v", err)
return
}

r = &AddInvoicePaymentResponse{}
if err = json.Unmarshal(body, r); err != nil {
err = fmt.Errorf("gowhmcs addinvoicepayment error: %v", err)
}

return

}

// UpdateInvoice updates the invoice with the given parameters of `r`.
func (a *API) UpdateInvoice(i *UpdateInvoiceRequest) (r *UpdateInvoiceResponse, err error) {

Expand Down Expand Up @@ -66,24 +89,43 @@ func (a *API) CreateInvoice(i *CreateInvoiceRequest) (r *CreateInvoiceResponse,

}

// Open ticket
func (a *API) OpenTicket(t *OpenTicketRequest) (r *OpenTicketResponse, err error) {

err = t.Error()
if err != nil {
return
}

body, err := a.Do("openticket", t)
if err != nil {
return
}

r = &OpenTicketResponse{}
err = json.Unmarshal(body, r)
return

}

// UpdateExistingClient updates an existing client.
func (a *API) UpdateExistingClient(c *ExistingClient) (r *UpdateClientResult, err error) {

err = c.Error()
if err != nil {
err = fmt.Errorf("gowhmcs updateexistingclient error: %v", err)
err = fmt.Errorf("Error: %v", err)
return
}

body, err := a.Do("updateclient", &c)
if err != nil {
err = fmt.Errorf("gowhmcs updateexistingclient error: %v", err)
err = fmt.Errorf("Error: %v", err)
return
}

r = &UpdateClientResult{}
if err = json.Unmarshal(body, r); err != nil {
err = fmt.Errorf("gowhmcs updateexistingclient error: %v", err)
err = fmt.Errorf("Error: %v", err)
}
return

Expand Down Expand Up @@ -187,18 +229,52 @@ func (a *API) ValidateLogin(v *ValidateLogin) (r *ValidateLoginResult, err error

body, err := a.Do("validatelogin", &v)
if err != nil {
err = fmt.Errorf("gowhmcs validatelogin error: %v", err)
err = fmt.Errorf("%v", err)
return
}

r = &ValidateLoginResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("gowhmcs validatelogin error: %v", err)
err = fmt.Errorf("%v", err)
}

return
}

func (a *API) GetClientsProducts(v *GetClientsProducts) (r *GetClientsProductsResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("GetClientsProducts", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &GetClientsProductsResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}
return
}

func (a *API) DecryptPassword(v *DecryptPassword) (r *DecryptPasswordResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("DecryptPassword", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &DecryptPasswordResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}
return
}

func (a *API) UpdateClientProduct(p *ClientProduct) (r *UpdateClientProductResult, err error) {

err = p.Error()
Expand All @@ -220,3 +296,79 @@ func (a *API) UpdateClientProduct(p *ClientProduct) (r *UpdateClientProductResul

return
}

// Reset account password
func (a *API) ResetPassword(v *ResetPassword) (r *ResetPasswordResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("ResetPassword", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &ResetPasswordResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}

return
}

//Terminate a service
func (a *API) TerminateService(v *TerminateService) (r *TerminateServiceResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("ModuleTerminate", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &TerminateServiceResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}

return
}

//Terminate a service
func (a *API) CreateService(v *CreateService) (r *CreateServiceResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("ModuleCreate", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &CreateServiceResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}

return
}

//Send email
func (a *API) SendEmail(v *SendEmail) (r *SendEmailResult, err error) {
err = v.Error()
if err != nil {
return
}
body, err := a.Do("SendEmail", &v)
if err != nil {
err = fmt.Errorf("%v", err)
return
}
r = &SendEmailResult{}
if err = json.Unmarshal(body, &r); err != nil {
err = fmt.Errorf("%v", err)
}

return
}
96 changes: 96 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ type ValidateLogin struct {
Password2 string `json:"password2"`
}

type DecryptPassword struct {
Password2 string `json:"password2"`
}

type ResetPassword struct {
Email string `json:"email"`
}

type TerminateService struct {
Id int64 `json:"serviceid"`
}

type CreateService struct {
Id int64 `json:"serviceid"`
}

type SendEmail struct {
MessageName string `json:"messagename"`
Id int64 `json:"id"`
}

type OpenTicketRequest struct {
DeptId int64 `json:"deptid"`
Subject string `json:"subject"`
Message string `json:"message"`
ClientId int64 `json:"clientid"`
}

type GetClientsProducts struct {
ServiceId int `json:"serviceid"`
}

type GetClientsProductsResult struct {
Result string `json:"result"`
ClientID int64 `json:"clientid"`
ServiceID string `json:"serviceid"`
Pid int64 `json:"pid"`
Domain string `json:"domain"`
TotalResults int64 `json:"totalresults"`
StartNumber int64 `json:"startnumber"`
NumReturned int64 `json:"numreturned"`
}

// AddClientResult is the WHMCS response when adding a client.
type AddClientResult struct {
ClientID int64 `json:"clientid"`
Expand All @@ -60,6 +103,27 @@ type ValidateLoginResult struct {
Message string `json:"message"`
}

type DecryptPasswordResult struct {
Result string `json:"result"`
Password string `json:"password"`
}

type ResetPasswordResult struct {
Result string `json:"result"`
}

type TerminateServiceResult struct {
Result string `json:"result"`
}

type CreateServiceResult struct {
Result string `json:"result"`
}

type SendEmailResult struct {
Result string `json:"result"`
}

// ClientDetailsReq is the struct of parameters available to retrieve client details.
type ClientDetailsReq struct {
ClientID string `json:"clientid,omitempty"`
Expand All @@ -74,3 +138,35 @@ func (c *NewClient) Error() error {
func (v *ValidateLogin) Error() error {
return nil
}

func (v *ResetPassword) Error() error {
return nil
}

func (v *GetClientsProducts) Error() error {
return nil
}

func (v *DecryptPassword) Error() error {
return nil
}

func (v *TerminateService) Error() error {
return nil
}
func (v *CreateService) Error() error {
return nil
}

func (v *SendEmail) Error() error {
return nil
}

func (v *OpenTicketRequest) Error() error {
return nil
}

type OpenTicketResponse struct {
Result string `json:"result"`
TicketId string `json:"tid"`
}
8 changes: 4 additions & 4 deletions client_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
)

type ExistingClient struct {
ClientID string `"json:clientid,omitempty"`
ClientID int64 `"json:clientid,omitempty"`
ClientEmail string `json:"clientemail,omitempty"`

Firstname string `json:"firstname,omitempty"`
Expand Down Expand Up @@ -52,11 +52,11 @@ type ExistingClient struct {
// UpdateClientResult is the WHMCS response when updating a client.
type UpdateClientResult struct {
Result string `json:"result"`
ClientID int64 `json:"clientid,string"`
ClientID int64 `json:"clientid"`
}

func (c *ExistingClient) Error() error {
if c.ClientID == "" && c.ClientEmail == "" {
if c.ClientID == 0 && c.ClientEmail == "" {
return ErrNoClientDetails
}
return nil
Expand All @@ -68,6 +68,6 @@ func (c *ExistingClient) ByEmail(email string) {
}

// ByID sets the client's ID with the given id string
func (c *ExistingClient) ByID(id string) {
func (c *ExistingClient) ByID(id int64) {
c.ClientID = id
}
16 changes: 16 additions & 0 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,19 @@ type UpdateInvoiceRequest struct {
func (r *UpdateInvoiceRequest) Error() error {
return nil
}

// AddInvoicePaymentRequest
type AddInvoicePaymentRequest struct {
InvoiceID int64 `json:"invoiceid,string"`
TransID string `json:"transid"`
Gateway string `json:"gateway"`
Fees float64 `json:"fees"`
}

type AddInvoicePaymentResponse struct {
Result string `json:"result"`
}

func (r *AddInvoicePaymentRequest) Error() error {
return nil
}
Loading