diff --git a/v5/client.go b/v5/client.go index c877619..ee1b717 100644 --- a/v5/client.go +++ b/v5/client.go @@ -7,8 +7,11 @@ import ( "io/ioutil" "net/http" "net/url" + "strconv" "strings" "time" + + "github.com/google/go-querystring/query" ) const ( @@ -95,14 +98,6 @@ func buildRawResponse(resp *http.Response) ([]byte, error) { return res, nil } -// ErrorResponse method -func (c *Client) ErrorResponse(data []byte) (*ErrorResponse, error) { - var resp ErrorResponse - err := json.Unmarshal(data, &resp) - - return &resp, err -} - // checkBy select identifier type func checkBy(by string) string { var context = "id" @@ -113,3 +108,237 @@ func checkBy(by string) string { return context } + +// ApiVersions get available API versions +func (c *Client) ApiVersions() (*VersionResponse, int, error) { + var resp VersionResponse + data, status, err := c.GetRequest(fmt.Sprintf("%s/api-versions", unversionedPrefix)) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// ApiCredentials get available API methods +func (c *Client) ApiCredentials() (*CredentialResponse, int, error) { + var resp CredentialResponse + data, status, err := c.GetRequest(fmt.Sprintf("%s/credentials", unversionedPrefix)) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Customer get method +func (c *Client) Customer(id, by, site string) (*CustomerResponse, int, error) { + 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 != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Customers list method +func (c *Client) Customers(parameters CustomersRequest) (*CustomersResponse, int, error) { + var resp CustomersResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers?%s", versionedPrefix, params.Encode())) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomerCreate method +func (c *Client) CustomerCreate(customer Customer, site ...string) (*CustomerChangeResponse, int, error) { + var resp CustomerChangeResponse + customerJson, _ := json.Marshal(&customer) + + p := url.Values{ + "customer": {string(customerJson[:])}, + } + + if len(site) > 0 { + s := site[0] + + if s != "" { + p.Add("site", s) + } + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/create", versionedPrefix), p) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomerEdit method +func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (*CustomerChangeResponse, int, error) { + 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[:])}, + } + + if len(site) > 0 { + s := site[0] + + if s != "" { + p.Add("site", s) + } + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/%s/edit", versionedPrefix, uid), p) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersUpload method +func (c *Client) CustomersUpload(customers []Customer, site ...string) (*CustomersUploadResponse, int, error) { + var resp CustomersUploadResponse + + uploadJson, _ := json.Marshal(&customers) + + p := url.Values{ + "customers": {string(uploadJson[:])}, + } + + if len(site) > 0 { + s := site[0] + + if s != "" { + p.Add("site", s) + } + } + + data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/upload", versionedPrefix), p) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersFixExternalIds method +func (c *Client) CustomersFixExternalIds(customers []CustomerIdentifiers) (*SucessfulResponse, int, error) { + 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 != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// CustomersHistory method +func (c *Client) CustomersHistory(parameters CustomersHistoryRequest) (*CustomersHistoryResponse, int, error) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/history?%s", versionedPrefix, params.Encode())) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Order get method +func (c *Client) Order(id, by, site string) (*OrderResponse, int, error) { + 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 != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// Orders list method +func (c *Client) Orders(parameters OrdersRequest) (*OrdersResponse, int, error) { + var resp OrdersResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/orders?%s", versionedPrefix, params.Encode())) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} + +// OrdersHistory method +func (c *Client) OrdersHistory(parameters OrdersHistoryRequest) (*CustomersHistoryResponse, int, error) { + var resp CustomersHistoryResponse + + params, _ := query.Values(parameters) + + data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/history?%s", versionedPrefix, params.Encode())) + if err != nil { + return &resp, status, err + } + + err = json.Unmarshal(data, &resp) + + return &resp, status, err +} diff --git a/v5/filters.go b/v5/filters.go new file mode 100644 index 0000000..233a8f9 --- /dev/null +++ b/v5/filters.go @@ -0,0 +1,166 @@ +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 string `url:"minOrdersCount,omitempty"` + MaxOrdersCount string `url:"maxOrdersCount,omitempty"` + MinAverageSumm string `url:"minAverageSumm,omitempty"` + MaxAverageSumm string `url:"maxAverageSumm,omitempty"` + MinTotalSumm string `url:"minTotalSumm,omitempty"` + MaxTotalSumm string `url:"maxTotalSumm,omitempty"` + MinCostSumm string `url:"minCostSumm,omitempty"` + MaxCostSumm string `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 []string `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"` +} diff --git a/v5/methods_api.go b/v5/methods_api.go deleted file mode 100644 index 05054c0..0000000 --- a/v5/methods_api.go +++ /dev/null @@ -1,32 +0,0 @@ -package v5 - -import ( - "encoding/json" - "fmt" -) - -// ApiVersions get available API versions -func (c *Client) ApiVersions() (*VersionResponse, int, error) { - var resp VersionResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/api-versions", unversionedPrefix)) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// ApiCredentials get available API methods -func (c *Client) ApiCredentials() (*CredentialResponse, int, error) { - var resp CredentialResponse - data, status, err := c.GetRequest(fmt.Sprintf("%s/credentials", unversionedPrefix)) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} diff --git a/v5/methods_customers.go b/v5/methods_customers.go deleted file mode 100644 index 9b57f12..0000000 --- a/v5/methods_customers.go +++ /dev/null @@ -1,187 +0,0 @@ -package v5 - -import ( - "encoding/json" - "fmt" - "net/url" - "strconv" - - "github.com/google/go-querystring/query" -) - -// Customer get method -func (c *Client) Customer(id, by, site string) (*CustomerResponse, int, error) { - var resp CustomerResponse - var context = checkBy(by) - - fw := CustomerFilter{context, site} - params, _ := query.Values(fw) - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/%s?%s", versionedPrefix, id, params.Encode())) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// Customers list method -func (c *Client) Customers(filter CustomersFilter, limit, page int) (*CustomersResponse, int, error) { - var resp CustomersResponse - - if limit == 0 { - limit = 20 - } - - if page == 0 { - page = 1 - } - - fw := CustomersParameters{filter, limit, page} - params, _ := query.Values(fw) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers?%s", versionedPrefix, params.Encode())) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// CustomerCreate method -func (c *Client) CustomerCreate(customer Customer, site ...string) (*CustomerChangeResponse, int, error) { - var resp CustomerChangeResponse - customerJson, _ := json.Marshal(&customer) - - p := url.Values{ - "customer": {string(customerJson[:])}, - } - - if len(site) > 0 { - s := site[0] - - if s != "" { - p.Add("site", s) - } - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/create", versionedPrefix), p) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// CustomerEdit method -func (c *Client) CustomerEdit(customer Customer, by string, site ...string) (*CustomerChangeResponse, int, error) { - 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[:])}, - } - - if len(site) > 0 { - s := site[0] - - if s != "" { - p.Add("site", s) - } - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/%s/edit", versionedPrefix, uid), p) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// CustomersUpload method -func (c *Client) CustomersUpload(customers []Customer, site ...string) (*CustomersUploadResponse, int, error) { - var resp CustomersUploadResponse - - uploadJson, _ := json.Marshal(&customers) - - p := url.Values{ - "customers": {string(uploadJson[:])}, - } - - if len(site) > 0 { - s := site[0] - - if s != "" { - p.Add("site", s) - } - } - - data, status, err := c.PostRequest(fmt.Sprintf("%s/customers/upload", versionedPrefix), p) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// CustomersFixExternalIds method -func (c *Client) CustomersFixExternalIds(customers []CustomerIdentifiers) (*SucessfulResponse, int, error) { - 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 != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} - -// CustomersHistory method -func (c *Client) CustomersHistory(filter CustomersHistoryFilter, limit, page int) (*CustomersHistoryResponse, int, error) { - var resp CustomersHistoryResponse - - if limit == 0 { - limit = 20 - } - - if page == 0 { - page = 1 - } - - fw := CustomersHistoryParameters{filter, limit, page} - params, _ := query.Values(fw) - - data, status, err := c.GetRequest(fmt.Sprintf("%s/customers/history?%s", versionedPrefix, params.Encode())) - if err != nil { - return &resp, status, err - } - - err = json.Unmarshal(data, &resp) - - return &resp, status, err -} diff --git a/v5/methods_orders.go b/v5/methods_orders.go deleted file mode 100644 index 985a541..0000000 --- a/v5/methods_orders.go +++ /dev/null @@ -1 +0,0 @@ -package v5 diff --git a/v5/request.go b/v5/request.go new file mode 100644 index 0000000..915ce69 --- /dev/null +++ b/v5/request.go @@ -0,0 +1,53 @@ +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"` +} + +// CustomersUploadRequest type +type OrdersUploadRequest struct { + Customers []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"` +} diff --git a/v5/response.go b/v5/response.go new file mode 100644 index 0000000..1e556e7 --- /dev/null +++ b/v5/response.go @@ -0,0 +1,91 @@ +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"` +} + +// 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 []CustomerIdentifiers `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"` +} + +// 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"` +} diff --git a/v5/types.go b/v5/types.go new file mode 100644 index 0000000..52066a8 --- /dev/null +++ b/v5/types.go @@ -0,0 +1,294 @@ +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"` +} + +// 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"` +} + +type ApiKey struct { + Current bool `json:"current,omitempty"` +} + +type Property struct { + Code string `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` +} + +// 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 []CustomerPhone `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"` +} + +// CustomerPhone type +type CustomerPhone struct { + Number string `json:"number,omitempty"` +} + +// CustomerIdentifiers type +type CustomerIdentifiers struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,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 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"` +} + +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"` +} + +type OrderDeliveryTime struct { + From string `json:"from,omitempty"` + To string `json:"to,omitempty"` + Custom string `json:"custom,omitempty"` +} + +type OrderDeliveryService struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Active bool `json:"active,omitempty"` +} + +type OrderDeliveryData struct { + TrackNumber string `json:"trackNumber,omitempty"` + Status string `json:"status,omitempty"` + PickuppointAddress string `json:"pickuppointAddress,omitempty"` + PayerType string `json:"payerType,omitempty"` +} + +type OrderMarketplace struct { + Code string `json:"code,omitempty"` + OrderId string `json:"orderId,omitempty"` +} + +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"` +} + +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"` +} + +type Offer struct { + Id int `json:"id,omitempty"` + ExternalId string `json:"externalId,omitempty"` + XmlId string `json:"xmlId,omitempty"` + VatRate string `json:"vatRate,omitempty"` +} + +type User struct { + Id int `json:"id,omitempty"` + FirstName string `json:"firstName,omitempty"` + LastName string `json:"lastName,omitempty"` + Patronymic string `json:"patronymic,omitempty"` +} + +type PriceType struct { + Name string `json:"name,omitempty"` + Code string `json:"code,omitempty"` + Description string `json:"description,omitempty"` + FilterExpression string `json:"filterExpression,omitempty"` + Active bool `json:"active,omitempty"` + Ordering int `json:"ordering,omitempty"` +} diff --git a/v5/types_common.go b/v5/types_common.go deleted file mode 100644 index 4a1a90f..0000000 --- a/v5/types_common.go +++ /dev/null @@ -1,102 +0,0 @@ -package v5 - -import "net/http" - -// Client type -type Client struct { - Url string - Key string - httpClient *http.Client -} - -// ErrorResponse type -type ErrorResponse struct { - ErrorMsg string `json:"errorMsg,omitempty"` - Errors map[string]string `json:"errors,omitempty"` -} - -// SucessfulResponse type -type SucessfulResponse struct { - Success bool `json:"success,omitempty"` -} - -// 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"` -} - -// 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"` -} - -// 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"` -} - -type ApiKey struct { - Current bool `json:"current,omitempty"` -} - -type User struct { - Id int `json:"id,omitempty"` -} diff --git a/v5/types_customers.go b/v5/types_customers.go deleted file mode 100644 index 3486e48..0000000 --- a/v5/types_customers.go +++ /dev/null @@ -1,126 +0,0 @@ -package v5 - -// 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 []CustomerPhone `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"` - //CustomFields map[string]string `json:"customFields,omitempty"` -} - -// CustomerPhone type -type CustomerPhone struct { - Number string `json:"number,omitempty"` -} - -// CustomerIdentifiers type -type CustomerIdentifiers struct { - Id int `json:"id,omitempty"` - ExternalId string `json:"externalId,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"` -} - -// CustomerFilter for get customer request -type CustomerFilter struct { - By string `url:"by,omitempty"` - Site string `url:"site,omitempty"` -} - -// CustomerResponse type -type CustomerResponse struct { - Success bool `json:"success"` - Customer *Customer `json:"customer,omitempty,brackets"` -} - -type CustomersFilter struct { - ExternalIds []string `url:"externalIds,omitempty,brackets"` - City string `url:"city,omitempty"` -} - -type CustomersParameters struct { - Filter CustomersFilter `url:"filter,omitempty"` - Limit int `url:"limit,omitempty"` - Page int `url:"page,omitempty"` -} - -type CustomersResponse struct { - Success bool `json:"success"` - Pagination *Pagination `json:"pagination,omitempty"` - Customers []Customer `json:"customers,omitempty,brackets"` -} - -type CustomerChangeResponse struct { - Success bool `json:"success"` - Id int `json:"id,omitempty"` - State string `json:"state,omitempty"` -} - -type CustomersUploadParameters struct { - Customers []Customer `url:"customers,omitempty,brackets"` - Site string `url:"site,omitempty"` -} - -type CustomersUploadResponse struct { - Success bool `json:"success"` - UploadedCustomers []CustomerIdentifiers `json:"uploadedCustomers,omitempty,brackets"` -} - -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"` -} - -type CustomersHistoryParameters struct { - Filter CustomersHistoryFilter `url:"filter,omitempty"` - Limit int `url:"limit,omitempty"` - Page int `url:"page,omitempty"` -} - -type CustomersHistoryResponse struct { - Success bool `json:"success,omitempty"` - GeneratedAt string `json:"generatedAt,omitempty"` - History []CustomerHistoryRecord `json:"history,omitempty,brackets"` - Pagination *Pagination `json:"pagination,omitempty"` -} diff --git a/v5/types_orders.go b/v5/types_orders.go deleted file mode 100644 index e477acb..0000000 --- a/v5/types_orders.go +++ /dev/null @@ -1,52 +0,0 @@ -package v5 - -// 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"` - 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"` - Payments []OrderPayments `json:"payments,omitempty"` -} diff --git a/v5_tests/customers_test.go b/v5_tests/customers_test.go index 61418c4..6e2f1d1 100644 --- a/v5_tests/customers_test.go +++ b/v5_tests/customers_test.go @@ -4,17 +4,20 @@ import ( "fmt" "net/http" "testing" - "time" "github.com/retailcrm/api-client-go/v5" ) func TestClient_CustomersCustomers(t *testing.T) { c := client() - f := v5.CustomersFilter{} - f.City = "Москва" + f := v5.CustomersRequest{ + Filter: v5.CustomersFilter{ + City: "Москва", + }, + Page: 3, + } - data, status, err := c.Customers(f, 20, 1) + data, status, err := c.Customers(f) if err != nil { t.Errorf("%s", err) t.Fail() @@ -33,15 +36,16 @@ func TestClient_CustomersCustomers(t *testing.T) { func TestClient_CustomerChange(t *testing.T) { c := client() - f := v5.Customer{} random := RandomString(8) - f.FirstName = "Понтелей" - f.LastName = "Турбин" - f.Patronymic = "Аристархович" - f.ExternalId = random - f.Email = fmt.Sprintf("%s@example.com", random) + f := v5.Customer{ + FirstName: "Понтелей", + LastName: "Турбин", + Patronymic: "Аристархович", + ExternalId: random, + Email: fmt.Sprintf("%s@example.com", random), + } cr, sc, err := c.CustomerCreate(f) if err != nil { @@ -179,10 +183,13 @@ func TestClient_CustomersFixExternalIds(t *testing.T) { func TestClient_CustomersHistory(t *testing.T) { c := client() - f := v5.CustomersHistoryFilter{} - f.StartDate = time.Now().Add(-96 * time.Hour).Format("2006-01-02 15:04:05") + f := v5.CustomersHistoryRequest{ + Filter: v5.CustomersHistoryFilter{ + SinceId: 100, + }, + } - data, status, err := c.CustomersHistory(f, 20, 1) + data, status, err := c.CustomersHistory(f) if err != nil { t.Errorf("%s", err) t.Fail() diff --git a/v5_tests/orders_test.go b/v5_tests/orders_test.go new file mode 100644 index 0000000..8979636 --- /dev/null +++ b/v5_tests/orders_test.go @@ -0,0 +1,84 @@ +package v5_tests + +import ( + "net/http" + "testing" + + "github.com/retailcrm/api-client-go/v5" +) + +func TestClient_OrdersOrders(t *testing.T) { + c := client() + f := v5.OrdersRequest{ + Filter: v5.OrdersFilter{ + City: "Москва", + }, + Page: 1, + } + + data, status, err := c.Orders(f) + if err != nil { + t.Errorf("%s", err) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%s", err) + t.Fail() + } + + if data.Success != true { + t.Errorf("%s", err) + t.Fail() + } +} + +func TestClient_OrdersOrder(t *testing.T) { + c := client() + + data, status, err := c.Order("upload-b-1480333204", "externalId", "") + if err != nil { + t.Errorf("%s", err) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%s", err) + t.Fail() + } + + if data.Success != true { + t.Errorf("%s", err) + t.Fail() + } +} + +func TestClient_OrdersHistory(t *testing.T) { + c := client() + f := v5.OrdersHistoryRequest{ + Filter: v5.OrdersHistoryFilter{ + SinceId: 100, + }, + } + + data, status, err := c.OrdersHistory(f) + if err != nil { + t.Errorf("%s", err) + t.Fail() + } + + if status >= http.StatusBadRequest { + t.Errorf("%s", err) + t.Fail() + } + + if data.Success != true { + t.Errorf("%s", err) + t.Fail() + } + + if len(data.History) == 0 { + t.Errorf("%s", err) + t.Fail() + } +}