diff --git a/api.go b/api.go index 86b6424..0dd2472 100644 --- a/api.go +++ b/api.go @@ -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) { @@ -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 @@ -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() @@ -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 +} diff --git a/client.go b/client.go index 8686429..99756cf 100644 --- a/client.go +++ b/client.go @@ -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"` @@ -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"` @@ -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"` +} diff --git a/client_update.go b/client_update.go index 245738e..5fe2c51 100644 --- a/client_update.go +++ b/client_update.go @@ -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"` @@ -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 @@ -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 } diff --git a/invoice.go b/invoice.go index f78062f..c884b9b 100644 --- a/invoice.go +++ b/invoice.go @@ -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 +} diff --git a/main.go b/main.go index 3daf292..028c63a 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "errors" "fmt" "io/ioutil" - "log" + //"log" "net/http" "net/url" "strings" @@ -154,7 +154,7 @@ func (a *API) Do(cmd string, data interface{}) ([]byte, error) { } // POST it. - log.Printf("Send: %+v", m) + //log.Printf("Send: %+v", m) url := fmt.Sprintf("%s/includes/api.php", a.Endpoint) r, err := http.PostForm(url, form) if err != nil { @@ -171,12 +171,12 @@ func (a *API) Do(cmd string, data interface{}) ([]byte, error) { // attempt to get the JSON and ignore the PHP error output. body = bytes.TrimSpace(body) if bytes.HasSuffix(body, []byte("}")) && !bytes.HasPrefix(body, []byte("{")) { - log.Printf("Body probably displaying errors") + //log.Printf("Body probably displaying errors") if idx := bytes.Index(body, []byte("{")); idx > -1 { body = body[idx:] } } - log.Printf("Body: %s", body) + //log.Printf("Body: %s", body) // The most basic responses have no message, so allow for that here. s := APIBasicResponse{}