From 8fcde8980bd2fba81bf72ec81a5faad47a577e85 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Tue, 27 Feb 2018 11:37:15 +0300 Subject: [PATCH] Initial set of methods & tests (#1) --- .gitignore | 9 + README.md | 85 ++ retailcrm.go | 12 + v5/client.go | 1694 ++++++++++++++++++++++++++++++++++++ v5/client_test.go | 2078 +++++++++++++++++++++++++++++++++++++++++++++ v5/filters.go | 298 +++++++ v5/request.go | 144 ++++ v5/response.go | 346 ++++++++ v5/types.go | 866 +++++++++++++++++++ 9 files changed, 5532 insertions(+) create mode 100644 .gitignore create mode 100644 retailcrm.go create mode 100644 v5/client.go create mode 100644 v5/client_test.go create mode 100644 v5/filters.go create mode 100644 v5/request.go create mode 100644 v5/response.go create mode 100644 v5/types.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f6e21e --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# IDE's files +.idea + +# Project ignores diff --git a/README.md b/README.md index a9a5b8b..edd96f6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,88 @@ # retailCRM API Go client Go client for [retailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion5). + +## Installation + +```bash +go get -x github.com/retailcrm/api-client-go +``` + +## Usage + +```golang +package main + +import ( + "fmt" + "net/http" + + "github.com/retailcrm/api-client-go/v5" +) + +func main() { + var client = v5.New("https://demo.retailcrm.pro", "09jIJ09j0JKhgyfvyuUIKhiugF") + + data, status, err := client.Orders(v5.OrdersRequest{ + Filter: v5.OrdersFilter{}, + Limit: 20, + Page: 1, + }) + if err.ErrorMsg != "" { + fmt.Printf("%v", err.ErrorMsg) + } + + if status >= http.StatusBadRequest { + fmt.Printf("%v", err.ErrorMsg) + } + + for _, value := range data.Orders { + fmt.Printf("%v\n", value.Email) + } + + fmt.Println(data.Orders[1].FirstName) + + idata, status, err := c.InventoriesUpload( + []InventoryUpload{ + { + XmlId: "pTKIKAeghYzX21HTdzFCe1", + Stores: []InventoryUploadStore{ + {Code: "test-store-v5", Available: 10, PurchasePrice: 1500}, + {Code: "test-store-v4", Available: 20, PurchasePrice: 1530}, + {Code: "test-store", Available: 30, PurchasePrice: 1510}, + }, + }, + { + XmlId: "JQIvcrCtiSpOV3AAfMiQB3", + Stores: []InventoryUploadStore{ + {Code: "test-store-v5", Available: 45, PurchasePrice: 1500}, + {Code: "test-store-v4", Available: 32, PurchasePrice: 1530}, + {Code: "test-store", Available: 46, PurchasePrice: 1510}, + }, + }, + }, + ) + if err.ErrorMsg != "" { + fmt.Printf("%v", err.ErrorMsg) + } + + if status >= http.StatusBadRequest { + fmt.Printf("%v", err.ErrorMsg) + } + + fmt.Println(idata.processedOffersCount) +} +``` + +## Testing + +```bash +export RETAILCRM_URL="https://demo.retailcrm.pro" +export RETAILCRM_KEY="09jIJ09j0JKhgyfvyuUIKhiugF" +export RETAILCRM_USER="1" + +cd $GOPATH/src/github.com/retailcrm/api-client-go + +go test -v ./... + +``` diff --git a/retailcrm.go b/retailcrm.go new file mode 100644 index 0000000..d913ad7 --- /dev/null +++ b/retailcrm.go @@ -0,0 +1,12 @@ +package retailcrm + +import ( + "github.com/retailcrm/api-client-go/v5" +) + +// Version5 API client for v5 +func Version5(url string, key string) *v5.Client { + var client = v5.New(url, key) + + return client +} diff --git a/v5/client.go b/v5/client.go new file mode 100644 index 0000000..5b2f922 --- /dev/null +++ b/v5/client.go @@ -0,0 +1,1694 @@ +package v5 + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "strconv" + "strings" + "time" + + "github.com/google/go-querystring/query" +) + +const ( + versionedPrefix = "/api/v5" + unversionedPrefix = "/api" +) + +// New initalize client +func New(url string, key string) *Client { + return &Client{ + url, + key, + &http.Client{Timeout: 20 * time.Second}, + } +} + +// GetRequest implements GET Request +func (c *Client) GetRequest(urlWithParameters string) ([]byte, int, ErrorResponse) { + var res []byte + var bug ErrorResponse + + req, err := http.NewRequest("GET", fmt.Sprintf("%s%s", c.Url, urlWithParameters), nil) + if err != nil { + bug.ErrorMsg = err.Error() + return res, 0, bug + } + + req.Header.Set("X-API-KEY", c.Key) + + resp, err := c.httpClient.Do(req) + if err != nil { + bug.ErrorMsg = err.Error() + return res, 0, bug + } + + if resp.StatusCode >= http.StatusInternalServerError { + bug.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, bug + } + + res, err = buildRawResponse(resp) + if err != nil { + bug.ErrorMsg = err.Error() + } + + eresp, _ := c.ErrorResponse(res) + if eresp.ErrorMsg != "" { + return res, resp.StatusCode, eresp + } + + return res, resp.StatusCode, bug +} + +// PostRequest implements POST Request +func (c *Client) PostRequest(url string, postParams url.Values) ([]byte, int, ErrorResponse) { + var res []byte + var bug ErrorResponse + + req, err := http.NewRequest( + "POST", + fmt.Sprintf("%s%s", c.Url, url), + strings.NewReader(postParams.Encode()), + ) + if err != nil { + bug.ErrorMsg = err.Error() + return res, 0, bug + } + + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("X-API-KEY", c.Key) + + resp, err := c.httpClient.Do(req) + if err != nil { + bug.ErrorMsg = err.Error() + return res, 0, bug + } + + if resp.StatusCode >= http.StatusInternalServerError { + bug.ErrorMsg = fmt.Sprintf("HTTP request error. Status code: %d.\n", resp.StatusCode) + return res, resp.StatusCode, bug + } + + res, err = buildRawResponse(resp) + if err != nil { + bug.ErrorMsg = err.Error() + return res, 0, bug + } + + eresp, _ := c.ErrorResponse(res) + if eresp.ErrorMsg != "" { + return res, resp.StatusCode, eresp + } + + return res, resp.StatusCode, bug +} + +func buildRawResponse(resp *http.Response) ([]byte, error) { + defer resp.Body.Close() + + res, err := ioutil.ReadAll(resp.Body) + if err != nil { + return res, err + } + + return res, nil +} + +// checkBy select identifier type +func checkBy(by string) string { + var context = "id" + + if by != "id" { + context = "externalId" + } + + return context +} + +// fillSite add site code to parameters if present +func fillSite(p *url.Values, site []string) { + if len(site) > 0 { + s := site[0] + + if s != "" { + p.Add("site", s) + } + } +} + +// ApiVersions get all available API versions for exact account +// +// Example: +// +// var client = v5.New("https://demo.url", "09jIJ") +// +// data, status, err := client.ApiVersions() +// +// if err.ErrorMsg != "" { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// if status >= http.StatusBadRequest { +// fmt.Printf("%v", err.ErrorMsg) +// } +// +// for _, value := range data.versions { +// fmt.Printf("%v\n", value) +// } +func (c *Client) ApiVersions() (*VersionResponse, int, ErrorResponse) { + var resp VersionResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/api-versions", unversionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ApiCredentials get available API methods +func (c *Client) ApiCredentials() (*CredentialResponse, int, ErrorResponse) { + var resp CredentialResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/credentials", unversionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// StaticticUpdate update statistic +func (c *Client) StaticticUpdate() (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/statistic/update", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Segments get segments +func (c *Client) Segments(parameters SegmentsRequest) (*SegmentsResponse, int, ErrorResponse) { + var resp SegmentsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/segments?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Customer get method +func (c *Client) Customer(id, by, site string) (*CustomerResponse, int, ErrorResponse) { + var resp CustomerResponse + var context = checkBy(by) + + fw := CustomerRequest{context, site} + params, _ := query.Values(fw) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/%s?%s", versionedPrefix, id, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Customers list method +func (c *Client) Customers(parameters CustomersRequest) (*CustomersResponse, int, ErrorResponse) { + var resp CustomersResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomerCreate method +func (c *Client) CustomerCreate(customer Customer, site ...string) (*CustomerChangeResponse, int, ErrorResponse) { + var resp CustomerChangeResponse + + customerJson, _ := json.Marshal(&customer) + + p := url.Values{ + "customer": {string(customerJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomerEdit method +func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (*CustomerChangeResponse, int, ErrorResponse) { + var resp CustomerChangeResponse + var uid = strconv.Itoa(customer.Id) + var context = checkBy(by) + + if context == "externalId" { + uid = customer.ExternalId + } + + customerJson, _ := json.Marshal(&customer) + + p := url.Values{ + "by": {string(context)}, + "customer": {string(customerJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/%s/edit", versionedPrefix, uid), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersUpload method +func (c *Client) CustomersUpload(customers []Customer, site ...string) (*CustomersUploadResponse, int, ErrorResponse) { + var resp CustomersUploadResponse + + uploadJson, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(uploadJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/upload", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersCombine method +func (c *Client) CustomersCombine(customers []Customer, resultCustomer Customer) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + combineJsonIn, _ := json.Marshal(&customers) + combineJsonOut, _ := json.Marshal(&resultCustomer) + + p := url.Values{ + "customers": {string(combineJsonIn[:])}, + "resultCustomer": {string(combineJsonOut[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/combine", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersFixExternalIds method +func (c *Client) CustomersFixExternalIds(customers []IdentifiersPair) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + customersJson, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(customersJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/fix-external-ids", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersHistory method +func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (*CustomersHistoryResponse, int, ErrorResponse) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/history?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Order get method +func (c *Client) Order(id, by, site string) (*OrderResponse, int, ErrorResponse) { + var resp OrderResponse + var context = checkBy(by) + + fw := OrderRequest{context, site} + params, _ := query.Values(fw) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/%s?%s", versionedPrefix, id, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Orders list method +func (c *Client) Orders(parameters OrdersRequest) (*OrdersResponse, int, ErrorResponse) { + var resp OrdersResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderCreate method +func (c *Client) OrderCreate(order Order, site ...string) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + orderJson, _ := json.Marshal(&order) + + p := url.Values{ + "order": {string(orderJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderEdit method +func (c *Client) OrderEdit(order Order, by string, site ...string) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + var uid = strconv.Itoa(order.Id) + var context = checkBy(by) + + if context == "externalId" { + uid = order.ExternalId + } + + orderJson, _ := json.Marshal(&order) + + p := url.Values{ + "by": {string(context)}, + "order": {string(orderJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/%s/edit", versionedPrefix, uid), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrdersUpload method +func (c *Client) OrdersUpload(orders []Order, site ...string) (*OrdersUploadResponse, int, ErrorResponse) { + var resp OrdersUploadResponse + + uploadJson, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(uploadJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/upload", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrdersCombine method +func (c *Client) OrdersCombine(technique string, order, resultOrder Order) (*OperationResponse, int, ErrorResponse) { + var resp OperationResponse + + combineJsonIn, _ := json.Marshal(&order) + combineJsonOut, _ := json.Marshal(&resultOrder) + + p := url.Values{ + "technique": {technique}, + "order": {string(combineJsonIn[:])}, + "resultOrder": {string(combineJsonOut[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/combine", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrdersFixExternalIds method +func (c *Client) OrdersFixExternalIds(orders []IdentifiersPair) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + ordersJson, _ := json.Marshal(&orders) + + p := url.Values{ + "orders": {string(ordersJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/fix-external-ids", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrdersHistory method +func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (*CustomersHistoryResponse, int, ErrorResponse) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/history?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Pack get method +func (c *Client) Pack(id int) (*PackResponse, int, ErrorResponse) { + var resp PackResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs/%d", versionedPrefix, id)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Packs list method +func (c *Client) Packs(parameters PacksRequest) (*PacksResponse, int, ErrorResponse) { + var resp PacksResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PackCreate method +func (c *Client) PackCreate(pack Pack) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + packJson, _ := json.Marshal(&pack) + + p := url.Values{ + "pack": {string(packJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PackEdit method +func (c *Client) PackEdit(pack Pack) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + packJson, _ := json.Marshal(&pack) + + p := url.Values{ + "pack": {string(packJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/%d/edit", versionedPrefix, pack.Id), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PackDelete method +func (c *Client) PackDelete(id int) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/packs/%d/delete", versionedPrefix, id), url.Values{}) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PacksHistory method +func (c *Client) PacksHistory(parameters PacksHistoryRequest) (*PacksHistoryResponse, int, ErrorResponse) { + var resp PacksHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders/packs/history?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// User get method +func (c *Client) User(id int) (*UserResponse, int, ErrorResponse) { + var resp UserResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/users/%d", versionedPrefix, id)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Users list method +func (c *Client) Users(parameters UsersRequest) (*UsersResponse, int, ErrorResponse) { + var resp UsersResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/users?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// UserGroups list method +func (c *Client) UserGroups(parameters UserGroupsRequest) (*UserGroupsResponse, int, ErrorResponse) { + var resp UserGroupsResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/user-groups", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// UserStatus update method +func (c *Client) UserStatus(id int, status string) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + p := url.Values{ + "status": {string(status)}, + } + + data, st, err := c.PostRequest(fmt.Sprintf("%s/users/%d/status", versionedPrefix, id), p) + if err.ErrorMsg != "" { + return &resp, st, err + } + + json.Unmarshal(data, &resp) + + return &resp, st, err +} + +// Task get method +func (c *Client) Task(id int) (*TaskResponse, int, ErrorResponse) { + var resp TaskResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/tasks/%d", versionedPrefix, id)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Tasks list method +func (c *Client) Tasks(parameters TasksRequest) (*TasksResponse, int, ErrorResponse) { + var resp TasksResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/tasks?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// TaskCreate method +func (c *Client) TaskCreate(task Task, site ...string) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + taskJson, _ := json.Marshal(&task) + + p := url.Values{ + "task": {string(taskJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/tasks/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// TaskEdit method +func (c *Client) TaskEdit(task Task, site ...string) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + var uid = strconv.Itoa(task.Id) + + taskJson, _ := json.Marshal(&task) + + p := url.Values{ + "task": {string(taskJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/tasks/%s/edit", versionedPrefix, uid), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Notes list method +func (c *Client) Notes(parameters NotesRequest) (*NotesResponse, int, ErrorResponse) { + var resp NotesResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/notes?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// NoteCreate method +func (c *Client) NoteCreate(note Note, site ...string) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + noteJson, _ := json.Marshal(¬e) + + p := url.Values{ + "note": {string(noteJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/notes/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// NoteDelete method +func (c *Client) NoteDelete(id int) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + p := url.Values{ + "id": {string(id)}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/notes/%d/delete", versionedPrefix, id), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentCreate method +func (c *Client) PaymentCreate(payment Payment, site ...string) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + paymentJson, _ := json.Marshal(&payment) + + p := url.Values{ + "payment": {string(paymentJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentDelete method +func (c *Client) PaymentDelete(id int) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + p := url.Values{ + "id": {string(id)}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/%d/delete", versionedPrefix, id), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentEdit method +func (c *Client) PaymentEdit(payment Payment, by string, site ...string) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + var uid = strconv.Itoa(payment.Id) + var context = checkBy(by) + + if context == "externalId" { + uid = payment.ExternalId + } + + paymentJson, _ := json.Marshal(&payment) + + p := url.Values{ + "payment": {string(paymentJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/orders/payments/%s/edit", versionedPrefix, uid), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Countries method +func (c *Client) Countries() (*CountriesResponse, int, ErrorResponse) { + var resp CountriesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/countries", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CostGroups method +func (c *Client) CostGroups() (*CostGroupsResponse, int, ErrorResponse) { + var resp CostGroupsResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/cost-groups", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CostItems method +func (c *Client) CostItems() (*CostItemsResponse, int, ErrorResponse) { + var resp CostItemsResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/cost-items", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Couriers method +func (c *Client) Couriers() (*CouriersResponse, int, ErrorResponse) { + var resp CouriersResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/couriers", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryServices method +func (c *Client) DeliveryServices() (*DeliveryServiceResponse, int, ErrorResponse) { + var resp DeliveryServiceResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/delivery-services", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryTypes method +func (c *Client) DeliveryTypes() (*DeliveryTypesResponse, int, ErrorResponse) { + var resp DeliveryTypesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/delivery-types", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// LegalEntities method +func (c *Client) LegalEntities() (*LegalEntitiesResponse, int, ErrorResponse) { + var resp LegalEntitiesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/legal-entities", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderMethods method +func (c *Client) OrderMethods() (*OrderMethodsResponse, int, ErrorResponse) { + var resp OrderMethodsResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/order-methods", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderTypes method +func (c *Client) OrderTypes() (*OrderTypesResponse, int, ErrorResponse) { + var resp OrderTypesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/order-types", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentStatuses method +func (c *Client) PaymentStatuses() (*PaymentStatusesResponse, int, ErrorResponse) { + var resp PaymentStatusesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/payment-statuses", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentTypes method +func (c *Client) PaymentTypes() (*PaymentTypesResponse, int, ErrorResponse) { + var resp PaymentTypesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/payment-types", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PriceTypes method +func (c *Client) PriceTypes() (*PriceTypesResponse, int, ErrorResponse) { + var resp PriceTypesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/price-types", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ProductStatuses method +func (c *Client) ProductStatuses() (*ProductStatusesResponse, int, ErrorResponse) { + var resp ProductStatusesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/product-statuses", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Statuses method +func (c *Client) Statuses() (*StatusesResponse, int, ErrorResponse) { + var resp StatusesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/statuses", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// StatusGroups method +func (c *Client) StatusGroups() (*StatusGroupsResponse, int, ErrorResponse) { + var resp StatusGroupsResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/status-groups", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Sites method +func (c *Client) Sites() (*SitesResponse, int, ErrorResponse) { + var resp SitesResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/sites", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Stores method +func (c *Client) Stores() (*StoresResponse, int, ErrorResponse) { + var resp StoresResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/reference/stores", versionedPrefix)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CostGroupEdit method +func (c *Client) CostGroupEdit(costGroup CostGroup) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&costGroup) + + p := url.Values{ + "costGroup": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-groups/%s/edit", versionedPrefix, costGroup.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CostItemEdit method +func (c *Client) CostItemEdit(costItem CostItem) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&costItem) + + p := url.Values{ + "costItem": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/cost-items/%s/edit", versionedPrefix, costItem.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CourierCreate method +func (c *Client) CourierCreate(courier Courier) (*CreateResponse, int, ErrorResponse) { + var resp CreateResponse + + objJson, _ := json.Marshal(&courier) + + p := url.Values{ + "courier": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CourierEdit method +func (c *Client) CourierEdit(courier Courier) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&courier) + + p := url.Values{ + "courier": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/couriers/%d/edit", versionedPrefix, courier.Id), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryServiceEdit method +func (c *Client) DeliveryServiceEdit(deliveryService DeliveryService) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&deliveryService) + + p := url.Values{ + "deliveryService": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-services/%s/edit", versionedPrefix, deliveryService.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryTypeEdit method +func (c *Client) DeliveryTypeEdit(deliveryType DeliveryType) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&deliveryType) + + p := url.Values{ + "deliveryType": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/delivery-types/%s/edit", versionedPrefix, deliveryType.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// LegalEntityEditorderMe method +func (c *Client) LegalEntityEdit(legalEntity LegalEntity) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&legalEntity) + + p := url.Values{ + "legalEntity": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/legal-entities/%s/edit", versionedPrefix, legalEntity.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderMethodEdit method +func (c *Client) OrderMethodEdit(orderMethod OrderMethod) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&orderMethod) + + p := url.Values{ + "orderMethod": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-methods/%s/edit", versionedPrefix, orderMethod.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrderTypeEdit method +func (c *Client) OrderTypeEdit(orderType OrderType) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&orderType) + + p := url.Values{ + "orderType": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/order-types/%s/edit", versionedPrefix, orderType.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentStatusEdit method +func (c *Client) PaymentStatusEdit(paymentStatus PaymentStatus) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&paymentStatus) + + p := url.Values{ + "paymentStatus": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-statuses/%s/edit", versionedPrefix, paymentStatus.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PaymentTypeEdit method +func (c *Client) PaymentTypeEdit(paymentType PaymentType) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&paymentType) + + p := url.Values{ + "paymentType": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/payment-types/%s/edit", versionedPrefix, paymentType.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PriceTypeEdit method +func (c *Client) PriceTypeEdit(priceType PriceType) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&priceType) + + p := url.Values{ + "priceType": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/price-types/%s/edit", versionedPrefix, priceType.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ProductStatusEdit method +func (c *Client) ProductStatusEdit(productStatus ProductStatus) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&productStatus) + + p := url.Values{ + "productStatus": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/product-statuses/%s/edit", versionedPrefix, productStatus.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// StatusEdit method +func (c *Client) StatusEdit(st Status) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&st) + + p := url.Values{ + "status": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/statuses/%s/edit", versionedPrefix, st.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// SiteEdit method +func (c *Client) SiteEdit(site Site) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&site) + + p := url.Values{ + "site": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/sites/%s/edit", versionedPrefix, site.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// StoreEdit method +func (c *Client) StoreEdit(store Store) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + objJson, _ := json.Marshal(&store) + + p := url.Values{ + "store": {string(objJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/reference/stores/%s/edit", versionedPrefix, store.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Inventories method +func (c *Client) Inventories(parameters InventoriesRequest) (*InventoriesResponse, int, ErrorResponse) { + var resp InventoriesResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/store/inventories?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// InventoriesUpload method +func (c *Client) InventoriesUpload(inventories []InventoryUpload, site ...string) (*StoreUploadResponse, int, ErrorResponse) { + var resp StoreUploadResponse + + uploadJson, _ := json.Marshal(&inventories) + + p := url.Values{ + "offers": {string(uploadJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/store/inventories/upload", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// PricesUpload method +func (c *Client) PricesUpload(prices []OfferPriceUpload) (*StoreUploadResponse, int, ErrorResponse) { + var resp StoreUploadResponse + + uploadJson, _ := json.Marshal(&prices) + + p := url.Values{ + "prices": {string(uploadJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/store/prices/upload", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ProductsGroup method +func (c *Client) ProductsGroup(parameters ProductsGroupsRequest) (*ProductsGroupsResponse, int, ErrorResponse) { + var resp ProductsGroupsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/store/product-groups?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ProductsGroup method +func (c *Client) Products(parameters ProductsRequest) (*ProductsResponse, int, ErrorResponse) { + var resp ProductsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/store/products?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ProductsProperties method +func (c *Client) ProductsProperties(parameters ProductsPropertiesRequest) (*ProductsPropertiesResponse, int, ErrorResponse) { + var resp ProductsPropertiesResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/store/products/properties?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryTracking method +func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (*SucessfulResponse, int, ErrorResponse) { + var resp SucessfulResponse + + updateJson, _ := json.Marshal(¶meters) + + p := url.Values{ + "statusUpdate": {string(updateJson[:])}, + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/generic/%s/tracking", versionedPrefix, subcode), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryShipments method +func (c *Client) DeliveryShipments(parameters DeliveryShipmentsRequest) (*DeliveryShipmentsResponse, int, ErrorResponse) { + var resp DeliveryShipmentsResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/delivery/shipments?%s", versionedPrefix, params.Encode())) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryShipments method +func (c *Client) DeliveryShipment(id int) (*DeliveryShipmentResponse, int, ErrorResponse) { + var resp DeliveryShipmentResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/delivery/shipments/%s", versionedPrefix, id)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryShipmentEdit method +func (c *Client) DeliveryShipmentEdit(shipment DeliveryShipment, site ...string) (*DeliveryShipmentUpdateResponse, int, ErrorResponse) { + var resp DeliveryShipmentUpdateResponse + updateJson, _ := json.Marshal(&shipment) + + p := url.Values{ + "deliveryShipment": {string(updateJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/shipments/%s/edit", versionedPrefix, strconv.Itoa(shipment.Id)), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// DeliveryShipmentCreate method +func (c *Client) DeliveryShipmentCreate(shipment DeliveryShipment, deliveryType string, site ...string) (*DeliveryShipmentUpdateResponse, int, ErrorResponse) { + var resp DeliveryShipmentUpdateResponse + updateJson, _ := json.Marshal(&shipment) + + p := url.Values{ + "deliveryType": {string(deliveryType)}, + "deliveryShipment": {string(updateJson[:])}, + } + + fillSite(&p, site) + + data, status, err := c.PostRequest(fmt.Sprintf("%s/delivery/shipments/create", versionedPrefix), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// IntegrationModule method +func (c *Client) IntegrationModule(code string) (*IntegrationModuleResponse, int, ErrorResponse) { + var resp IntegrationModuleResponse + + data, status, err := c.GetRequest(fmt.Sprintf("%s/integration-modules/%s", versionedPrefix, code)) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// IntegrationModuleEdit method +func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (*IntegrationModuleEditResponse, int, ErrorResponse) { + var resp IntegrationModuleEditResponse + updateJson, _ := json.Marshal(&integrationModule) + + p := url.Values{"integrationModule": {string(updateJson[:])}} + + data, status, err := c.PostRequest(fmt.Sprintf("%s/integration-modules/%s/edit", versionedPrefix, integrationModule.Code), p) + if err.ErrorMsg != "" { + return &resp, status, err + } + + json.Unmarshal(data, &resp) + + return &resp, status, err +} diff --git a/v5/client_test.go b/v5/client_test.go new file mode 100644 index 0000000..34ad4c5 --- /dev/null +++ b/v5/client_test.go @@ -0,0 +1,2078 @@ +package v5 + +import ( + "fmt" + "math/rand" + "net/http" + "net/url" + "os" + "strconv" + "testing" + "time" +) + +var r *rand.Rand // Rand for this package. +var user, _ = strconv.Atoi(os.Getenv("RETAILCRM_USER")) +var statuses = map[int]bool{http.StatusOK: true, http.StatusCreated: true} + +func init() { + r = rand.New(rand.NewSource(time.Now().UnixNano())) +} + +func RandomString(strlen int) string { + const chars = "abcdefghijklmnopqrstuvwxyz0123456789" + result := make([]byte, strlen) + + for i := range result { + result[i] = chars[r.Intn(len(chars))] + } + + return string(result) +} + +func client() *Client { + return New(os.Getenv("RETAILCRM_URL"), os.Getenv("RETAILCRM_KEY")) +} + +func TestGetRequest(t *testing.T) { + c := client() + _, status, _ := c.GetRequest("/fake-method") + + if status != http.StatusNotFound { + t.Fail() + } +} + +func TestPostRequest(t *testing.T) { + c := client() + _, status, _ := c.PostRequest("/fake-method", url.Values{}) + + if status != http.StatusNotFound { + t.Fail() + } +} + +func TestClient_ApiVersionsVersions(t *testing.T) { + c := client() + + data, status, err := c.ApiVersions() + if err.ErrorMsg != "" { + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Fail() + } + + if data.Success != true { + t.Fail() + } +} + +func TestClient_ApiCredentialsCredentials(t *testing.T) { + c := client() + + data, status, err := c.ApiCredentials() + if err.ErrorMsg != "" { + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Fail() + } + + if data.Success != true { + t.Fail() + } +} + +func TestClient_CustomersCustomers(t *testing.T) { + c := client() + + data, status, err := c.Customers(CustomersRequest{ + Filter: CustomersFilter{ + City: "Москва", + }, + Page: 3, + }) + + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomerChange(t *testing.T) { + c := client() + + f := Customer{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + Address: &Address{ + City: "Москва", + Street: "Кутузовский", + Building: "14", + }, + } + + cr, sc, err := c.CustomerCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sc != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if cr.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + f.Id = cr.Id + f.Vip = true + + ed, se, err := c.CustomerEdit(f, "id") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if se != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if ed.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + data, status, err := c.Customer(f.ExternalId, "externalId", "") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Customer.ExternalId != f.ExternalId { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomersUpload(t *testing.T) { + c := client() + customers := make([]Customer, 3) + + for i := range customers { + customers[i] = Customer{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + } + } + + data, status, err := c.CustomersUpload(customers) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomersCombine(t *testing.T) { + c := client() + + dataFirst, status, err := c.CustomerCreate(Customer{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if dataFirst.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + dataSecond, status, err := c.CustomerCreate(Customer{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if dataSecond.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + dataThird, status, err := c.CustomerCreate(Customer{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if dataThird.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + data, status, err := c.CustomersCombine([]Customer{{Id: dataFirst.Id}, {Id: dataSecond.Id}}, Customer{Id: dataThird.Id}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomersFixExternalIds(t *testing.T) { + c := client() + f := Customer{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + } + + cr, sc, err := c.CustomerCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sc != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if cr.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + customers := []IdentifiersPair{{ + Id: cr.Id, + ExternalId: RandomString(8), + }} + + fx, fe, err := c.CustomersFixExternalIds(customers) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if fe != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if fx.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CustomersHistory(t *testing.T) { + c := client() + f := CustomersHistoryRequest{ + Filter: CustomersHistoryFilter{ + SinceId: 20, + }, + } + + data, status, err := c.CustomersHistory(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if len(data.History) == 0 { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_NotesNotes(t *testing.T) { + c := client() + + data, status, err := c.Notes(NotesRequest{Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_NotesCreateDelete(t *testing.T) { + c := client() + + createCustomerResponse, createCustomerStatus, err := c.CustomerCreate(Customer{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if createCustomerStatus != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if createCustomerResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + noteCreateResponse, noteCreateStatus, err := c.NoteCreate(Note{ + Text: "some text", + ManagerId: user, + Customer: &Customer{ + Id: createCustomerResponse.Id, + }, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if noteCreateStatus != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if noteCreateResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + noteDeleteResponse, noteDeleteStatus, err := c.NoteDelete(noteCreateResponse.Id) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if noteDeleteStatus != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if noteDeleteResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrdersOrders(t *testing.T) { + c := client() + + data, status, err := c.Orders(OrdersRequest{Filter: OrdersFilter{City: "Москва"}, Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrderChange(t *testing.T) { + c := client() + + random := RandomString(8) + + f := Order{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: random, + Email: fmt.Sprintf("%s@example.com", random), + } + + cr, sc, err := c.OrderCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sc != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if cr.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + f.Id = cr.Id + f.CustomerComment = "test comment" + + ed, se, err := c.OrderEdit(f, "id") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if se != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if ed.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + data, status, err := c.Order(f.ExternalId, "externalId", "") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Order.ExternalId != f.ExternalId { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrdersUpload(t *testing.T) { + c := client() + orders := make([]Order, 3) + + for i := range orders { + orders[i] = Order{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + } + } + + data, status, err := c.OrdersUpload(orders) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrdersCombine(t *testing.T) { + c := client() + + dataFirst, status, err := c.OrderCreate(Order{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if dataFirst.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + dataSecond, status, err := c.OrderCreate(Order{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if dataSecond.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + data, status, err := c.OrdersCombine("ours", Order{Id: dataFirst.Id}, Order{Id: dataSecond.Id}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrdersFixExternalIds(t *testing.T) { + c := client() + f := Order{ + FirstName: fmt.Sprintf("Name_%s", RandomString(8)), + LastName: fmt.Sprintf("Test_%s", RandomString(8)), + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + } + + cr, sc, err := c.OrderCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sc != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if cr.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + orders := []IdentifiersPair{{ + Id: cr.Id, + ExternalId: RandomString(8), + }} + + fx, fe, err := c.OrdersFixExternalIds(orders) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if fe != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if fx.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrdersHistory(t *testing.T) { + c := client() + + data, status, err := c.OrdersHistory(OrdersHistoryRequest{Filter: OrdersHistoryFilter{SinceId: 20}}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if len(data.History) == 0 { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PaymentCreateEditDelete(t *testing.T) { + c := client() + + order := Order{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + } + + createOrderResponse, status, err := c.OrderCreate(order) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if createOrderResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + f := Payment{ + Order: &Order{ + Id: createOrderResponse.Id, + }, + Amount: 300, + Type: "cash", + } + + paymentCreateResponse, status, err := c.PaymentCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if paymentCreateResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + k := Payment{ + Id: paymentCreateResponse.Id, + Amount: 500, + } + + paymentEditResponse, status, err := c.PaymentEdit(k, "id") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if paymentEditResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + paymentDeleteResponse, status, err := c.PaymentDelete(paymentCreateResponse.Id) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if paymentDeleteResponse.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_TasksTasks(t *testing.T) { + c := client() + + f := TasksRequest{ + Filter: TasksFilter{ + Creators: []int{user}, + }, + Page: 1, + } + + data, status, err := c.Tasks(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_TaskChange(t *testing.T) { + c := client() + + f := Task{ + Text: RandomString(15), + PerformerId: user, + } + + cr, sc, err := c.TaskCreate(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sc != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if cr.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + f.Id = cr.Id + f.Commentary = RandomString(20) + + gt, sg, err := c.Task(f.Id) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if sg != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if gt.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + data, status, err := c.TaskEdit(f) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_UsersUsers(t *testing.T) { + c := client() + + data, status, err := c.Users(UsersRequest{Filter: UsersFilter{Active: 1}, Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_UsersUser(t *testing.T) { + c := client() + + data, st, err := c.User(user) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_UsersGroups(t *testing.T) { + c := client() + + data, status, err := c.UserGroups(UserGroupsRequest{Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_UsersUpdate(t *testing.T) { + c := client() + + data, st, err := c.UserStatus(user, "busy") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_StaticticUpdate(t *testing.T) { + c := client() + + data, st, err := c.StaticticUpdate() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Countries(t *testing.T) { + c := client() + + data, st, err := c.Couriers() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostGroups(t *testing.T) { + c := client() + + data, st, err := c.CostGroups() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostItems(t *testing.T) { + c := client() + + data, st, err := c.CostItems() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Couriers(t *testing.T) { + c := client() + + data, st, err := c.Couriers() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_DeliveryService(t *testing.T) { + c := client() + + data, st, err := c.DeliveryServices() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_DeliveryTypes(t *testing.T) { + c := client() + + data, st, err := c.DeliveryTypes() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_LegalEntities(t *testing.T) { + c := client() + + data, st, err := c.LegalEntities() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrderMethods(t *testing.T) { + c := client() + + data, st, err := c.OrderMethods() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrderTypes(t *testing.T) { + c := client() + + data, st, err := c.OrderTypes() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PaymentStatuses(t *testing.T) { + c := client() + + data, st, err := c.PaymentStatuses() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PaymentTypes(t *testing.T) { + c := client() + + data, st, err := c.PaymentTypes() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PriceTypes(t *testing.T) { + c := client() + + data, st, err := c.PriceTypes() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_ProductStatuses(t *testing.T) { + c := client() + + data, st, err := c.ProductStatuses() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Statuses(t *testing.T) { + c := client() + + data, st, err := c.Statuses() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_StatusGroups(t *testing.T) { + c := client() + + data, st, err := c.StatusGroups() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Sites(t *testing.T) { + c := client() + + data, st, err := c.Sites() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Stores(t *testing.T) { + c := client() + + data, st, err := c.Stores() + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if st != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_CostGroupItemEdit(t *testing.T) { + c := client() + + uid := RandomString(4) + + data, st, err := c.CostGroupEdit(CostGroup{ + Code: fmt.Sprintf("cost-gr-%s", uid), + Active: false, + Color: "#da5c98", + Name: fmt.Sprintf("CostGroup-%s", uid), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + idata, st, err := c.CostItemEdit(CostItem{ + Code: fmt.Sprintf("cost-it-%s", uid), + Name: fmt.Sprintf("CostItem-%s", uid), + Group: fmt.Sprintf("cost-gr-%s", uid), + Type: "const", + AppliesToOrders: true, + Active: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if idata.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Courier(t *testing.T) { + c := client() + + cur := Courier{ + Active: true, + Email: fmt.Sprintf("%s@example.com", RandomString(5)), + FirstName: fmt.Sprintf("%s", RandomString(5)), + LastName: fmt.Sprintf("%s", RandomString(5)), + } + + data, st, err := c.CourierCreate(cur) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + cur.Id = data.Id + cur.Patronymic = fmt.Sprintf("%s", RandomString(5)) + + idata, st, err := c.CourierEdit(cur) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if idata.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_DeliveryServiceEdit(t *testing.T) { + c := client() + + data, st, err := c.DeliveryServiceEdit(DeliveryService{ + Active: false, + Code: RandomString(5), + Name: RandomString(5), + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_DeliveryTypeEdit(t *testing.T) { + c := client() + + x := []string{"cash", "bank-card"} + + data, st, err := c.DeliveryTypeEdit(DeliveryType{ + Active: false, + Code: RandomString(5), + Name: RandomString(5), + DefaultCost: 300, + PaymentTypes: x, + DefaultForCrm: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrderMethodEdit(t *testing.T) { + c := client() + + data, st, err := c.OrderMethodEdit(OrderMethod{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + DefaultForCrm: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_OrderTypeEdit(t *testing.T) { + c := client() + + data, st, err := c.OrderTypeEdit(OrderType{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + DefaultForCrm: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PaymentStatusEdit(t *testing.T) { + c := client() + + data, st, err := c.PaymentStatusEdit(PaymentStatus{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + DefaultForCrm: false, + PaymentTypes: []string{"cash"}, + PaymentComplete: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PaymentTypeEdit(t *testing.T) { + c := client() + + data, st, err := c.PaymentTypeEdit(PaymentType{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + DefaultForCrm: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PriceTypeEdit(t *testing.T) { + c := client() + + data, st, err := c.PriceTypeEdit(PriceType{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_ProductStatusEdit(t *testing.T) { + c := client() + + data, st, err := c.ProductStatusEdit(ProductStatus{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + CancelStatus: false, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_StatusEdit(t *testing.T) { + c := client() + + data, st, err := c.StatusEdit(Status{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + Group: "new", + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_SiteEdit(t *testing.T) { + c := client() + + data, _, err := c.SiteEdit(Site{ + Code: RandomString(5), + Name: RandomString(5), + Url: fmt.Sprintf("https://%s.example.com", RandomString(4)), + LoadFromYml: false, + }) + if err.ErrorMsg == "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != false { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_StoreEdit(t *testing.T) { + c := client() + + data, st, err := c.StoreEdit(Store{ + Code: RandomString(5), + Name: RandomString(5), + Active: false, + Type: "store-type-warehouse", + InventoryType: "integer", + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if !statuses[st] { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PackChange(t *testing.T) { + c := client() + + o, status, err := c.OrderCreate(Order{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: RandomString(8), + Email: fmt.Sprintf("%s@example.com", RandomString(8)), + Items: []OrderItem{{Offer: Offer{Id: 1609}, Quantity: 5}}, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if o.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + g, status, err := c.Order(strconv.Itoa(o.Id), "id", "") + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if o.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + p, status, err := c.PackCreate(Pack{ + Store: "test-store", + ItemId: g.Order.Items[0].Id, + Quantity: 1, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if p.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + s, status, err := c.Pack(p.Id) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if s.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + e, status, err := c.PackEdit(Pack{Id: p.Id, Quantity: 2}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if e.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + d, status, err := c.PackDelete(p.Id) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if d.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_PacksHistory(t *testing.T) { + c := client() + + data, status, err := c.PacksHistory(PacksHistoryRequest{Filter: OrdersHistoryFilter{SinceId: 5}}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if len(data.History) == 0 { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Packs(t *testing.T) { + c := client() + + data, status, err := c.Packs(PacksRequest{Filter: PacksFilter{}, Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Inventories(t *testing.T) { + c := client() + + data, status, err := c.Inventories(InventoriesRequest{Filter: InventoriesFilter{Details: 1}, Page: 1}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Segments(t *testing.T) { + c := client() + + data, status, err := c.Segments(SegmentsRequest{}) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if data.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_IntegrationModule(t *testing.T) { + c := client() + + name := RandomString(5) + code := RandomString(8) + + m, status, err := c.IntegrationModuleEdit(IntegrationModule{ + Code: code, + IntegrationCode: code, + Active: false, + Name: fmt.Sprintf("Integration module %s", name), + AccountUrl: fmt.Sprintf("http://example.com/%s/account", name), + BaseUrl: fmt.Sprintf("http://example.com/%s", name), + ClientId: RandomString(10), + Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg", + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusCreated { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if m.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + g, status, err := c.IntegrationModule(code) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if g.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_IntegrationModuleFail(t *testing.T) { + c := client() + code := RandomString(8) + + m, status, err := c.IntegrationModuleEdit(IntegrationModule{ + Code: code, + }) + if err.ErrorMsg == "" { + t.Fail() + } + + if status < http.StatusBadRequest { + t.Fail() + } + + if m.Success != false { + t.Fail() + } + + g, status, err := c.IntegrationModule(RandomString(12)) + if err.ErrorMsg == "" { + t.Fail() + } + + if status < http.StatusBadRequest { + t.Fail() + } + + if g.Success != false { + t.Fail() + } +} + +func TestClient_ProductsGroup(t *testing.T) { + c := client() + + g, status, err := c.ProductsGroup(ProductsGroupsRequest{ + Filter: ProductsGroupsFilter{ + Active: 1, + }, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if g.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_Products(t *testing.T) { + c := client() + + g, status, err := c.Products(ProductsRequest{ + Filter: ProductsFilter{ + Active: 1, + MinPrice: 1, + }, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if g.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_ProductsProperties(t *testing.T) { + c := client() + + sites := make([]string, 1) + sites[0] = os.Getenv("RETAILCRM_SITE") + + g, status, err := c.ProductsProperties(ProductsPropertiesRequest{ + Filter: ProductsPropertiesFilter{ + Sites: sites, + }, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if g.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} + +func TestClient_DeliveryShipments(t *testing.T) { + c := client() + + g, status, err := c.DeliveryShipments(DeliveryShipmentsRequest{ + Filter: ShipmentFilter{ + DateFrom: "2017-10-10", + }, + }) + if err.ErrorMsg != "" { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if status != http.StatusOK { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } + + if g.Success != true { + t.Errorf("%v", err.ErrorMsg) + t.Fail() + } +} diff --git a/v5/filters.go b/v5/filters.go new file mode 100644 index 0000000..7bcb7dd --- /dev/null +++ b/v5/filters.go @@ -0,0 +1,298 @@ +package v5 + +// CustomersFilter type +type CustomersFilter struct { + Ids []string `url:"ids,omitempty,brackets"` + ExternalIds []string `url:"externalIds,omitempty,brackets"` + City string `url:"city,omitempty"` + Region string `url:"region,omitempty"` + Name string `url:"name,omitempty"` + Email string `url:"email,omitempty"` + Notes string `url:"notes,omitempty"` + MinOrdersCount int `url:"minOrdersCount,omitempty"` + MaxOrdersCount int `url:"maxOrdersCount,omitempty"` + MinAverageSumm float32 `url:"minAverageSumm,omitempty"` + MaxAverageSumm float32 `url:"maxAverageSumm,omitempty"` + MinTotalSumm float32 `url:"minTotalSumm,omitempty"` + MaxTotalSumm float32 `url:"maxTotalSumm,omitempty"` + MinCostSumm float32 `url:"minCostSumm,omitempty"` + MaxCostSumm float32 `url:"maxCostSumm,omitempty"` + ClassSegment string `url:"classSegment,omitempty"` + Vip int `url:"vip,omitempty"` + Bad int `url:"bad,omitempty"` + Attachments int `url:"attachments,omitempty"` + Online int `url:"online,omitempty"` + EmailMarketingUnsubscribed int `url:"emailMarketingUnsubscribed,omitempty"` + Sex string `url:"sex,omitempty"` + Segment string `url:"segment,omitempty"` + DiscountCardNumber string `url:"discountCardNumber,omitempty"` + ContragentName string `url:"contragentName,omitempty"` + ContragentInn string `url:"contragentInn,omitempty"` + ContragentKpp string `url:"contragentKpp,omitempty"` + ContragentBik string `url:"contragentBik,omitempty"` + ContragentCorrAccount string `url:"contragentCorrAccount,omitempty"` + ContragentBankAccount string `url:"contragentBankAccount,omitempty"` + ContragentTypes []string `url:"contragentTypes,omitempty,brackets"` + Sites []string `url:"sites,omitempty,brackets"` + Managers []string `url:"managers,omitempty,brackets"` + ManagerGroups []string `url:"managerGroups,omitempty,brackets"` + DateFrom string `url:"dateFrom,omitempty"` + DateTo string `url:"dateTo,omitempty"` + FirstWebVisitFrom string `url:"firstWebVisitFrom,omitempty"` + FirstWebVisitTo string `url:"firstWebVisitTo,omitempty"` + LastWebVisitFrom string `url:"lastWebVisitFrom,omitempty"` + LastWebVisitTo string `url:"lastWebVisitTo,omitempty"` + FirstOrderFrom string `url:"firstOrderFrom,omitempty"` + FirstOrderTo string `url:"firstOrderTo,omitempty"` + LastOrderFrom string `url:"lastOrderFrom,omitempty"` + LastOrderTo string `url:"lastOrderTo,omitempty"` + BrowserId string `url:"browserId,omitempty"` + Commentary string `url:"commentary,omitempty"` + SourceName string `url:"sourceName,omitempty"` + MediumName string `url:"mediumName,omitempty"` + CampaignName string `url:"campaignName,omitempty"` + KeywordName string `url:"keywordName,omitempty"` + AdContentName string `url:"adContentName,omitempty"` + CustomFields map[string]string `url:"customFields,omitempty,brackets"` +} + +// CustomersHistoryFilter type +type CustomersHistoryFilter struct { + CustomerId int `url:"customerId,omitempty"` + SinceId int `url:"sinceId,omitempty"` + CustomerExternalId string `url:"customerExternalId,omitempty"` + StartDate string `url:"startDate,omitempty"` + EndDate string `url:"endDate,omitempty"` +} + +// OrdersFilter type +type OrdersFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + ExternalIds []string `url:"externalIds,omitempty,brackets"` + Numbers []string `url:"numbers,omitempty,brackets"` + Customer string `url:"customer,omitempty"` + CustomerId string `url:"customerId,omitempty"` + CustomerExternalId string `url:"customerExternalId,omitempty"` + Countries []string `url:"countries,omitempty,brackets"` + City string `url:"city,omitempty"` + Region string `url:"region,omitempty"` + Index string `url:"index,omitempty"` + Metro string `url:"metro,omitempty"` + Email string `url:"email,omitempty"` + DeliveryTimeFrom string `url:"deliveryTimeFrom,omitempty"` + DeliveryTimeTo string `url:"deliveryTimeTo,omitempty"` + MinPrepaySumm string `url:"minPrepaySumm,omitempty"` + MaxPrepaySumm string `url:"maxPrepaySumm,omitempty"` + MinPrice string `url:"minPrice,omitempty"` + MaxPrice string `url:"maxPrice,omitempty"` + Product string `url:"product,omitempty"` + Vip int `url:"vip,omitempty"` + Bad int `url:"bad,omitempty"` + Attachments int `url:"attachments,omitempty"` + Expired int `url:"expired,omitempty"` + Call int `url:"call,omitempty"` + Online int `url:"online,omitempty"` + Shipped int `url:"shipped,omitempty"` + UploadedToExtStoreSys int `url:"uploadedToExtStoreSys,omitempty"` + ReceiptFiscalDocumentAttribute int `url:"receiptFiscalDocumentAttribute,omitempty"` + ReceiptStatus int `url:"receiptStatus,omitempty"` + ReceiptOperation int `url:"receiptOperation,omitempty"` + MinDeliveryCost string `url:"minDeliveryCost,omitempty"` + MaxDeliveryCost string `url:"maxDeliveryCost,omitempty"` + MinDeliveryNetCost string `url:"minDeliveryNetCost,omitempty"` + MaxDeliveryNetCost string `url:"maxDeliveryNetCost,omitempty"` + ManagerComment string `url:"managerComment,omitempty"` + CustomerComment string `url:"customerComment,omitempty"` + MinMarginSumm string `url:"minMarginSumm,omitempty"` + MaxMarginSumm string `url:"maxMarginSumm,omitempty"` + MinPurchaseSumm string `url:"minPurchaseSumm,omitempty"` + MaxPurchaseSumm string `url:"maxPurchaseSumm,omitempty"` + MinCostSumm string `url:"minCostSumm,omitempty"` + MaxCostSumm string `url:"maxCostSumm,omitempty"` + TrackNumber string `url:"trackNumber,omitempty"` + ContragentName string `url:"contragentName,omitempty"` + ContragentInn string `url:"contragentInn,omitempty"` + ContragentKpp string `url:"contragentKpp,omitempty"` + ContragentBik string `url:"contragentBik,omitempty"` + ContragentCorrAccount string `url:"contragentCorrAccount,omitempty"` + ContragentBankAccount string `url:"contragentBankAccount,omitempty"` + ContragentTypes []string `url:"contragentTypes,omitempty,brackets"` + OrderTypes []string `url:"orderTypes,omitempty,brackets"` + PaymentStatuses []string `url:"paymentStatuses,omitempty,brackets"` + PaymentTypes []string `url:"paymentTypes,omitempty,brackets"` + DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"` + OrderMethods []string `url:"orderMethods,omitempty,brackets"` + ShipmentStores []string `url:"shipmentStores,omitempty,brackets"` + Couriers []string `url:"couriers,omitempty,brackets"` + Managers []string `url:"managers,omitempty,brackets"` + ManagerGroups []string `url:"managerGroups,omitempty,brackets"` + Sites []string `url:"sites,omitempty,brackets"` + CreatedAtFrom string `url:"createdAtFrom,omitempty"` + CreatedAtTo string `url:"createdAtTo,omitempty"` + FullPaidAtFrom string `url:"fullPaidAtFrom,omitempty"` + FullPaidAtTo string `url:"fullPaidAtTo,omitempty"` + DeliveryDateFrom string `url:"deliveryDateFrom,omitempty"` + DeliveryDateTo string `url:"deliveryDateTo,omitempty"` + StatusUpdatedAtFrom string `url:"statusUpdatedAtFrom,omitempty"` + StatusUpdatedAtTo string `url:"statusUpdatedAtTo,omitempty"` + DpdParcelDateFrom string `url:"dpdParcelDateFrom,omitempty"` + DpdParcelDateTo string `url:"dpdParcelDateTo,omitempty"` + FirstWebVisitFrom string `url:"firstWebVisitFrom,omitempty"` + FirstWebVisitTo string `url:"firstWebVisitTo,omitempty"` + LastWebVisitFrom string `url:"lastWebVisitFrom,omitempty"` + LastWebVisitTo string `url:"lastWebVisitTo,omitempty"` + FirstOrderFrom string `url:"firstOrderFrom,omitempty"` + FirstOrderTo string `url:"firstOrderTo,omitempty"` + LastOrderFrom string `url:"lastOrderFrom,omitempty"` + LastOrderTo string `url:"lastOrderTo,omitempty"` + ShipmentDateFrom string `url:"shipmentDateFrom,omitempty"` + ShipmentDateTo string `url:"shipmentDateTo,omitempty"` + ExtendedStatus []string `url:"extendedStatus,omitempty,brackets"` + SourceName string `url:"sourceName,omitempty"` + MediumName string `url:"mediumName,omitempty"` + CampaignName string `url:"campaignName,omitempty"` + KeywordName string `url:"keywordName,omitempty"` + AdContentName string `url:"adContentName,omitempty"` + CustomFields map[string]string `url:"customFields,omitempty,brackets"` +} + +// OrdersHistoryFilter type +type OrdersHistoryFilter struct { + OrderId int `url:"orderId,omitempty"` + SinceId int `url:"sinceId,omitempty"` + OrderExternalId string `url:"orderExternalId,omitempty"` + StartDate string `url:"startDate,omitempty"` + EndDate string `url:"endDate,omitempty"` +} + +// UsersFilter type +type UsersFilter struct { + Email string `url:"email,omitempty"` + Status string `url:"status,omitempty"` + Online int `url:"online,omitempty"` + Active int `url:"active,omitempty"` + IsManager int `url:"isManager,omitempty"` + IsAdmin int `url:"isAdmin,omitempty"` + CreatedAtFrom string `url:"createdAtFrom,omitempty"` + CreatedAtTo string `url:"createdAtTo,omitempty"` + Groups []string `url:"groups,omitempty,brackets"` +} + +// TasksFilter type +type TasksFilter struct { + OrderNumber string `url:"orderNumber,omitempty"` + Status string `url:"status,omitempty"` + Customer string `url:"customer,omitempty"` + Text string `url:"text,omitempty"` + DateFrom string `url:"dateFrom,omitempty"` + DateTo string `url:"dateTo,omitempty"` + Creators []int `url:"creators,omitempty,brackets"` + Performers []int `url:"performers,omitempty,brackets"` +} + +// NotesFilter type +type NotesFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + CustomerIds []int `url:"customerIds,omitempty,brackets"` + CustomerExternalIds []string `url:"customerExternalIds,omitempty,brackets"` + ManagerIds []int `url:"managerIds,omitempty,brackets"` + Text string `url:"text,omitempty"` + CreatedAtFrom string `url:"createdAtFrom,omitempty"` + CreatedAtTo string `url:"createdAtTo,omitempty"` +} + +// SegmentsFilter type +type SegmentsFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + Active int `url:"active,omitempty"` + Name string `url:"name,omitempty"` + Type string `url:"type,omitempty"` + MinCustomersCount int `url:"minCustomersCount,omitempty"` + MaxCustomersCount int `url:"maxCustomersCount,omitempty"` + DateFrom string `url:"dateFrom,omitempty"` + DateTo string `url:"dateTo,omitempty"` +} + +// PacksFilter type +type PacksFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + Stores []string `url:"stores,omitempty"` + ItemId int `url:"itemId,omitempty"` + OfferXmlId string `url:"offerXmlId,omitempty"` + OfferExternalId string `url:"offerExternalId,omitempty"` + OrderId int `url:"orderId,omitempty"` + OrderExternalId string `url:"orderExternalId,omitempty"` + ShipmentDateFrom string `url:"shipmentDateFrom,omitempty"` + ShipmentDateTo string `url:"shipmentDateTo,omitempty"` + InvoiceNumber string `url:"invoiceNumber,omitempty"` + DeliveryNoteNumber string `url:"deliveryNoteNumber,omitempty"` +} + +// InventoriesFilter type +type InventoriesFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + ProductExternalId string `url:"productExternalId,omitempty"` + ProductArticle string `url:"productArticle,omitempty"` + OfferExternalId string `url:"offerExternalId,omitempty"` + OfferXmlId string `url:"offerXmlId,omitempty"` + OfferArticle string `url:"offerArticle,omitempty"` + ProductActive int `url:"productActive,omitempty"` + Details int `url:"details,omitempty"` + Sites []string `url:"sites,omitempty,brackets"` +} + +// ProductsGroupsFilter type +type ProductsGroupsFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + Sites []string `url:"sites,omitempty,brackets"` + Active int `url:"active,omitempty"` + ParentGroupId string `url:"parentGroupId,omitempty"` +} + +// ProductsFilter type +type ProductsFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + OfferIds []int `url:"offerIds,omitempty,brackets"` + Active int `url:"active,omitempty"` + Recommended int `url:"recommended,omitempty"` + Novelty int `url:"novelty,omitempty"` + Stock int `url:"stock,omitempty"` + Popular int `url:"popular,omitempty"` + MaxQuantity float32 `url:"maxQuantity,omitempty"` + MinQuantity float32 `url:"minQuantity,omitempty"` + MaxPurchasePrice float32 `url:"maxPurchasePrice,omitempty"` + MinPurchasePrice float32 `url:"minPurchasePrice,omitempty"` + MaxPrice float32 `url:"maxPrice,omitempty"` + MinPrice float32 `url:"minPrice,omitempty"` + Groups string `url:"groups,omitempty"` + Name string `url:"name,omitempty"` + ClassSegment string `url:"classSegment,omitempty"` + XmlId string `url:"xmlId,omitempty"` + ExternalId string `url:"externalId,omitempty"` + Manufacturer string `url:"manufacturer,omitempty"` + Url string `url:"url,omitempty"` + PriceType string `url:"priceType,omitempty"` + OfferExternalId string `url:"offerExternalId,omitempty"` + Sites []string `url:"sites,omitempty,brackets"` + Properties map[string]string `url:"properties,omitempty,brackets"` +} + +// ProductsPropertiesFilter type +type ProductsPropertiesFilter struct { + Code string `url:"code,omitempty"` + Name string `url:"name,omitempty"` + Sites []string `url:"sites,omitempty,brackets"` +} + +// ShipmentFilter type +type ShipmentFilter struct { + Ids []int `url:"ids,omitempty,brackets"` + ExternalId string `url:"externalId,omitempty"` + OrderNumber string `url:"orderNumber,omitempty"` + DateFrom string `url:"dateFrom,omitempty"` + DateTo string `url:"dateTo,omitempty"` + Stores []string `url:"stores,omitempty,brackets"` + Managers []string `url:"managers,omitempty,brackets"` + DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"` + Statuses []string `url:"statuses,omitempty,brackets"` +} diff --git a/v5/request.go b/v5/request.go new file mode 100644 index 0000000..91e4888 --- /dev/null +++ b/v5/request.go @@ -0,0 +1,144 @@ +package v5 + +// CustomerRequest type +type CustomerRequest struct { + By string `url:"by,omitempty"` + Site string `url:"site,omitempty"` +} + +// CustomersRequest type +type CustomersRequest struct { + Filter CustomersFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// CustomersUploadRequest type +type CustomersUploadRequest struct { + Customers []Customer `url:"customers,omitempty,brackets"` + Site string `url:"site,omitempty"` +} + +// CustomersHistoryRequest type +type CustomersHistoryRequest struct { + Filter CustomersHistoryFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// OrderRequest type +type OrderRequest struct { + By string `url:"by,omitempty"` + Site string `url:"site,omitempty"` +} + +// OrdersRequest type +type OrdersRequest struct { + Filter OrdersFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// OrdersUploadRequest type +type OrdersUploadRequest struct { + Orders []Order `url:"orders,omitempty,brackets"` + Site string `url:"site,omitempty"` +} + +// OrdersHistoryRequest type +type OrdersHistoryRequest struct { + Filter OrdersHistoryFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// PacksRequest type +type PacksRequest struct { + Filter PacksFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// PacksHistoryRequest type +type PacksHistoryRequest struct { + Filter OrdersHistoryFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// UsersRequest type +type UsersRequest struct { + Filter UsersFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// UserGroupsRequest type +type UserGroupsRequest struct { + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// TasksRequest type +type TasksRequest struct { + Filter TasksFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// NotesRequest type +type NotesRequest struct { + Filter TasksFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// SegmentsRequest type +type SegmentsRequest struct { + Filter SegmentsFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// InventoriesRequest type +type InventoriesRequest struct { + Filter InventoriesFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// ProductsGroupsRequest type +type ProductsGroupsRequest struct { + Filter ProductsGroupsFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// ProductsRequest type +type ProductsRequest struct { + Filter ProductsFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// ProductsPropertiesRequest type +type ProductsPropertiesRequest struct { + Filter ProductsPropertiesFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} + +// DeliveryTrackingRequest type +type DeliveryTrackingRequest struct { + DeliveryId string `url:"deliveryId,omitempty"` + TrackNumber string `url:"trackNumber,omitempty"` + History []DeliveryHistoryRecord `url:"history,omitempty,brackets"` + ExtraData map[string]string `url:"extraData,omitempty,brackets"` +} + +// DeliveryShipmentsRequest type +type DeliveryShipmentsRequest struct { + Filter ShipmentFilter `url:"filter,omitempty"` + Limit int `url:"limit,omitempty"` + Page int `url:"page,omitempty"` +} diff --git a/v5/response.go b/v5/response.go new file mode 100644 index 0000000..62d17cc --- /dev/null +++ b/v5/response.go @@ -0,0 +1,346 @@ +package v5 + +import "encoding/json" + +// ErrorResponse type +type ErrorResponse struct { + ErrorMsg string `json:"errorMsg,omitempty"` + Errors map[string]string `json:"errors,omitempty"` +} + +// ErrorResponse method +func (c *Client) ErrorResponse(data []byte) (ErrorResponse, error) { + var resp ErrorResponse + err := json.Unmarshal(data, &resp) + + return resp, err +} + +// SucessfulResponse type +type SucessfulResponse struct { + Success bool `json:"success,omitempty"` +} + +// CreateResponse type +type CreateResponse struct { + Success bool `json:"success"` + Id int `json:"id,omitempty"` +} + +// OperationResponse type +type OperationResponse struct { + Success bool `json:"success"` + Errors map[string]string `json:"errors,omitempty,brackets"` +} + +// VersionResponse return available API versions +type VersionResponse struct { + Success bool `json:"success,omitempty"` + Versions []string `json:"versions,brackets,omitempty"` +} + +// CredentialResponse return available API methods +type CredentialResponse struct { + Success bool `json:"success,omitempty"` + Credentials []string `json:"credentials,brackets,omitempty"` + SiteAccess string `json:"siteAccess,omitempty"` + SitesAvailable []string `json:"sitesAvailable,brackets,omitempty"` +} + +// CustomerResponse type +type CustomerResponse struct { + Success bool `json:"success"` + Customer *Customer `json:"customer,omitempty,brackets"` +} + +// CustomersResponse type +type CustomersResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Customers []Customer `json:"customers,omitempty,brackets"` +} + +// CustomerChangeResponse type +type CustomerChangeResponse struct { + Success bool `json:"success"` + Id int `json:"id,omitempty"` + State string `json:"state,omitempty"` +} + +// CustomersUploadResponse type +type CustomersUploadResponse struct { + Success bool `json:"success"` + UploadedCustomers []IdentifiersPair `json:"uploadedCustomers,omitempty,brackets"` +} + +// CustomersHistoryResponse type +type CustomersHistoryResponse struct { + Success bool `json:"success,omitempty"` + GeneratedAt string `json:"generatedAt,omitempty"` + History []CustomerHistoryRecord `json:"history,omitempty,brackets"` + Pagination *Pagination `json:"pagination,omitempty"` +} + +// OrderResponse type +type OrderResponse struct { + Success bool `json:"success"` + Order *Order `json:"order,omitempty,brackets"` +} + +// OrdersResponse type +type OrdersResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Orders []Order `json:"orders,omitempty,brackets"` +} + +// OrdersUploadResponse type +type OrdersUploadResponse struct { + Success bool `json:"success"` + UploadedOrders []IdentifiersPair `json:"uploadedOrders,omitempty,brackets"` +} + +// OrdersHistoryResponse type +type OrdersHistoryResponse struct { + Success bool `json:"success,omitempty"` + GeneratedAt string `json:"generatedAt,omitempty"` + History []OrdersHistoryRecord `json:"history,omitempty,brackets"` + Pagination *Pagination `json:"pagination,omitempty"` +} + +// PackResponse type +type PackResponse struct { + Success bool `json:"success"` + Pack *Pack `json:"pack,omitempty,brackets"` +} + +// PacksResponse type +type PacksResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Packs []Pack `json:"packs,omitempty,brackets"` +} + +// PacksHistoryResponse type +type PacksHistoryResponse struct { + Success bool `json:"success,omitempty"` + GeneratedAt string `json:"generatedAt,omitempty"` + History []PacksHistoryRecord `json:"history,omitempty,brackets"` + Pagination *Pagination `json:"pagination,omitempty"` +} + +// UserResponse type +type UserResponse struct { + Success bool `json:"success"` + User *User `json:"user,omitempty,brackets"` +} + +// UsersResponse type +type UsersResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Users []User `json:"users,omitempty,brackets"` +} + +// UserGroupsResponse type +type UserGroupsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Groups []UserGroup `json:"groups,omitempty,brackets"` +} + +// TaskResponse type +type TaskResponse struct { + Success bool `json:"success"` + Task *Task `json:"task,omitempty,brackets"` +} + +// TasksResponse type +type TasksResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Tasks []Task `json:"tasks,omitempty,brackets"` +} + +// NotesResponse type +type NotesResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Notes []Note `json:"notes,omitempty,brackets"` +} + +// SegmentsResponse type +type SegmentsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Segments []Segment `json:"segments,omitempty,brackets"` +} + +// CountriesResponse type +type CountriesResponse struct { + Success bool `json:"success"` + CountriesIso []string `json:"countriesIso,omitempty,brackets"` +} + +// CostGroupsResponse type +type CostGroupsResponse struct { + Success bool `json:"success"` + CostGroups []CostGroup `json:"costGroups,omitempty,brackets"` +} + +// CostItemsResponse type +type CostItemsResponse struct { + Success bool `json:"success"` + CostItems []CostItem `json:"costItems,omitempty,brackets"` +} + +// CouriersResponse type +type CouriersResponse struct { + Success bool `json:"success"` + Couriers []Courier `json:"couriers,omitempty,brackets"` +} + +// DeliveryServiceResponse type +type DeliveryServiceResponse struct { + Success bool `json:"success"` + DeliveryServices map[string]DeliveryService `json:"deliveryServices,omitempty,brackets"` +} + +// DeliveryTypesResponse type +type DeliveryTypesResponse struct { + Success bool `json:"success"` + DeliveryTypes map[string]DeliveryType `json:"deliveryTypes,omitempty,brackets"` +} + +// LegalEntitiesResponse type +type LegalEntitiesResponse struct { + Success bool `json:"success"` + LegalEntities []LegalEntity `json:"legalEntities,omitempty,brackets"` +} + +// OrderMethodsResponse type +type OrderMethodsResponse struct { + Success bool `json:"success"` + OrderMethods map[string]OrderMethod `json:"orderMethods,omitempty,brackets"` +} + +// OrderTypesResponse type +type OrderTypesResponse struct { + Success bool `json:"success"` + OrderTypes map[string]OrderType `json:"orderTypes,omitempty,brackets"` +} + +// PaymentStatusesResponse type +type PaymentStatusesResponse struct { + Success bool `json:"success"` + PaymentStatuses map[string]PaymentStatus `json:"paymentStatuses,omitempty,brackets"` +} + +// PaymentTypesResponse type +type PaymentTypesResponse struct { + Success bool `json:"success"` + PaymentTypes map[string]PaymentType `json:"paymentTypes,omitempty,brackets"` +} + +// PriceTypesResponse type +type PriceTypesResponse struct { + Success bool `json:"success"` + PriceTypes []PriceType `json:"priceTypes,omitempty,brackets"` +} + +// ProductStatusesResponse type +type ProductStatusesResponse struct { + Success bool `json:"success"` + ProductStatuses map[string]ProductStatus `json:"productStatuses,omitempty,brackets"` +} + +// StatusesResponse type +type StatusesResponse struct { + Success bool `json:"success"` + Statuses map[string]Status `json:"statuses,omitempty,brackets"` +} + +// StatusGroupsResponse type +type StatusGroupsResponse struct { + Success bool `json:"success"` + StatusGroups map[string]StatusGroup `json:"statusGroups,omitempty,brackets"` +} + +// SitesResponse type +type SitesResponse struct { + Success bool `json:"success"` + Sites map[string]Site `json:"sites,omitempty,brackets"` +} + +// StoresResponse type +type StoresResponse struct { + Success bool `json:"success"` + Stores []Store `json:"stores,omitempty,brackets"` +} + +// InventoriesResponse type +type InventoriesResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Offers []Offer `json:"offers,omitempty"` +} + +// StoreUploadResponse type +type StoreUploadResponse struct { + Success bool `json:"success"` + ProcessedOffersCount int `json:"processedOffersCount,omitempty"` + NotFoundOffers []Offer `json:"notFoundOffers,omitempty"` +} + +// ProductsGroupsResponse type +type ProductsGroupsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + ProductGroup []ProductGroup `json:"productGroup,omitempty,brackets"` +} + +// ProductsResponse type +type ProductsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Products []Product `json:"products,omitempty,brackets"` +} + +// ProductsPropertiesResponse type +type ProductsPropertiesResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + Properties []Property `json:"properties,omitempty,brackets"` +} + +// DeliveryShipmentsResponse type +type DeliveryShipmentsResponse struct { + Success bool `json:"success"` + Pagination *Pagination `json:"pagination,omitempty"` + DeliveryShipments []DeliveryShipment `json:"deliveryShipments,omitempty,brackets"` +} + +// DeliveryShipmentResponse type +type DeliveryShipmentResponse struct { + Success bool `json:"success"` + DeliveryShipment *DeliveryShipment `json:"deliveryShipment,omitempty,brackets"` +} + +// DeliveryShipmentUpdateResponse type +type DeliveryShipmentUpdateResponse struct { + Success bool `json:"success"` + Id int `json:"id,omitempty"` + Status string `json:"status,omitempty"` +} + +// IntegrationModuleResponse type +type IntegrationModuleResponse struct { + Success bool `json:"success"` + IntegrationModule *IntegrationModule `json:"integrationModule,omitempty"` +} + +// IntegrationModuleEditResponse type +type IntegrationModuleEditResponse struct { + Success bool `json:"success"` + Info map[string]string `json:"info,omitempty,brackets"` +} diff --git a/v5/types.go b/v5/types.go new file mode 100644 index 0000000..4663dba --- /dev/null +++ b/v5/types.go @@ -0,0 +1,866 @@ +package v5 + +import "net/http" + +// Client type +type Client struct { + Url string + Key string + httpClient *http.Client +} + +// Pagination type +type Pagination struct { + Limit int `json:"limit,omitempty"` + TotalCount int `json:"totalCount,omitempty"` + CurrentPage int `json:"currentPage,omitempty"` + TotalPageCount int `json:"totalPageCount,omitempty"` +} + +// Address type +type Address struct { + Index string `json:"index,omitempty"` + CountryIso string `json:"countryIso,omitempty"` + Region string `json:"region,omitempty"` + RegionId int `json:"regionId,omitempty"` + City string `json:"city,omitempty"` + CityId int `json:"cityId,omitempty"` + CityType string `json:"cityType,omitempty"` + Street string `json:"street,omitempty"` + StreetId int `json:"streetId,omitempty"` + StreetType string `json:"streetType,omitempty"` + Building string `json:"building,omitempty"` + Flat string `json:"flat,omitempty"` + IntercomCode string `json:"intercomCode,omitempty"` + Floor int `json:"floor,omitempty"` + Block int `json:"block,omitempty"` + House string `json:"house,omitempty"` + Metro string `json:"metro,omitempty"` + Notes string `json:"notes,omitempty"` + Text string `json:"text,omitempty"` +} + +// GeoHierarchyRow type +type GeoHierarchyRow struct { + Country string `json:"country,omitempty"` + Region string `json:"region,omitempty"` + RegionId int `json:"regionId,omitempty"` + City string `json:"city,omitempty"` + CityId int `json:"cityId,omitempty"` +} + +// Source type +type Source struct { + Source string `json:"source,omitempty"` + Medium string `json:"medium,omitempty"` + Campaign string `json:"campaign,omitempty"` + Keyword string `json:"keyword,omitempty"` + Content string `json:"content,omitempty"` +} + +// Contragent type +type Contragent struct { + ContragentType string `json:"contragentType,omitempty"` + LegalName string `json:"legalName,omitempty"` + LegalAddress string `json:"legalAddress,omitempty"` + INN string `json:"INN,omitempty"` + OKPO string `json:"OKPO,omitempty"` + KPP string `json:"KPP,omitempty"` + OGRN string `json:"OGRN,omitempty"` + OGRNIP string `json:"OGRNIP,omitempty"` + CertificateNumber string `json:"certificateNumber,omitempty"` + CertificateDate string `json:"certificateDate,omitempty"` + BIK string `json:"BIK,omitempty"` + Bank string `json:"bank,omitempty"` + BankAddress string `json:"bankAddress,omitempty"` + CorrAccount string `json:"corrAccount,omitempty"` + BankAccount string `json:"bankAccount,omitempty"` +} + +// ApiKey type +type ApiKey struct { + Current bool `json:"current,omitempty"` +} + +// Property type +type Property struct { + Code string `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` + Sites []string `json:"Sites,omitempty,brackets"` +} + +// IdentifiersPair type +type IdentifiersPair struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` +} + +// DeliveryTime type +type DeliveryTime struct { + From string `json:"from,omitempty"` + To string `json:"to,omitempty"` + Custom string `json:"custom,omitempty"` +} + +/** +Customer related types +*/ + +// Customer type +type Customer struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Patronymic string `json:"patronymic,omitempty"` + Sex string `json:"sex,omitempty"` + Email string `json:"email,omitempty"` + Phones []Phone `json:"phones,brackets,omitempty"` + Address *Address `json:"address,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Birthday string `json:"birthday,omitempty"` + ManagerId int `json:"managerId,omitempty"` + Vip bool `json:"vip,omitempty"` + Bad bool `json:"bad,omitempty"` + Site string `json:"site,omitempty"` + Source *Source `json:"source,omitempty"` + Contragent *Contragent `json:"contragent,omitempty"` + PersonalDiscount float32 `json:"personalDiscount,omitempty"` + CumulativeDiscount float32 `json:"cumulativeDiscount,omitempty"` + DiscountCardNumber string `json:"discountCardNumber,omitempty"` + EmailMarketingUnsubscribedAt string `json:"emailMarketingUnsubscribedAt,omitempty"` + AvgMarginSumm float32 `json:"avgMarginSumm,omitempty"` + MarginSumm float32 `json:"marginSumm,omitempty"` + TotalSumm float32 `json:"totalSumm,omitempty"` + AverageSumm float32 `json:"averageSumm,omitempty"` + OrdersCount int `json:"ordersCount,omitempty"` + CostSumm float32 `json:"costSumm,omitempty"` + MaturationTime int `json:"maturationTime,omitempty"` + FirstClientId string `json:"firstClientId,omitempty"` + LastClientId string `json:"lastClientId,omitempty"` + BrowserId string `json:"browserId,omitempty"` + CustomFields []map[string]string `json:"customFields,omitempty,brackets"` +} + +// Phone type +type Phone struct { + Number string `json:"number,omitempty"` +} + +// CustomerHistoryRecord type +type CustomerHistoryRecord struct { + Id int `json:"id,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Created bool `json:"created,omitempty"` + Deleted bool `json:"deleted,omitempty"` + Source string `json:"source,omitempty"` + Field string `json:"field,omitempty"` + User *User `json:"user,omitempty,brackets"` + ApiKey *ApiKey `json:"apiKey,omitempty,brackets"` + Customer *Customer `json:"customer,omitempty,brackets"` +} + +/** +Order related types +*/ + +// Order type +type Order struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + Number string `json:"number,omitempty"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Patronymic string `json:"patronymic,omitempty"` + Email string `json:"email,omitempty"` + Phone string `json:"phone,omitempty"` + AdditionalPhone string `json:"additionalPhone,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + StatusUpdatedAt string `json:"statusUpdatedAt,omitempty"` + ManagerId int `json:"managerId,omitempty"` + Mark int `json:"mark,omitempty"` + Call bool `json:"call,omitempty"` + Expired bool `json:"expired,omitempty"` + FromApi bool `json:"fromApi,omitempty"` + MarkDatetime string `json:"markDatetime,omitempty"` + CustomerComment string `json:"customerComment,omitempty"` + ManagerComment string `json:"managerComment,omitempty"` + Status string `json:"status,omitempty"` + StatusComment string `json:"statusComment,omitempty"` + FullPaidAt string `json:"fullPaidAt,omitempty"` + Site string `json:"site,omitempty"` + OrderType string `json:"orderType,omitempty"` + OrderMethod string `json:"orderMethod,omitempty"` + CountryIso string `json:"countryIso,omitempty"` + Summ float32 `json:"summ,omitempty"` + TotalSumm float32 `json:"totalSumm,omitempty"` + PrepaySum float32 `json:"prepaySum,omitempty"` + PurchaseSumm float32 `json:"purchaseSumm,omitempty"` + DiscountManualAmount float32 `json:"discountManualAmount,omitempty"` + DiscountManualPercent float32 `json:"discountManualPercent,omitempty"` + Weight float32 `json:"weight,omitempty"` + Length int `json:"length,omitempty"` + Width int `json:"width,omitempty"` + Height int `json:"height,omitempty"` + ShipmentStore string `json:"shipmentStore,omitempty"` + ShipmentDate string `json:"shipmentDate,omitempty"` + ClientId string `json:"clientId,omitempty"` + Shipped bool `json:"shipped,omitempty"` + UploadedToExternalStoreSystem bool `json:"uploadedToExternalStoreSystem,omitempty"` + Source *Source `json:"source,omitempty"` + Contragent *Contragent `json:"contragent,omitempty"` + Customer *Customer `json:"customer,omitempty"` + Delivery *OrderDelivery `json:"delivery,omitempty"` + Marketplace *OrderMarketplace `json:"marketplace,omitempty"` + Items []OrderItem `json:"items,omitempty,brackets"` + CustomFields []map[string]string `json:"customFields,omitempty,brackets"` + Payments []OrderPayment `json:"payments,omitempty,brackets"` +} + +// OrderDelivery type +type OrderDelivery struct { + Code string `json:"code,omitempty"` + IntegrationCode string `json:"integrationCode,omitempty"` + Cost float32 `json:"cost,omitempty"` + NetCost float32 `json:"netCost,omitempty"` + VatRate string `json:"vatRate,omitempty"` + Date string `json:"date,omitempty"` + Time *OrderDeliveryTime `json:"time,omitempty"` + Address *Address `json:"address,omitempty"` + Service *OrderDeliveryService `json:"service,omitempty"` + Data *OrderDeliveryData `json:"data,omitempty"` +} + +// OrderDeliveryTime type +type OrderDeliveryTime struct { + From string `json:"from,omitempty"` + To string `json:"to,omitempty"` + Custom string `json:"custom,omitempty"` +} + +// OrderDeliveryService type +type OrderDeliveryService struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` +} + +// OrderDeliveryData type +type OrderDeliveryData struct { + TrackNumber string `json:"trackNumber,omitempty"` + Status string `json:"status,omitempty"` + PickuppointAddress string `json:"pickuppointAddress,omitempty"` + PayerType string `json:"payerType,omitempty"` +} + +// OrderMarketplace type +type OrderMarketplace struct { + Code string `json:"code,omitempty"` + OrderId string `json:"orderId,omitempty"` +} + +// OrderPayment type +type OrderPayment struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + Type string `json:"type,omitempty"` + Status string `json:"status,omitempty"` + PaidAt string `json:"paidAt,omitempty"` + Amount float32 `json:"amount,omitempty"` + Comment string `json:"comment,omitempty"` +} + +// OrderItem type +type OrderItem struct { + Id int `json:"id,omitempty"` + InitialPrice float32 `json:"initialPrice,omitempty"` + PurchasePrice float32 `json:"purchasePrice,omitempty"` + DiscountTotal float32 `json:"discountTotal,omitempty"` + DiscountManualAmount float32 `json:"discountManualAmount,omitempty"` + DiscountManualPercent float32 `json:"discountManualPercent,omitempty"` + ProductName string `json:"productName,omitempty"` + VatRate string `json:"vatRate,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Quantity float32 `json:"quantity,omitempty"` + Status string `json:"status,omitempty"` + Comment string `json:"comment,omitempty"` + IsCanceled bool `json:"isCanceled,omitempty"` + Offer Offer `json:"offer,omitempty"` + Properties []Property `json:"properties,omitempty,brackets"` + PriceType *PriceType `json:"priceType,omitempty"` +} + +// OrdersHistoryRecord type +type OrdersHistoryRecord struct { + Id int `json:"id,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Created bool `json:"created,omitempty"` + Deleted bool `json:"deleted,omitempty"` + Source string `json:"source,omitempty"` + Field string `json:"field,omitempty"` + User *User `json:"user,omitempty,brackets"` + ApiKey *ApiKey `json:"apiKey,omitempty,brackets"` + Order *Order `json:"order,omitempty,brackets"` +} + +// Pack type +type Pack struct { + Id int `json:"id,omitempty"` + PurchasePrice float32 `json:"purchasePrice,omitempty"` + Quantity float32 `json:"quantity,omitempty"` + Store string `json:"store,omitempty"` + ShipmentDate string `json:"shipmentDate,omitempty"` + InvoiceNumber string `json:"invoiceNumber,omitempty"` + DeliveryNoteNumber string `json:"deliveryNoteNumber,omitempty"` + Item *PackItem `json:"item,omitempty"` + ItemId int `json:"itemId,omitempty"` +} + +// PackItem type +type PackItem struct { + Id int `json:"id,omitempty"` + Order *Order `json:"order,omitempty"` + Offer *Offer `json:"offer,omitempty"` +} + +// PacksHistoryRecord type +type PacksHistoryRecord struct { + Id int `json:"id,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Created bool `json:"created,omitempty"` + Deleted bool `json:"deleted,omitempty"` + Source string `json:"source,omitempty"` + Field string `json:"field,omitempty"` + User *User `json:"user,omitempty,brackets"` + Pack *Pack `json:"pack,omitempty,brackets"` +} + +// Offer type +type Offer struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + Name string `json:"name,omitempty"` + XmlId string `json:"xmlId,omitempty"` + Article string `json:"article,omitempty"` + VatRate string `json:"vatRate,omitempty"` + Price float32 `json:"price,omitempty"` + PurchasePrice float32 `json:"purchasePrice,omitempty"` + Quantity float32 `json:"quantity,omitempty"` + Height float32 `json:"height,omitempty"` + Width float32 `json:"width,omitempty"` + Length float32 `json:"length,omitempty"` + Weight float32 `json:"weight,omitempty"` + Stores []Inventory `json:"stores,omitempty,brackets"` + Properties map[string]string `json:"properties,omitempty,brackets"` + Prices []OfferPrice `json:"prices,omitempty,brackets"` + Images []string `json:"images,omitempty,brackets"` +} + +// Inventory type +type Inventory struct { + PurchasePrice float32 `json:"purchasePrice,omitempty"` + Quantity float32 `json:"quantity,omitempty"` + Store string `json:"store,omitempty"` +} + +// InventoryUpload type +type InventoryUpload struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + XmlId string `json:"xmlId,omitempty"` + Stores []InventoryUploadStore `json:"stores,omitempty"` +} + +// InventoryUploadStore type +type InventoryUploadStore struct { + PurchasePrice float32 `json:"purchasePrice,omitempty"` + Available float32 `json:"available,omitempty"` + Code string `json:"code,omitempty"` +} + +// OfferPrice type +type OfferPrice struct { + Price float32 `json:"price,omitempty"` + Ordering int `json:"ordering,omitempty"` + PriceType string `json:"priceType,omitempty"` +} + +// OfferPriceUpload type +type OfferPriceUpload struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + XmlId string `json:"xmlId,omitempty"` + Site string `json:"site,omitempty"` + Prices []PriceUpload `json:"prices,omitempty"` +} + +// PriceUpload type +type PriceUpload struct { + Code string `json:"code,omitempty"` + Price float32 `json:"price,omitempty"` +} + +/** +User related types +*/ + +// User type +type User struct { + Id int `json:"id,omitempty"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Patronymic string `json:"patronymic,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Active bool `json:"active,omitempty"` + Online bool `json:"online,omitempty"` + IsAdmin bool `json:"isAdmin,omitempty"` + IsManager bool `json:"isManager,omitempty"` + Email string `json:"email,omitempty"` + Phone string `json:"phone,omitempty"` + Status string `json:"status,omitempty"` + Groups []UserGroup `json:"groups,omitempty,brackets"` +} + +// UserGroup type +type UserGroup struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + SignatureTemplate string `json:"signatureTemplate,omitempty"` + IsManager bool `json:"isManager,omitempty"` + IsDeliveryMen bool `json:"isDeliveryMen,omitempty"` + DeliveryTypes []string `json:"deliveryTypes,omitempty,brackets"` + BreakdownOrderTypes []string `json:"breakdownOrderTypes,omitempty,brackets"` + BreakdownSites []string `json:"breakdownSites,omitempty,brackets"` + BreakdownOrderMethods []string `json:"breakdownOrderMethods,omitempty,brackets"` + GrantedOrderTypes []string `json:"grantedOrderTypes,omitempty,brackets"` + GrantedSites []string `json:"grantedSites,omitempty,brackets"` +} + +/** +Task related types +*/ + +// Task type +type Task struct { + Id int `json:"id,omitempty"` + PerformerId int `json:"performerId,omitempty"` + Text string `json:"text,omitempty"` + Commentary string `json:"commentary,omitempty"` + Datetime string `json:"datetime,omitempty"` + Complete bool `json:"complete,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Creator int `json:"creator,omitempty"` + Performer int `json:"performer,omitempty"` + Phone string `json:"phone,omitempty"` + PhoneSite string `json:"phoneSite,omitempty"` + Customer *Customer `json:"customer,omitempty"` + Order *Order `json:"order,omitempty"` +} + +/* + Notes related types +*/ + +// Note type +type Note struct { + Id int `json:"id,omitempty"` + ManagerId int `json:"managerId,omitempty"` + Text string `json:"text,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + Customer *Customer `json:"customer,omitempty"` +} + +/* + Payments related types +*/ + +// Payment type +type Payment struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + PaidAt string `json:"paidAt,omitempty"` + Amount float32 `json:"amount,omitempty"` + Comment string `json:"comment,omitempty"` + Status string `json:"status,omitempty"` + Type string `json:"type,omitempty"` + Order *Order `json:"order,omitempty"` +} + +/* + Segment related types +*/ + +// Segment type +type Segment struct { + Id int `json:"id,omitempty"` + Code string `json:"code,omitempty"` + Name string `json:"name,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + CustomersCount int `json:"customersCount,omitempty"` + IsDynamic bool `json:"isDynamic,omitempty"` + Active bool `json:"active,omitempty"` +} + +/** +Reference related types +*/ + +// CostGroup type +type CostGroup struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Color string `json:"color,omitempty"` + Active bool `json:"active,omitempty"` + Ordering int `json:"ordering,omitempty"` +} + +// CostItem type +type CostItem struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Group string `json:"group,omitempty"` + Type string `json:"type,omitempty"` + Active bool `json:"active,omitempty"` + AppliesToOrders bool `json:"appliesToOrders,omitempty"` + AppliesToUsers bool `json:"appliesToUsers,omitempty"` + Ordering int `json:"ordering,omitempty"` + Source *Source `json:"source,omitempty"` +} + +// Courier type +type Courier struct { + Id int `json:"id,omitempty"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Patronymic string `json:"patronymic,omitempty"` + Email string `json:"email,omitempty"` + Description string `json:"description,omitempty"` + Active bool `json:"active,omitempty"` + Phone *Phone `json:"phone,omitempty"` +} + +// DeliveryService type +type DeliveryService struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` +} + +// DeliveryType type +type DeliveryType struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + DefaultCost float32 `json:"defaultCost,omitempty"` + DefaultNetCost float32 `json:"defaultNetCost,omitempty"` + Description string `json:"description,omitempty"` + IntegrationCode string `json:"integrationCode,omitempty"` + VatRate string `json:"vatRate,omitempty"` + DefaultForCrm bool `json:"defaultForCrm,omitempty"` + DeliveryServices []string `json:"deliveryServices,omitempty"` + PaymentTypes []string `json:"paymentTypes,omitempty"` +} + +// LegalEntity type +type LegalEntity struct { + Code string `json:"code,omitempty"` + VatRate string `json:"vatRate,omitempty"` + CountryIso string `json:"countryIso,omitempty"` + ContragentType string `json:"contragentType,omitempty"` + LegalName string `json:"legalName,omitempty"` + LegalAddress string `json:"legalAddress,omitempty"` + INN string `json:"INN,omitempty"` + OKPO string `json:"OKPO,omitempty"` + KPP string `json:"KPP,omitempty"` + OGRN string `json:"OGRN,omitempty"` + OGRNIP string `json:"OGRNIP,omitempty"` + CertificateNumber string `json:"certificateNumber,omitempty"` + CertificateDate string `json:"certificateDate,omitempty"` + BIK string `json:"BIK,omitempty"` + Bank string `json:"bank,omitempty"` + BankAddress string `json:"bankAddress,omitempty"` + CorrAccount string `json:"corrAccount,omitempty"` + BankAccount string `json:"bankAccount,omitempty"` +} + +// OrderMethod type +type OrderMethod struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + DefaultForCrm bool `json:"defaultForCrm,omitempty"` + DefaultForApi bool `json:"defaultForApi,omitempty"` +} + +// OrderType type +type OrderType struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + DefaultForCrm bool `json:"defaultForCrm,omitempty"` + DefaultForApi bool `json:"defaultForApi,omitempty"` +} + +// PaymentStatus type +type PaymentStatus struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + DefaultForCrm bool `json:"defaultForCrm,omitempty"` + DefaultForApi bool `json:"defaultForApi,omitempty"` + PaymentComplete bool `json:"paymentComplete,omitempty"` + Description string `json:"description,omitempty"` + Ordering int `json:"ordering,omitempty"` + PaymentTypes []string `json:"paymentTypes,omitempty,brackets"` +} + +// PaymentType type +type PaymentType struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + DefaultForCrm bool `json:"defaultForCrm,omitempty"` + DefaultForApi bool `json:"defaultForApi,omitempty"` + Description string `json:"description,omitempty"` + DeliveryTypes []string `json:"deliveryTypes,omitempty,brackets"` + PaymentStatuses []string `json:"PaymentStatuses,omitempty,brackets"` +} + +// PriceType type +type PriceType struct { + Id int `json:"id,omitempty"` + Code string `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Active bool `json:"active,omitempty"` + Default bool `json:"default,omitempty"` + Description string `json:"description,omitempty"` + FilterExpression string `json:"filterExpression,omitempty"` + Ordering int `json:"ordering,omitempty"` + Groups []string `json:"groups,omitempty,brackets"` + Geo []GeoHierarchyRow `json:"geo,omitempty,brackets"` +} + +// ProductStatus type +type ProductStatus struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + Ordering int `json:"ordering,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + CancelStatus bool `json:"cancelStatus,omitempty"` + OrderStatusByProductStatus string `json:"orderStatusByProductStatus,omitempty"` + OrderStatusForProductStatus string `json:"orderStatusForProductStatus,omitempty"` +} + +// Status type +type Status struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + Ordering int `json:"ordering,omitempty"` + Group string `json:"group,omitempty"` +} + +// StatusGroup type +type StatusGroup struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` + Ordering int `json:"ordering,omitempty"` + Process bool `json:"process,omitempty"` + Statuses []string `json:"statuses,omitempty,brackets"` +} + +// Site type +type Site struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Url string `json:"url,omitempty"` + Description string `json:"description,omitempty"` + Phones string `json:"phones,omitempty"` + Zip string `json:"zip,omitempty"` + Address string `json:"address,omitempty"` + CountryIso string `json:"countryIso,omitempty"` + YmlUrl string `json:"ymlUrl,omitempty"` + LoadFromYml bool `json:"loadFromYml,omitempty"` + CatalogUpdatedAt string `json:"catalogUpdatedAt,omitempty"` + CatalogLoadingAt string `json:"catalogLoadingAt,omitempty"` + Contragent *LegalEntity `json:"contragent,omitempty"` +} + +// Store type +type Store struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + ExternalId string `json:"externalId,omitempty"` + Description string `json:"description,omitempty"` + XmlId string `json:"xmlId,omitempty"` + Email string `json:"email,omitempty"` + Type string `json:"type,omitempty"` + InventoryType string `json:"inventoryType,omitempty"` + Active bool `json:"active,omitempty"` + Phone *Phone `json:"phone,omitempty"` + Address *Address `json:"address,omitempty"` +} + +// ProductGroup type +type ProductGroup struct { + Id int `json:"id,omitempty"` + ParentId int `json:"parentId,omitempty"` + Name string `json:"name,omitempty"` + Site string `json:"site,omitempty"` + Active bool `json:"active,omitempty"` +} + +// Product type +type Product struct { + Id int `json:"id,omitempty"` + MaxPrice float32 `json:"maxPrice,omitempty"` + MinPrice float32 `json:"minPrice,omitempty"` + Name string `json:"name,omitempty"` + Url string `json:"url,omitempty"` + Article string `json:"article,omitempty"` + ExternalId string `json:"externalId,omitempty"` + Manufacturer string `json:"manufacturer,omitempty"` + ImageUrl string `json:"imageUrl,omitempty"` + Description string `json:"description,omitempty"` + Popular bool `json:"popular,omitempty"` + Stock bool `json:"stock,omitempty"` + Novelty bool `json:"novelty,omitempty"` + Recommended bool `json:"recommended,omitempty"` + Active bool `json:"active,omitempty"` + Quantity float32 `json:"quantity,omitempty"` + Offers []Offer `json:"offers,omitempty,brackets"` + Groups []ProductGroup `json:"groups,omitempty,brackets"` + Properties map[string]string `json:"properties,omitempty,brackets"` +} + +// DeliveryHistoryRecord type +type DeliveryHistoryRecord struct { + Code string `json:"code,omitempty"` + UpdatedAt string `json:"updatedAt,omitempty"` + Comment string `json:"comment,omitempty"` +} + +// DeliveryShipment type +type DeliveryShipment struct { + IntegrationCode string `json:"integrationCode,omitempty"` + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + DeliveryType string `json:"deliveryType,omitempty"` + Store string `json:"store,omitempty"` + ManagerId int `json:"managerId,omitempty"` + Status string `json:"status,omitempty"` + Date string `json:"date,omitempty"` + Time *DeliveryTime `json:"time,omitempty"` + LunchTime string `json:"lunchTime,omitempty"` + Comment string `json:"comment,omitempty"` + Orders []Order `json:"orders,omitempty,brackets"` + ExtraData map[string]string `json:"extraData,omitempty,brackets"` +} + +// IntegrationModule type +type IntegrationModule struct { + Code string `json:"code,omitempty"` + IntegrationCode string `json:"integrationCode,omitempty"` + Active bool `json:"active,omitempty"` + Freeze bool `json:"freeze,omitempty"` + Native bool `json:"native,omitempty"` + Name string `json:"name,omitempty"` + Logo string `json:"logo,omitempty"` + ClientId string `json:"clientId,omitempty"` + BaseUrl string `json:"baseUrl,omitempty"` + AccountUrl string `json:"accountUrl,omitempty"` + AvailableCountries []string `json:"availableCountries,omitempty"` + Actions []string `json:"actions,omitempty"` + Integrations *Integrations `json:"integrations,omitempty"` +} + +// Integrations type +type Integrations struct { + Telephony *Telephony `json:"telephony,omitempty"` + Delivery *Delivery `json:"delivery,omitempty"` + Store *Warehouse `json:"store,omitempty"` +} + +// Delivery type +type Delivery struct { + Description string `json:"description,omitempty"` + Actions []Action `json:"actions,omitempty,brackets"` + PayerType []string `json:"payerType,omitempty,brackets"` + PlatePrintLimit int `json:"platePrintLimit,omitempty"` + RateDeliveryCost bool `json:"rateDeliveryCost,omitempty"` + AllowPackages bool `json:"allowPackages,omitempty"` + CodAvailable bool `json:"codAvailable,omitempty"` + SelfShipmentAvailable bool `json:"selfShipmentAvailable,omitempty"` + AllowTrackNumber bool `json:"allowTrackNumber,omitempty"` + AvailableCountries []string `json:"availableCountries,omitempty"` + RequiredFields []string `json:"requiredFields,omitempty"` + StatusList []DeliveryStatus `json:"statusList,omitempty"` + PlateList []Plate `json:"plateList,omitempty"` + DeliveryDataFieldList []DeliveryDataField `json:"deliveryDataFieldList,omitempty"` + ShipmentDataFieldList []DeliveryDataField `json:"shipmentDataFieldList,omitempty"` +} + +// DeliveryStatus type +type DeliveryStatus struct { + Code string `json:"code,omitempty"` + Name string `json:"name,omitempty"` + IsEditable bool `json:"isEditable,omitempty"` +} + +// Plate type +type Plate struct { + Code string `json:"code,omitempty"` + Label string `json:"label,omitempty"` +} + +// DeliveryDataField type +type DeliveryDataField struct { + Code string `json:"code,omitempty"` + Label string `json:"label,omitempty"` + Hint string `json:"hint,omitempty"` + Type string `json:"type,omitempty"` + AutocompleteUrl string `json:"autocompleteUrl,omitempty"` + Multiple bool `json:"multiple,omitempty"` + Required bool `json:"required,omitempty"` + AffectsCost bool `json:"affectsCost,omitempty"` + Editable bool `json:"editable,omitempty"` +} + +// Telephony type +type Telephony struct { + MakeCallUrl string `json:"makeCallUrl,omitempty"` + AllowEdit bool `json:"allowEdit,omitempty"` + InputEventSupported bool `json:"inputEventSupported,omitempty"` + OutputEventSupported bool `json:"outputEventSupported,omitempty"` + HangupEventSupported bool `json:"hangupEventSupported,omitempty"` + ChangeUserStatusUrl string `json:"changeUserStatusUrl,omitempty"` + AdditionalCodes []AdditionalCode `json:"additionalCodes,omitempty,brackets"` + ExternalPhones []ExternalPhone `json:"externalPhones,omitempty,brackets"` +} + +// AdditionalCode type +type AdditionalCode struct { + Code string `json:"code,omitempty"` + UserId string `json:"userId,omitempty"` +} + +// ExternalPhone type +type ExternalPhone struct { + SiteCode string `json:"siteCode,omitempty"` + ExternalPhone string `json:"externalPhone,omitempty"` +} + +// Warehouse type +type Warehouse struct { + Actions []Action `json:"actions,omitempty,brackets"` +} + +// Action type +type Action struct { + Code string `json:"code,omitempty"` + Url string `json:"url,omitempty"` + CallPoints []string `json:"callPoints,omitempty"` +}