mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-04-08 11:32:04 +00:00
Compare commits
41 commits
Author | SHA1 | Date | |
---|---|---|---|
c62a02aa1f | |||
|
871459c8b7 | ||
d0b0dd59d6 | |||
|
cc83657f32 | ||
53e2ab5130 | |||
0123057e86 | |||
a8cae8b200 | |||
5fa64ff23e | |||
e2113a640e | |||
2f33b56cd3 | |||
|
8892fe6895 | ||
|
908f16b173 | ||
2859073353 | |||
a482cd1a2f | |||
92a5741c84 | |||
634ec386b1 | |||
d101ddb097 | |||
|
3186470ed9 | ||
904796f97a | |||
|
2f0f55be42 | ||
c79e6c0497 | |||
2587dd786a | |||
|
2333dbf493 | ||
|
d195460141 | ||
|
e6fc8f1e0e | ||
c9e5b1f79d | |||
3282ab045e | |||
4398f85214 | |||
|
77b49e04ab | ||
29062b8bf0 | |||
7c8e142cab | |||
e28631dcb2 | |||
a4de6df146 | |||
81a09e24d4 | |||
b5e7c3ff33 | |||
76135226fb | |||
a72a57fbe1 | |||
c2a33378b8 | |||
|
583362bfe3 | ||
|
ab648cd06a | ||
|
5c6d2ebead |
11 changed files with 2016 additions and 191 deletions
24
.github/workflows/ci.yml
vendored
24
.github/workflows/ci.yml
vendored
|
@ -20,10 +20,10 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Set up Go 1.17
|
- name: Set up Go 1.23
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.17'
|
go-version: '1.23'
|
||||||
- name: Get dependencies
|
- name: Get dependencies
|
||||||
run: |
|
run: |
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
@ -31,7 +31,7 @@ jobs:
|
||||||
- name: Lint code with golangci-lint
|
- name: Lint code with golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.50.1
|
version: v1.62.2
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
skip-pkg-cache: true
|
skip-pkg-cache: true
|
||||||
args: --build-tags=testutils
|
args: --build-tags=testutils
|
||||||
|
@ -40,13 +40,13 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: ['1.13', '1.14', '1.15', '1.16', '1.17']
|
go-version: ['1.19', '1.20', '1.21', '1.22', '1.23', 'stable']
|
||||||
include:
|
include:
|
||||||
- go-version: '1.17'
|
- go-version: '1.23'
|
||||||
coverage: 1
|
coverage: 1
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go ${{ matrix.go-version }}
|
- name: Set up Go ${{ matrix.go-version }}
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
|
@ -59,17 +59,21 @@ jobs:
|
||||||
env:
|
env:
|
||||||
COVERAGE: ${{ matrix.coverage }}
|
COVERAGE: ${{ matrix.coverage }}
|
||||||
if: env.COVERAGE != 1
|
if: env.COVERAGE != 1
|
||||||
run: go test -tags=testutils ./...
|
run: |
|
||||||
|
go install gotest.tools/gotestsum@latest
|
||||||
|
gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race
|
||||||
- name: Tests with coverage
|
- name: Tests with coverage
|
||||||
env:
|
env:
|
||||||
COVERAGE: ${{ matrix.coverage }}
|
COVERAGE: ${{ matrix.coverage }}
|
||||||
if: env.COVERAGE == 1
|
if: env.COVERAGE == 1
|
||||||
run: |
|
run: |
|
||||||
go test -tags=testutils ./... -race -coverprofile=coverage.txt -covermode=atomic "$d"
|
go install gotest.tools/gotestsum@latest
|
||||||
|
gotestsum --format testdox ./... -tags=testutils -v -cpu 2 -timeout 60s -race -cover -coverprofile=coverage.txt -covermode=atomic "$d"
|
||||||
- name: Coverage
|
- name: Coverage
|
||||||
env:
|
env:
|
||||||
COVERAGE: ${{ matrix.coverage }}
|
COVERAGE: ${{ matrix.coverage }}
|
||||||
if: env.COVERAGE == 1
|
if: env.COVERAGE == 1
|
||||||
run: |
|
run: |
|
||||||
|
go install github.com/axw/gocov/gocov@latest
|
||||||
|
gocov convert ./coverage.txt | gocov report
|
||||||
bash <(curl -s https://codecov.io/bash)
|
bash <(curl -s https://codecov.io/bash)
|
||||||
rm coverage.txt
|
|
||||||
|
|
|
@ -1,11 +1,37 @@
|
||||||
run:
|
run:
|
||||||
skip-dirs-use-default: true
|
skip-dirs-use-default: true
|
||||||
allow-parallel-runners: true
|
allow-parallel-runners: true
|
||||||
skip-files:
|
|
||||||
|
issues:
|
||||||
|
exclude-files:
|
||||||
- testutils.go
|
- testutils.go
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- lll
|
||||||
|
- errcheck
|
||||||
|
- misspell
|
||||||
|
- ineffassign
|
||||||
|
- whitespace
|
||||||
|
- makezero
|
||||||
|
- errcheck
|
||||||
|
- funlen
|
||||||
|
- goconst
|
||||||
|
- gocognit
|
||||||
|
- gocyclo
|
||||||
|
- godot
|
||||||
|
- unused
|
||||||
|
- errchkjson
|
||||||
|
- varnamelen
|
||||||
|
exclude-use-default: true
|
||||||
|
exclude-case-sensitive: false
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
max-same-issues: 0
|
||||||
|
fix: true
|
||||||
|
|
||||||
output:
|
output:
|
||||||
format: colored-line-number
|
formats:
|
||||||
|
- format: colored-line-number
|
||||||
sort-results: true
|
sort-results: true
|
||||||
|
|
||||||
# Linters below do not support go1.18 yet because of generics.
|
# Linters below do not support go1.18 yet because of generics.
|
||||||
|
@ -38,6 +64,7 @@ linters:
|
||||||
- errorlint
|
- errorlint
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exportloopref
|
- exportloopref
|
||||||
|
- copyloopvar
|
||||||
- funlen
|
- funlen
|
||||||
- gocognit
|
- gocognit
|
||||||
- goconst
|
- goconst
|
||||||
|
@ -53,7 +80,6 @@ linters:
|
||||||
- nestif
|
- nestif
|
||||||
- prealloc
|
- prealloc
|
||||||
- predeclared
|
- predeclared
|
||||||
- exportloopref
|
|
||||||
- unconvert
|
- unconvert
|
||||||
- whitespace
|
- whitespace
|
||||||
|
|
||||||
|
@ -79,7 +105,6 @@ linters-settings:
|
||||||
- unmarshal
|
- unmarshal
|
||||||
- unreachable
|
- unreachable
|
||||||
- unsafeptr
|
- unsafeptr
|
||||||
- fieldalignment
|
|
||||||
settings:
|
settings:
|
||||||
printf:
|
printf:
|
||||||
funcs:
|
funcs:
|
||||||
|
@ -179,34 +204,10 @@ linters-settings:
|
||||||
- t *testing.T
|
- t *testing.T
|
||||||
- e error
|
- e error
|
||||||
- i int
|
- i int
|
||||||
issues:
|
|
||||||
exclude-rules:
|
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- lll
|
|
||||||
- errcheck
|
|
||||||
- misspell
|
|
||||||
- ineffassign
|
|
||||||
- whitespace
|
|
||||||
- makezero
|
|
||||||
- errcheck
|
|
||||||
- funlen
|
|
||||||
- goconst
|
|
||||||
- gocognit
|
|
||||||
- gocyclo
|
|
||||||
- godot
|
|
||||||
- unused
|
|
||||||
- errchkjson
|
|
||||||
- varnamelen
|
|
||||||
exclude-use-default: true
|
|
||||||
exclude-case-sensitive: false
|
|
||||||
max-issues-per-linter: 0
|
|
||||||
max-same-issues: 0
|
|
||||||
fix: true
|
|
||||||
|
|
||||||
severity:
|
severity:
|
||||||
default-severity: error
|
default-severity: error
|
||||||
case-sensitive: false
|
case-sensitive: false
|
||||||
|
|
||||||
service:
|
service:
|
||||||
golangci-lint-version: 1.50.x
|
golangci-lint-version: 1.62.x
|
||||||
|
|
840
client.go
840
client.go
|
@ -17,10 +17,6 @@ import (
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPStatusUnknown can return for the method `/api/v5/customers/upload`, `/api/v5/customers-corporate/upload`,
|
|
||||||
// `/api/v5/orders/upload`.
|
|
||||||
const HTTPStatusUnknown = 460
|
|
||||||
|
|
||||||
// New initialize client.
|
// New initialize client.
|
||||||
func New(url string, key string) *Client {
|
func New(url string, key string) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
|
@ -36,6 +32,125 @@ func (c *Client) WithLogger(logger BasicLogger) *Client {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableRateLimiter activates rate limiting with specified retry attempts.
|
||||||
|
func (c *Client) EnableRateLimiter(maxAttempts uint) *Client {
|
||||||
|
c.mutex.Lock()
|
||||||
|
defer c.mutex.Unlock()
|
||||||
|
|
||||||
|
c.limiter = &RateLimiter{
|
||||||
|
maxAttempts: maxAttempts,
|
||||||
|
lastRequest: time.Now().Add(-time.Second), // Initialize to allow immediate first request.
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyRateLimit applies rate limiting before sending a request.
|
||||||
|
func (c *Client) applyRateLimit(uri string) {
|
||||||
|
if c.limiter == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.limiter.mutex.Lock()
|
||||||
|
defer c.limiter.mutex.Unlock()
|
||||||
|
|
||||||
|
var delay time.Duration
|
||||||
|
if strings.HasPrefix(uri, "/telephony") {
|
||||||
|
delay = telephonyDelay
|
||||||
|
} else {
|
||||||
|
delay = regularDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed := time.Since(c.limiter.lastRequest)
|
||||||
|
if elapsed < delay {
|
||||||
|
time.Sleep(delay - elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.limiter.lastRequest = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) executeWithRetryBytes(
|
||||||
|
uri string,
|
||||||
|
executeFunc func() (interface{}, int, error),
|
||||||
|
) ([]byte, int, error) {
|
||||||
|
res, status, err := c.executeWithRetry(uri, executeFunc)
|
||||||
|
if res == nil {
|
||||||
|
return nil, status, err
|
||||||
|
}
|
||||||
|
return res.([]byte), status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) executeWithRetryReadCloser(
|
||||||
|
uri string,
|
||||||
|
executeFunc func() (interface{}, int, error),
|
||||||
|
) (io.ReadCloser, int, error) {
|
||||||
|
res, status, err := c.executeWithRetry(uri, executeFunc)
|
||||||
|
if res == nil {
|
||||||
|
return nil, status, err
|
||||||
|
}
|
||||||
|
return res.(io.ReadCloser), status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// executeWithRetry executes a request with retry logic for rate limiting.
|
||||||
|
func (c *Client) executeWithRetry(
|
||||||
|
uri string,
|
||||||
|
executeFunc func() (interface{}, int, error),
|
||||||
|
) (interface{}, int, error) {
|
||||||
|
if c.limiter == nil {
|
||||||
|
return executeFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
res interface{}
|
||||||
|
statusCode int
|
||||||
|
err error
|
||||||
|
lastAttempt bool
|
||||||
|
attempt uint = 1
|
||||||
|
maxAttempts = c.limiter.maxAttempts
|
||||||
|
totalAttempts = "∞"
|
||||||
|
infinite = maxAttempts == 0
|
||||||
|
)
|
||||||
|
|
||||||
|
var baseDelay time.Duration
|
||||||
|
if strings.HasPrefix(uri, "/telephony") {
|
||||||
|
baseDelay = telephonyDelay
|
||||||
|
} else {
|
||||||
|
baseDelay = regularDelay
|
||||||
|
}
|
||||||
|
|
||||||
|
if !infinite {
|
||||||
|
totalAttempts = strconv.FormatUint(uint64(maxAttempts), 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
for infinite || attempt <= maxAttempts {
|
||||||
|
c.applyRateLimit(uri)
|
||||||
|
res, statusCode, err = executeFunc()
|
||||||
|
lastAttempt = !infinite && attempt == maxAttempts
|
||||||
|
|
||||||
|
// If rate limited on final attempt, set error to ErrRateLimited. Return results otherwise.
|
||||||
|
if statusCode == http.StatusServiceUnavailable && lastAttempt {
|
||||||
|
return res, statusCode, ErrRateLimited
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not rate limited or on final attempt, return result.
|
||||||
|
if statusCode != http.StatusServiceUnavailable || lastAttempt {
|
||||||
|
return res, statusCode, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate exponential backoff delay: baseDelay * 2^(attempt-1).
|
||||||
|
backoffDelay := baseDelay * (1 << (attempt - 1))
|
||||||
|
if c.Debug {
|
||||||
|
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%s)",
|
||||||
|
backoffDelay, attempt, totalAttempts)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(backoffDelay)
|
||||||
|
attempt++
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, statusCode, err
|
||||||
|
}
|
||||||
|
|
||||||
// writeLog writes to the log.
|
// writeLog writes to the log.
|
||||||
func (c *Client) writeLog(format string, v ...interface{}) {
|
func (c *Client) writeLog(format string, v ...interface{}) {
|
||||||
if c.logger != nil {
|
if c.logger != nil {
|
||||||
|
@ -48,7 +163,6 @@ func (c *Client) writeLog(format string, v ...interface{}) {
|
||||||
|
|
||||||
// GetRequest implements GET Request.
|
// GetRequest implements GET Request.
|
||||||
func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, error) {
|
func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte, int, error) {
|
||||||
var res []byte
|
|
||||||
var prefix = "/api/v5"
|
var prefix = "/api/v5"
|
||||||
|
|
||||||
if len(versioned) > 0 {
|
if len(versioned) > 0 {
|
||||||
|
@ -57,41 +171,49 @@ func (c *Client) GetRequest(urlWithParameters string, versioned ...bool) ([]byte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil)
|
uri := urlWithParameters
|
||||||
if err != nil {
|
|
||||||
return res, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("X-API-KEY", c.Key)
|
return c.executeWithRetryBytes(uri, func() (interface{}, int, error) {
|
||||||
|
var res []byte
|
||||||
|
|
||||||
if c.Debug {
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), nil)
|
||||||
c.writeLog("API Request: %s %s", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), c.Key)
|
if err != nil {
|
||||||
}
|
return res, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
req.Header.Set("X-API-KEY", c.Key)
|
||||||
if err != nil {
|
|
||||||
return res, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusInternalServerError {
|
if c.Debug {
|
||||||
return res, resp.StatusCode, CreateGenericAPIError(
|
c.writeLog("API Request: %s %s", fmt.Sprintf("%s%s%s", c.URL, prefix, urlWithParameters), c.Key)
|
||||||
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
res, err = buildRawResponse(resp)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, 0, err
|
return res, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError {
|
if resp.StatusCode >= http.StatusInternalServerError && resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
return res, resp.StatusCode, CreateAPIError(res)
|
return res, resp.StatusCode, CreateGenericAPIError(
|
||||||
}
|
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
if c.Debug {
|
res, err = buildRawResponse(resp)
|
||||||
c.writeLog("API Response: %s", res)
|
if err != nil {
|
||||||
}
|
return res, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
return res, resp.StatusCode, nil
|
if resp.StatusCode >= http.StatusBadRequest &&
|
||||||
|
resp.StatusCode < http.StatusInternalServerError &&
|
||||||
|
resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
|
return res, resp.StatusCode, CreateAPIError(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Debug {
|
||||||
|
c.writeLog("API Response: %s", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, resp.StatusCode, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostRequest implements POST Request with generic body data.
|
// PostRequest implements POST Request with generic body data.
|
||||||
|
@ -100,12 +222,7 @@ func (c *Client) PostRequest(
|
||||||
postData interface{},
|
postData interface{},
|
||||||
contType ...string,
|
contType ...string,
|
||||||
) ([]byte, int, error) {
|
) ([]byte, int, error) {
|
||||||
var (
|
var contentType string
|
||||||
res []byte
|
|
||||||
contentType string
|
|
||||||
)
|
|
||||||
|
|
||||||
prefix := "/api/v5"
|
|
||||||
|
|
||||||
if len(contType) > 0 {
|
if len(contType) > 0 {
|
||||||
contentType = contType[0]
|
contentType = contType[0]
|
||||||
|
@ -113,47 +230,55 @@ func (c *Client) PostRequest(
|
||||||
contentType = "application/x-www-form-urlencoded"
|
contentType = "application/x-www-form-urlencoded"
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, err := getReaderForPostData(postData)
|
prefix := "/api/v5"
|
||||||
if err != nil {
|
|
||||||
return res, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, uri), reader)
|
return c.executeWithRetryBytes(uri, func() (interface{}, int, error) {
|
||||||
if err != nil {
|
var res []byte
|
||||||
return res, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("Content-Type", contentType)
|
reader, err := getReaderForPostData(postData)
|
||||||
req.Header.Set("X-API-KEY", c.Key)
|
if err != nil {
|
||||||
|
return res, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
if c.Debug {
|
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s%s", c.URL, prefix, uri), reader)
|
||||||
c.writeLog("API Request: %s %s", uri, c.Key)
|
if err != nil {
|
||||||
}
|
return res, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
req.Header.Set("Content-Type", contentType)
|
||||||
if err != nil {
|
req.Header.Set("X-API-KEY", c.Key)
|
||||||
return res, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusInternalServerError {
|
if c.Debug {
|
||||||
return res, resp.StatusCode, CreateGenericAPIError(
|
c.writeLog("API Request: %s %s", uri, c.Key)
|
||||||
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
res, err = buildRawResponse(resp)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, 0, err
|
return res, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError {
|
if resp.StatusCode >= http.StatusInternalServerError && resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
return res, resp.StatusCode, CreateAPIError(res)
|
return res, resp.StatusCode, CreateGenericAPIError(
|
||||||
}
|
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
if c.Debug {
|
res, err = buildRawResponse(resp)
|
||||||
c.writeLog("API Response: %s", res)
|
if err != nil {
|
||||||
}
|
return res, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
return res, resp.StatusCode, nil
|
if resp.StatusCode >= http.StatusBadRequest &&
|
||||||
|
resp.StatusCode < http.StatusInternalServerError &&
|
||||||
|
resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
|
return res, resp.StatusCode, CreateAPIError(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Debug {
|
||||||
|
c.writeLog("API Response: %s", res)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, resp.StatusCode, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getReaderForPostData(postData interface{}) (io.Reader, error) {
|
func getReaderForPostData(postData interface{}) (io.Reader, error) {
|
||||||
|
@ -1832,6 +1957,174 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si
|
||||||
return resp, status, nil
|
return resp, status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearCart clears the current customer's shopping cart
|
||||||
|
//
|
||||||
|
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customer-interaction-site-cart-clear
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.ClearCart("site_id", retailcrm.SiteFilter{SiteBy: "id"},
|
||||||
|
// retailcrm.ClearCartRequest{
|
||||||
|
// ClearedAt: time.Now().String(),
|
||||||
|
// Customer: retailcrm.CartCustomer{
|
||||||
|
// ID: 1,
|
||||||
|
// ExternalID: "ext_id",
|
||||||
|
// Site: "site",
|
||||||
|
// BrowserID: "browser_id",
|
||||||
|
// GaClientID: "ga_client_id",
|
||||||
|
// },
|
||||||
|
// Order: retailcrm.ClearCartOrder{
|
||||||
|
// ID: 1,
|
||||||
|
// ExternalID: "ext_id",
|
||||||
|
// Number: "abc123",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
func (c *Client) ClearCart(site string, filter SiteFilter, req ClearCartRequest) (
|
||||||
|
SuccessfulResponse, int, error,
|
||||||
|
) {
|
||||||
|
var resp SuccessfulResponse
|
||||||
|
|
||||||
|
updateJSON, err := json.Marshal(&req)
|
||||||
|
if err != nil {
|
||||||
|
return SuccessfulResponse{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"cart": {string(updateJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
params, _ := query.Values(filter)
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest(fmt.Sprintf("/customer-interaction/%s/cart/clear?%s", site, params.Encode()), p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCart creates or overwrites shopping cart data
|
||||||
|
//
|
||||||
|
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customer-interaction-site-cart-set
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.SetCart("site_id", retailcrm.SiteFilter{SiteBy: "id"},
|
||||||
|
// retailcrm.SetCartRequest{
|
||||||
|
// ExternalID: "ext_id",
|
||||||
|
// DroppedAt: time.Now().String(),
|
||||||
|
// Link: "link",
|
||||||
|
// Customer: retailcrm.CartCustomer{
|
||||||
|
// ID: 1,
|
||||||
|
// ExternalID: "ext_id",
|
||||||
|
// Site: "site",
|
||||||
|
// BrowserID: "browser_id",
|
||||||
|
// GaClientID: "ga_client_id",
|
||||||
|
// },
|
||||||
|
// Items: []retailcrm.SetCartItem{
|
||||||
|
// {
|
||||||
|
// Quantity: 1,
|
||||||
|
// Price: 1.0,
|
||||||
|
// Offer: retailcrm.SetCartOffer{
|
||||||
|
// ID: 1,
|
||||||
|
// ExternalID: "ext_id",
|
||||||
|
// XMLID: "xml_id",
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
func (c *Client) SetCart(site string, filter SiteFilter, req SetCartRequest) (
|
||||||
|
SuccessfulResponse, int, error,
|
||||||
|
) {
|
||||||
|
var resp SuccessfulResponse
|
||||||
|
|
||||||
|
updateJSON, err := json.Marshal(&req)
|
||||||
|
if err != nil {
|
||||||
|
return SuccessfulResponse{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"cart": {string(updateJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
params, _ := query.Values(filter)
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest(fmt.Sprintf("/customer-interaction/%s/cart/set?%s", site, params.Encode()), p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCart returns the current customer's shopping cart
|
||||||
|
//
|
||||||
|
// For more information see https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-customer-interaction-site-cart-customerId
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.GetCart("site_id","customer_id",
|
||||||
|
// retailcrm.GetCartFilter{ SiteBy: "code", By: "externalId"})
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
func (c *Client) GetCart(site, customer string, filter GetCartFilter) (CartResponse, int, error) {
|
||||||
|
var resp CartResponse
|
||||||
|
|
||||||
|
params, _ := query.Values(filter)
|
||||||
|
|
||||||
|
data, status, err := c.GetRequest(fmt.Sprintf("/customer-interaction/%s/cart/%s?%s", site, customer, params.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
// DeliveryTracking updates tracking data
|
// DeliveryTracking updates tracking data
|
||||||
//
|
//
|
||||||
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-generic-subcode-tracking
|
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-delivery-generic-subcode-tracking
|
||||||
|
@ -2109,6 +2402,323 @@ func (c *Client) IntegrationModule(code string) (IntegrationModuleResponse, int,
|
||||||
return resp, status, nil
|
return resp, status, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LinksCreate creates a link
|
||||||
|
//
|
||||||
|
// For more information see https://www.simla.com/docs/Developers/API/APIVersions/APIv5#post--api-v5-orders-links-create
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.LinksCreate(retailcrm.SerializedOrderLink{
|
||||||
|
// Comment: "comment for link",
|
||||||
|
// Orders: []retailcrm.LinkedOrder{{ID: 10}, {ID: 12}},
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if data.Success == true {
|
||||||
|
// log.Println("Creating a link")
|
||||||
|
// }
|
||||||
|
func (c *Client) LinksCreate(link SerializedOrderLink, site ...string) (SuccessfulResponse, int, error) {
|
||||||
|
var resp SuccessfulResponse
|
||||||
|
|
||||||
|
linkJSON, err := json.Marshal(link)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"link": {string(linkJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
fillSite(&p, site)
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest("/orders/links/create", p)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientIdsUpload uploading of web analytics clientId
|
||||||
|
//
|
||||||
|
// For more information see https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-web-analytics-client-ids-upload
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.ClientIdsUpload([]retailcrm.ClientID{
|
||||||
|
// {
|
||||||
|
// Value: "value",
|
||||||
|
// Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
||||||
|
// Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalID"},
|
||||||
|
// Site: "site",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Value: "value",
|
||||||
|
// Order: LinkedOrder{ID: 12, ExternalID: "externalID2", Number: "number2"},
|
||||||
|
// Customer: SerializedEntityCustomer{ID: 12, ExternalID: "externalID2"},
|
||||||
|
// Site: "site2",
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if data.Success == true {
|
||||||
|
// log.Println("Upload is successful")
|
||||||
|
// }
|
||||||
|
func (c *Client) ClientIdsUpload(clientIds []ClientID) (ClientIDResponse, int, error) {
|
||||||
|
var resp ClientIDResponse
|
||||||
|
clientIdsJSON, err := json.Marshal(&clientIds)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"clientIds": {string(clientIdsJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest("/web-analytics/client-ids/upload", p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SourcesUpload uploading of sources
|
||||||
|
//
|
||||||
|
// For more information see https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-web-analytics-sources-upload
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.SourcesUpload([]retailcrm.Source{
|
||||||
|
// {
|
||||||
|
// Source: "source",
|
||||||
|
// Medium: "medium",
|
||||||
|
// Campaign: "campaign",
|
||||||
|
// Keyword: "keyword",
|
||||||
|
// Content: "content",
|
||||||
|
// ClientID: "10",
|
||||||
|
// Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
|
// Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
||||||
|
// Site: "site",
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if data.Success == true {
|
||||||
|
// log.Println("Upload is successful!")
|
||||||
|
// }
|
||||||
|
func (c *Client) SourcesUpload(sources []Source) (SourcesResponse, int, error) {
|
||||||
|
var resp SourcesResponse
|
||||||
|
sourcesJSON, err := json.Marshal(&sources)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"sources": {string(sourcesJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest("/web-analytics/sources/upload", p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currencies returns a list of currencies
|
||||||
|
//
|
||||||
|
// For more information see https://docs.simla.com/Developers/API/APIVersions/APIv5#get--api-v5-reference-currencies
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.Currencies()
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// for _, value := range data.Currencies {
|
||||||
|
// log.Printf("%v\n", value)
|
||||||
|
// }
|
||||||
|
func (c *Client) Currencies() (CurrencyResponse, int, error) {
|
||||||
|
var resp CurrencyResponse
|
||||||
|
|
||||||
|
data, status, err := c.GetRequest("/reference/currencies")
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CurrenciesCreate create currency
|
||||||
|
//
|
||||||
|
// For more information see https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-reference-currencies-create
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.CurrenciesCreate(retailcrm.Currency{
|
||||||
|
// Code: "RUB",
|
||||||
|
// IsBase: true,
|
||||||
|
// IsAutoConvert: true,
|
||||||
|
// AutoConvertExtraPercent: 1,
|
||||||
|
// ManualConvertNominal: 1,
|
||||||
|
// ManualConvertValue: 1,
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if data.Success == true {
|
||||||
|
// log.Println("Create currency")
|
||||||
|
// }
|
||||||
|
func (c *Client) CurrenciesCreate(currency Currency) (CurrencyCreateResponse, int, error) {
|
||||||
|
var resp CurrencyCreateResponse
|
||||||
|
currencyJSON, err := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"currency": {string(currencyJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest("/reference/currencies/create", p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CurrenciesEdit edit an currency
|
||||||
|
//
|
||||||
|
// For more information see https://docs.simla.com/Developers/API/APIVersions/APIv5#post--api-v5-reference-currencies-id-edit
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = retailcrm.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.CurrenciesEdit(
|
||||||
|
// retailcrm.Currency{
|
||||||
|
// ID: 10,
|
||||||
|
// Code: "RUB",
|
||||||
|
// IsBase: true,
|
||||||
|
// IsAutoConvert: true,
|
||||||
|
// AutoConvertExtraPercent: 1,
|
||||||
|
// ManualConvertNominal: 1,
|
||||||
|
// ManualConvertValue: 1,
|
||||||
|
// },
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// if err != nil {
|
||||||
|
// if apiErr, ok := retailcrm.AsAPIError(err); ok {
|
||||||
|
// log.Fatalf("http status: %d, %s", status, apiErr.String())
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Fatalf("http status: %d, error: %s", status, err)
|
||||||
|
// }
|
||||||
|
// if data.Success == true {
|
||||||
|
// log.Println("Currency was edit")
|
||||||
|
// }
|
||||||
|
func (c *Client) CurrenciesEdit(currency Currency) (SuccessfulResponse, int, error) {
|
||||||
|
var resp SuccessfulResponse
|
||||||
|
var uid = strconv.Itoa(currency.ID)
|
||||||
|
|
||||||
|
currencyJSON, err := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, http.StatusBadRequest, err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"currency": {string(currencyJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, status, err := c.PostRequest(fmt.Sprintf("/reference/currencies/%s/edit", uid), p)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return resp, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, status, nil
|
||||||
|
}
|
||||||
|
|
||||||
// IntegrationModuleEdit integration module create/edit
|
// IntegrationModuleEdit integration module create/edit
|
||||||
//
|
//
|
||||||
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-integration-modules-code
|
// For more information see http://www.simla.com/docs/Developers/API/APIVersions/APIv5#get--api-v5-integration-modules-code
|
||||||
|
@ -4650,7 +5260,7 @@ func (c *Client) StaticticsUpdate() (SuccessfulResponse, int, error) {
|
||||||
//
|
//
|
||||||
// data, status, err := client.Costs(CostsRequest{
|
// data, status, err := client.Costs(CostsRequest{
|
||||||
// Filter: CostsFilter{
|
// Filter: CostsFilter{
|
||||||
// Ids: []string{"1","2","3"},
|
// IDs: []string{"1","2","3"},
|
||||||
// MinSumm: "1000"
|
// MinSumm: "1000"
|
||||||
// },
|
// },
|
||||||
// })
|
// })
|
||||||
|
@ -6445,53 +7055,52 @@ func (c *Client) EditProductsGroup(by, id, site string, group ProductGroup) (Act
|
||||||
// log.Printf("%s", fileData)
|
// log.Printf("%s", fileData)
|
||||||
// }
|
// }
|
||||||
func (c *Client) GetOrderPlate(by, orderID, site string, plateID int) (io.ReadCloser, int, error) {
|
func (c *Client) GetOrderPlate(by, orderID, site string, plateID int) (io.ReadCloser, int, error) {
|
||||||
p := url.Values{
|
requestURL := fmt.Sprintf("%s/api/v5/orders/%s/plates/%d/print?%s", c.URL, orderID, plateID, url.Values{
|
||||||
"by": {checkBy(by)},
|
"by": {checkBy(by)},
|
||||||
"site": {site},
|
"site": {site},
|
||||||
}
|
}.Encode())
|
||||||
|
|
||||||
requestURL := fmt.Sprintf("%s/api/v5/orders/%s/plates/%d/print?%s", c.URL, orderID, plateID, p.Encode())
|
return c.executeWithRetryReadCloser(requestURL, func() (interface{}, int, error) {
|
||||||
req, err := http.NewRequest("GET", requestURL, nil)
|
req, err := http.NewRequest("GET", requestURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
req.Header.Set("X-API-KEY", c.Key)
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("X-API-KEY", c.Key)
|
if c.Debug {
|
||||||
|
c.writeLog("API Request: %s %s", requestURL, c.Key)
|
||||||
|
}
|
||||||
|
|
||||||
if c.Debug {
|
resp, err := c.httpClient.Do(req)
|
||||||
c.writeLog("API Request: %s %s", requestURL, c.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := c.httpClient.Do(req)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusInternalServerError {
|
|
||||||
return nil, resp.StatusCode, CreateGenericAPIError(
|
|
||||||
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode >= http.StatusBadRequest && resp.StatusCode < http.StatusInternalServerError {
|
|
||||||
res, err := buildRawResponse(resp)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, resp.StatusCode, CreateAPIError(res)
|
if resp.StatusCode >= http.StatusInternalServerError && resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
}
|
return nil, resp.StatusCode, CreateGenericAPIError(
|
||||||
|
fmt.Sprintf("HTTP request error. Status code: %d.", resp.StatusCode))
|
||||||
|
}
|
||||||
|
|
||||||
reader := resp.Body
|
if resp.StatusCode >= http.StatusBadRequest &&
|
||||||
err = reader.Close()
|
resp.StatusCode < http.StatusInternalServerError &&
|
||||||
|
resp.StatusCode != http.StatusServiceUnavailable {
|
||||||
|
res, err := buildRawResponse(resp)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return reader, resp.StatusCode, nil
|
return nil, resp.StatusCode, CreateAPIError(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.Body, resp.StatusCode, nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationsSend send a notification
|
// NotificationsSend send a notification
|
||||||
|
@ -6590,3 +7199,26 @@ func (c *Client) EditMGChannelTemplate(req EditMGChannelTemplateRequest) (int, e
|
||||||
|
|
||||||
return code, nil
|
return code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) StoreOffers(req OffersRequest) (StoreOffersResponse, int, error) {
|
||||||
|
var result StoreOffersResponse
|
||||||
|
|
||||||
|
filter, err := query.Values(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, status, err := c.GetRequest(fmt.Sprintf("/store/offers?%s", filter.Encode()))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(resp, &result)
|
||||||
|
if err != nil {
|
||||||
|
return StoreOffersResponse{}, status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, status, nil
|
||||||
|
}
|
||||||
|
|
848
client_test.go
848
client_test.go
|
@ -3,6 +3,7 @@ package retailcrm
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -81,21 +82,131 @@ func TestBaseURLTrimmed(t *testing.T) {
|
||||||
assert.Equal(t, c1.URL, c3.URL)
|
assert.Equal(t, c1.URL, c3.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRequest(t *testing.T) {
|
func TestGetRequestWithRateLimiter(t *testing.T) {
|
||||||
c := client()
|
t.Run("Basic 404 response", func(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
defer gock.Off()
|
defer gock.Off()
|
||||||
|
|
||||||
gock.New(crmURL).
|
gock.New(crmURL).
|
||||||
Get("/api/v5/fake-method").
|
Get("/api/v5/fake-method").
|
||||||
Reply(404).
|
Reply(404).
|
||||||
BodyString(`{"success": false, "errorMsg" : "Method not found"}`)
|
BodyString(`{"success": false, "errorMsg" : "Method not found"}`)
|
||||||
|
|
||||||
_, status, _ := c.GetRequest("/fake-method")
|
_, status, _ := c.GetRequest("/fake-method")
|
||||||
|
|
||||||
if status != http.StatusNotFound {
|
assert.Equal(t, http.StatusNotFound, status)
|
||||||
t.Fail()
|
})
|
||||||
}
|
|
||||||
|
t.Run("Rate limiter respects configured RPS", func(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
c.EnableRateLimiter(3)
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
numRequests := 5
|
||||||
|
|
||||||
|
for i := 0; i < numRequests; i++ {
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/test-method").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
for i := 0; i < numRequests; i++ {
|
||||||
|
_, _, err := c.GetRequest("/test-method")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Request %d failed: %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
minExpectedTime := time.Duration(numRequests-1) * time.Second / 10
|
||||||
|
assert.Truef(t, elapsed > minExpectedTime,
|
||||||
|
"Rate limiter not working correctly. Expected minimum time %v, got %v",
|
||||||
|
minExpectedTime, elapsed)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Rate limiter respects telephony endpoint RPS", func(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
c.EnableRateLimiter(3)
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
numRequests := 5
|
||||||
|
|
||||||
|
for i := 0; i < numRequests; i++ {
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/telephony/test-call").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
for i := 0; i < numRequests; i++ {
|
||||||
|
_, _, err := c.GetRequest("/telephony/test-call")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Request %d failed: %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
minExpectedTime := time.Duration(numRequests-1) * time.Second / 40
|
||||||
|
assert.Truef(t, elapsed > minExpectedTime,
|
||||||
|
"Rate limiter not working correctly for telephony. Expected minimum time %v, got %v",
|
||||||
|
minExpectedTime, elapsed)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Rate limiter retries on 503 responses", func(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
c.EnableRateLimiter(3)
|
||||||
|
c.Debug = true
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/retry-test").
|
||||||
|
Reply(503).
|
||||||
|
BodyString(`{"success": false, "errorMsg": "Rate limit exceeded"}`)
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/retry-test").
|
||||||
|
Reply(503).
|
||||||
|
BodyString(`{"success": false, "errorMsg": "Rate limit exceeded"}`)
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/retry-test").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
_, status, err := c.GetRequest("/retry-test")
|
||||||
|
|
||||||
|
require.NoErrorf(t, err, "Request failed despite retries: %v", err)
|
||||||
|
assert.Equal(t, http.StatusOK, status)
|
||||||
|
assert.True(t, gock.IsDone(), "Not all expected requests were made")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Rate limiter gives up after max attempts", func(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
c.EnableRateLimiter(2)
|
||||||
|
|
||||||
|
defer gock.OffAll()
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/api/v5/retry-test").
|
||||||
|
Reply(503).
|
||||||
|
BodyString(`{"success": false, "errorMsg": "Rate limit exceeded"}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, status, err := c.GetRequest("/retry-test")
|
||||||
|
|
||||||
|
assert.Equalf(t, http.StatusServiceUnavailable, status,
|
||||||
|
"Expected status 503 after max retries, got %d", status)
|
||||||
|
assert.ErrorIs(t, err, ErrRateLimited, "Expected error after max retries, got nil")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostRequest(t *testing.T) {
|
func TestPostRequest(t *testing.T) {
|
||||||
|
@ -1766,6 +1877,171 @@ func TestClient_CorporateCustomerEdit(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_ClearCart(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
site := "site_id"
|
||||||
|
filter := SiteFilter{SiteBy: "id"}
|
||||||
|
request := ClearCartRequest{
|
||||||
|
ClearedAt: time.Now().String(),
|
||||||
|
Customer: CartCustomer{
|
||||||
|
ID: 1,
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
Site: "site",
|
||||||
|
BrowserID: "browser_id",
|
||||||
|
GaClientID: "ga_client_id",
|
||||||
|
},
|
||||||
|
Order: ClearCartOrder{
|
||||||
|
ID: 1,
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
Number: "abc123",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post(fmt.Sprintf("/customer-interaction/%s/cart/clear", site)).
|
||||||
|
MatchParam("siteBy", filter.SiteBy).
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success":true}`)
|
||||||
|
|
||||||
|
data, status, err := c.ClearCart(site, filter, request)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("(%d) %v", status, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_SetCart(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
site := "site_id"
|
||||||
|
filter := SiteFilter{SiteBy: "id"}
|
||||||
|
request := SetCartRequest{
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
DroppedAt: time.Now().String(),
|
||||||
|
Link: "link",
|
||||||
|
Customer: CartCustomer{
|
||||||
|
ID: 1,
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
Site: "site",
|
||||||
|
BrowserID: "browser_id",
|
||||||
|
GaClientID: "ga_client_id",
|
||||||
|
},
|
||||||
|
Items: []SetCartItem{
|
||||||
|
{
|
||||||
|
Quantity: 1,
|
||||||
|
Price: 1.0,
|
||||||
|
Offer: SetCartOffer{
|
||||||
|
ID: 1,
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
XMLID: "xml_id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post(fmt.Sprintf("/customer-interaction/%s/cart/set", site)).
|
||||||
|
MatchParam("siteBy", filter.SiteBy).
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success":true}`)
|
||||||
|
|
||||||
|
data, status, err := c.SetCart(site, filter, request)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("(%d) %v", status, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_GetCart(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
site := "site_id"
|
||||||
|
customer := "customer_id"
|
||||||
|
filter := GetCartFilter{
|
||||||
|
SiteBy: "code",
|
||||||
|
By: "externalId",
|
||||||
|
}
|
||||||
|
|
||||||
|
expCart := Cart{
|
||||||
|
Currency: "currency",
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
DroppedAt: time.Now().String(),
|
||||||
|
ClearedAt: time.Now().String(),
|
||||||
|
Link: "link",
|
||||||
|
Items: []CartItem{
|
||||||
|
{
|
||||||
|
ID: 1,
|
||||||
|
Quantity: 2,
|
||||||
|
Price: 3.0,
|
||||||
|
Offer: CartOffer{
|
||||||
|
DisplayName: "name",
|
||||||
|
ID: 1,
|
||||||
|
ExternalID: "ext_id",
|
||||||
|
XMLID: "xml_id",
|
||||||
|
Name: "name",
|
||||||
|
Article: "article",
|
||||||
|
VatRate: "vat_rate",
|
||||||
|
Properties: StringMap{
|
||||||
|
"a": "b",
|
||||||
|
"c": "d",
|
||||||
|
},
|
||||||
|
Barcode: "barcode",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cartResp := CartResponse{
|
||||||
|
SuccessfulResponse: SuccessfulResponse{Success: true},
|
||||||
|
Cart: expCart,
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get(fmt.Sprintf("/customer-interaction/%s/cart/%s", site, customer)).
|
||||||
|
MatchParams(map[string]string{
|
||||||
|
"siteBy": filter.SiteBy,
|
||||||
|
"by": filter.By,
|
||||||
|
}).
|
||||||
|
Reply(200).
|
||||||
|
JSON(cartResp)
|
||||||
|
|
||||||
|
data, status, err := c.GetCart(site, customer, filter)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("(%d) %v", status, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expCart, data.Cart) {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_NotesNotes(t *testing.T) {
|
func TestClient_NotesNotes(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
|
|
||||||
|
@ -1988,6 +2264,419 @@ func TestClient_OrdersOrders_Fail(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_LinksCreate(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
orders := []LinkedOrder{{ID: 10}, {ID: 12}}
|
||||||
|
|
||||||
|
link := SerializedOrderLink{
|
||||||
|
Comment: "comment",
|
||||||
|
Orders: orders,
|
||||||
|
}
|
||||||
|
|
||||||
|
linkJSON, _ := json.Marshal(link)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"link": {string(linkJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/links/create").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(201).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
data, status, err := c.LinksCreate(link)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_LinksCreate_Fail(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
orders := []LinkedOrder{{ID: 10}}
|
||||||
|
|
||||||
|
link := SerializedOrderLink{
|
||||||
|
Comment: "comment",
|
||||||
|
Orders: orders,
|
||||||
|
}
|
||||||
|
|
||||||
|
linkJSON, _ := json.Marshal(link)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"link": {string(linkJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/links/create").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(400).
|
||||||
|
BodyString(`{"errorMsg": "Errors in the entity format", errors: [orders: "This collection should contain 2 elements or more."}`)
|
||||||
|
|
||||||
|
data, _, err := c.LinksCreate(link)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error must be return")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != false {
|
||||||
|
t.Error(successFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_ClientIdsUpload(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
clientIds := []ClientID{
|
||||||
|
{
|
||||||
|
Value: "value",
|
||||||
|
Order: LinkedOrder{ID: 10, ExternalID: "externalID", Number: "number"},
|
||||||
|
Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalID"},
|
||||||
|
Site: "site",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Value: "value2",
|
||||||
|
Order: LinkedOrder{ID: 12, ExternalID: "externalID2", Number: "number2"},
|
||||||
|
Customer: SerializedEntityCustomer{ID: 12, ExternalID: "externalID2"},
|
||||||
|
Site: "site2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
clientIdsJSON, _ := json.Marshal(&clientIds)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"clientIds": {string(clientIdsJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/web-analytics/client-ids/upload").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(201).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
data, status, err := c.ClientIdsUpload(clientIds)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_ClientIdsUpload_Fail(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
clientIds := []ClientID{
|
||||||
|
{
|
||||||
|
Value: "value",
|
||||||
|
Order: LinkedOrder{ID: 10},
|
||||||
|
Customer: SerializedEntityCustomer{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
clientIdsJSON, _ := json.Marshal(&clientIds)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"clientIds": {string(clientIdsJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/web-analytics/client-ids/upload").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(400).
|
||||||
|
BodyString(`
|
||||||
|
{
|
||||||
|
"errorMsg": "ClientIds are loaded with errors",
|
||||||
|
"errors": [0: "customer: Set one of the following fields: id, externalId"]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
data, _, err := c.ClientIdsUpload(clientIds)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error must be return")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != false {
|
||||||
|
t.Error(successFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_SourcesUpload(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
sources := []Source{
|
||||||
|
{
|
||||||
|
Source: "source",
|
||||||
|
Medium: "medium",
|
||||||
|
Campaign: "campaign",
|
||||||
|
Keyword: "keyword",
|
||||||
|
Content: "content",
|
||||||
|
ClientID: "10",
|
||||||
|
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
|
Customer: SerializedEntityCustomer{ID: 10, ExternalID: "externalId"},
|
||||||
|
Site: "site",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcesJSON, _ := json.Marshal(&sources)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"sources": {string(sourcesJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/web-analytics/sources/upload").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(201).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
data, status, err := c.SourcesUpload(sources)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_SourcesUpload_Fail(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
sources := []Source{
|
||||||
|
{
|
||||||
|
Source: "source",
|
||||||
|
Medium: "medium",
|
||||||
|
Campaign: "campaign",
|
||||||
|
Keyword: "keyword",
|
||||||
|
Content: "content",
|
||||||
|
ClientID: "12",
|
||||||
|
Order: LinkedOrder{ID: 10, ExternalID: "externalId", Number: "number"},
|
||||||
|
Customer: SerializedEntityCustomer{},
|
||||||
|
Site: "site",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcesJSON, _ := json.Marshal(&sources)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"sources": {string(sourcesJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/web-analytics/sources/upload").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(400).
|
||||||
|
BodyString(`
|
||||||
|
{
|
||||||
|
"errorMsg": "ClientIds are loaded with errors",
|
||||||
|
"errors": [0: "customer: Set one of the following fields: id, externalId"]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
data, _, err := c.SourcesUpload(sources)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Error must be return")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != false {
|
||||||
|
t.Error(successFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_Currencies(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Get("/reference/currencies").
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"currencies": [
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"code": "code",
|
||||||
|
"isBase": true,
|
||||||
|
"isAutoConvert": true,
|
||||||
|
"autoConvertExtraPercent": 1,
|
||||||
|
"manualConvertNominal": 1,
|
||||||
|
"manualConvertValue": 1.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 12,
|
||||||
|
"code": "code2",
|
||||||
|
"isBase": false,
|
||||||
|
"isAutoConvert": false,
|
||||||
|
"autoConvertExtra_percent": 2,
|
||||||
|
"manualConvertNominal": 5,
|
||||||
|
"manualConvertValue": 60.25
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`)
|
||||||
|
|
||||||
|
resp := CurrencyResponse{
|
||||||
|
Success: true,
|
||||||
|
Currencies: []Currency{
|
||||||
|
{
|
||||||
|
ID: 10,
|
||||||
|
Code: "code",
|
||||||
|
IsBase: true,
|
||||||
|
IsAutoConvert: true,
|
||||||
|
AutoConvertExtraPercent: 1,
|
||||||
|
ManualConvertNominal: 1,
|
||||||
|
ManualConvertValue: 1.5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: 12,
|
||||||
|
Code: "code2",
|
||||||
|
IsBase: false,
|
||||||
|
IsAutoConvert: false,
|
||||||
|
AutoConvertExtraPercent: 0,
|
||||||
|
ManualConvertNominal: 5,
|
||||||
|
ManualConvertValue: 60.25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, status, err := c.Currencies()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, resp, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_CurrenciesCreate(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
currency := Currency{
|
||||||
|
ID: 10,
|
||||||
|
Code: "RUB",
|
||||||
|
IsBase: true,
|
||||||
|
IsAutoConvert: true,
|
||||||
|
AutoConvertExtraPercent: 1,
|
||||||
|
ManualConvertNominal: 1,
|
||||||
|
ManualConvertValue: 1.5,
|
||||||
|
}
|
||||||
|
|
||||||
|
currencyJSON, _ := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"currency": {string(currencyJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post("/reference/currencies/create").
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(201).
|
||||||
|
BodyString(`{"success": true, "id": 10}`)
|
||||||
|
|
||||||
|
data, status, err := c.CurrenciesCreate(currency)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, currency.ID, data.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClient_CurrenciesEdit(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
currency := Currency{
|
||||||
|
ID: 10,
|
||||||
|
Code: "code",
|
||||||
|
IsBase: true,
|
||||||
|
IsAutoConvert: true,
|
||||||
|
AutoConvertExtraPercent: 1,
|
||||||
|
ManualConvertNominal: 1,
|
||||||
|
ManualConvertValue: 1.5,
|
||||||
|
}
|
||||||
|
var uid = strconv.Itoa(currency.ID)
|
||||||
|
currencyJSON, _ := json.Marshal(¤cy)
|
||||||
|
|
||||||
|
p := url.Values{
|
||||||
|
"currency": {string(currencyJSON)},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
gock.New(crmURL).
|
||||||
|
Post(fmt.Sprintf("/reference/currencies/%s/edit", uid)).
|
||||||
|
BodyString(p.Encode()).
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
data, status, err := c.CurrenciesEdit(currency)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if status >= http.StatusBadRequest {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.Success != true {
|
||||||
|
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_OrderChange(t *testing.T) {
|
func TestClient_OrderChange(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
|
|
||||||
|
@ -3409,7 +4098,95 @@ func TestClient_PriceTypes(t *testing.T) {
|
||||||
gock.New(crmURL).
|
gock.New(crmURL).
|
||||||
Get("/reference/price-types").
|
Get("/reference/price-types").
|
||||||
Reply(200).
|
Reply(200).
|
||||||
BodyString(`{"success": true}`)
|
BodyString(`
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"priceTypes": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"code": "base",
|
||||||
|
"name": "Base",
|
||||||
|
"active": true,
|
||||||
|
"promo": false,
|
||||||
|
"default": true,
|
||||||
|
"geo": [],
|
||||||
|
"groups": [],
|
||||||
|
"ordering": 1,
|
||||||
|
"currency": "MXN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"code": "cop",
|
||||||
|
"name": "COP",
|
||||||
|
"active": false,
|
||||||
|
"promo": false,
|
||||||
|
"default": false,
|
||||||
|
"geo": [],
|
||||||
|
"groups": [
|
||||||
|
"manager_1"
|
||||||
|
],
|
||||||
|
"ordering": 990,
|
||||||
|
"currency": "MXN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"code": "promo_test",
|
||||||
|
"name": "Promotional",
|
||||||
|
"active": false,
|
||||||
|
"promo": true,
|
||||||
|
"default": false,
|
||||||
|
"geo": [
|
||||||
|
{
|
||||||
|
"country": "CO",
|
||||||
|
"regionId": "",
|
||||||
|
"region": "Todas las regiones",
|
||||||
|
"cityId": "",
|
||||||
|
"city": "All"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "ES",
|
||||||
|
"regionId": "",
|
||||||
|
"region": "Todas las regiones",
|
||||||
|
"cityId": "",
|
||||||
|
"city": "All"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"country": "MX",
|
||||||
|
"regionId": "",
|
||||||
|
"region": "Todas las regiones",
|
||||||
|
"cityId": "",
|
||||||
|
"city": "All"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"groups": [],
|
||||||
|
"ordering": 990,
|
||||||
|
"currency": "MXN"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"code": "wholesale",
|
||||||
|
"name": "Wholesale",
|
||||||
|
"active": false,
|
||||||
|
"promo": true,
|
||||||
|
"default": false,
|
||||||
|
"description": "Solo para ventas al mayoreo con mas de 10 articulos.",
|
||||||
|
"filterExpression": "order.quantity >= 1",
|
||||||
|
"geo": [
|
||||||
|
{
|
||||||
|
"country": "MX",
|
||||||
|
"regionId": "",
|
||||||
|
"region": "Todas las regiones",
|
||||||
|
"cityId": "",
|
||||||
|
"city": "All"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"groups": [],
|
||||||
|
"ordering": 990,
|
||||||
|
"currency": "MXN"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
data, st, err := c.PriceTypes()
|
data, st, err := c.PriceTypes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5247,6 +6024,13 @@ func TestClient_IntegrationModule(t *testing.T) {
|
||||||
ClientID: RandomString(10),
|
ClientID: RandomString(10),
|
||||||
Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg",
|
Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg",
|
||||||
Integrations: &Integrations{
|
Integrations: &Integrations{
|
||||||
|
MgBot: &MgBot{
|
||||||
|
RefreshToken: true,
|
||||||
|
},
|
||||||
|
MgTransport: &MgTransport{
|
||||||
|
WebhookURL: "https://loc.example.local/webhook",
|
||||||
|
RefreshToken: true,
|
||||||
|
},
|
||||||
Delivery: &Delivery{
|
Delivery: &Delivery{
|
||||||
StatusList: []DeliveryStatus{
|
StatusList: []DeliveryStatus{
|
||||||
{
|
{
|
||||||
|
@ -5476,6 +6260,7 @@ func TestClient_Products(t *testing.T) {
|
||||||
Get("/store/products").
|
Get("/store/products").
|
||||||
MatchParam("filter[active]", "1").
|
MatchParam("filter[active]", "1").
|
||||||
MatchParam("filter[minPrice]", "1").
|
MatchParam("filter[minPrice]", "1").
|
||||||
|
MatchParam("filter[urlLike]", "https://test.com/path/to/resource").
|
||||||
Reply(200).
|
Reply(200).
|
||||||
BodyString(`{"success": true}`)
|
BodyString(`{"success": true}`)
|
||||||
|
|
||||||
|
@ -5483,6 +6268,7 @@ func TestClient_Products(t *testing.T) {
|
||||||
Filter: ProductsFilter{
|
Filter: ProductsFilter{
|
||||||
Active: 1,
|
Active: 1,
|
||||||
MinPrice: 1,
|
MinPrice: 1,
|
||||||
|
URLLike: "https://test.com/path/to/resource",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5704,7 +6490,7 @@ func TestClient_Cost(t *testing.T) {
|
||||||
|
|
||||||
costs, status, err := c.Costs(CostsRequest{
|
costs, status, err := c.Costs(CostsRequest{
|
||||||
Filter: CostsFilter{
|
Filter: CostsFilter{
|
||||||
Ids: []string{strconv.Itoa(id)},
|
IDs: []int{id},
|
||||||
},
|
},
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
Page: 1,
|
Page: 1,
|
||||||
|
@ -7912,3 +8698,39 @@ func TestClient_EditMGChannelTemplate(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, statuses[code])
|
assert.True(t, statuses[code])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClient_StoreOffers(t *testing.T) {
|
||||||
|
cl := client()
|
||||||
|
|
||||||
|
gock.New(cl.URL).
|
||||||
|
Get(prefix+"/store/offers").
|
||||||
|
MatchParam("filter[active]", "1").
|
||||||
|
MatchParam("filter[ids][]", "76").
|
||||||
|
Reply(http.StatusOK).
|
||||||
|
JSON(getStoreOfferResponse())
|
||||||
|
|
||||||
|
a := 1
|
||||||
|
f := OffersRequest{OffersFilter{Ids: []int{76}, Active: &a}}
|
||||||
|
|
||||||
|
resp, status, err := cl.StoreOffers(f)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !statuses[status] {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.Success != true {
|
||||||
|
t.Errorf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Len(t, resp.Offers, 1)
|
||||||
|
assert.Equal(t, 76, resp.Offers[0].ID)
|
||||||
|
assert.Equal(t, "Название\nПеревод строки", resp.Offers[0].Name)
|
||||||
|
assert.Equal(t, 222, resp.Offers[0].Product.ID)
|
||||||
|
assert.Equal(t, "base", resp.Offers[0].Prices[0].PriceType)
|
||||||
|
assert.Equal(t, float32(10000), resp.Offers[0].Prices[0].Price)
|
||||||
|
assert.Equal(t, "RUB", resp.Offers[0].Prices[0].Currency)
|
||||||
|
}
|
||||||
|
|
2
error.go
2
error.go
|
@ -9,6 +9,8 @@ import (
|
||||||
|
|
||||||
var missingParameterMatcher = regexp.MustCompile(`^Parameter \'([\w\]\[\_\-]+)\' is missing$`)
|
var missingParameterMatcher = regexp.MustCompile(`^Parameter \'([\w\]\[\_\-]+)\' is missing$`)
|
||||||
var (
|
var (
|
||||||
|
// ErrRateLimited will be returned if request was rate limited.
|
||||||
|
ErrRateLimited = NewAPIError("rate limit exceeded")
|
||||||
// ErrMissingCredentials will be returned if no API key was provided to the API.
|
// ErrMissingCredentials will be returned if no API key was provided to the API.
|
||||||
ErrMissingCredentials = NewAPIError(`apiKey is missing`)
|
ErrMissingCredentials = NewAPIError(`apiKey is missing`)
|
||||||
// ErrInvalidCredentials will be returned if provided API key is invalid.
|
// ErrInvalidCredentials will be returned if provided API key is invalid.
|
||||||
|
|
40
filters.go
40
filters.go
|
@ -199,6 +199,7 @@ type OrdersFilter struct {
|
||||||
PaymentStatuses []string `url:"paymentStatuses,omitempty,brackets"`
|
PaymentStatuses []string `url:"paymentStatuses,omitempty,brackets"`
|
||||||
PaymentTypes []string `url:"paymentTypes,omitempty,brackets"`
|
PaymentTypes []string `url:"paymentTypes,omitempty,brackets"`
|
||||||
DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"`
|
DeliveryTypes []string `url:"deliveryTypes,omitempty,brackets"`
|
||||||
|
DeliveryServices []string `url:"deliveryServices,omitempty,brackets"`
|
||||||
OrderMethods []string `url:"orderMethods,omitempty,brackets"`
|
OrderMethods []string `url:"orderMethods,omitempty,brackets"`
|
||||||
ShipmentStores []string `url:"shipmentStores,omitempty,brackets"`
|
ShipmentStores []string `url:"shipmentStores,omitempty,brackets"`
|
||||||
Couriers []string `url:"couriers,omitempty,brackets"`
|
Couriers []string `url:"couriers,omitempty,brackets"`
|
||||||
|
@ -351,6 +352,7 @@ type ProductsFilter struct {
|
||||||
ExternalID string `url:"externalId,omitempty"`
|
ExternalID string `url:"externalId,omitempty"`
|
||||||
Manufacturer string `url:"manufacturer,omitempty"`
|
Manufacturer string `url:"manufacturer,omitempty"`
|
||||||
URL string `url:"url,omitempty"`
|
URL string `url:"url,omitempty"`
|
||||||
|
URLLike string `url:"urlLike,omitempty"`
|
||||||
PriceType string `url:"priceType,omitempty"`
|
PriceType string `url:"priceType,omitempty"`
|
||||||
OfferExternalID string `url:"offerExternalId,omitempty"`
|
OfferExternalID string `url:"offerExternalId,omitempty"`
|
||||||
Sites []string `url:"sites,omitempty,brackets"`
|
Sites []string `url:"sites,omitempty,brackets"`
|
||||||
|
@ -379,22 +381,22 @@ type ShipmentFilter struct {
|
||||||
|
|
||||||
// CostsFilter type.
|
// CostsFilter type.
|
||||||
type CostsFilter struct {
|
type CostsFilter struct {
|
||||||
MinSumm string `url:"minSumm,omitempty"`
|
MinSumm int `url:"minSumm,omitempty"`
|
||||||
MaxSumm string `url:"maxSumm,omitempty"`
|
MaxSumm int `url:"maxSumm,omitempty"`
|
||||||
OrderNumber string `url:"orderNumber,omitempty"`
|
OrderNumber string `url:"orderNumber,omitempty"`
|
||||||
Comment string `url:"orderNumber,omitempty"`
|
Comment string `url:"orderNumber,omitempty"`
|
||||||
Ids []string `url:"ids,omitempty,brackets"`
|
IDs []int `url:"ids,omitempty,brackets"`
|
||||||
Sites []string `url:"sites,omitempty,brackets"`
|
Sites []string `url:"sites,omitempty,brackets"`
|
||||||
CreatedBy []string `url:"createdBy,omitempty,brackets"`
|
CreatedBy []int `url:"createdBy,omitempty,brackets"`
|
||||||
CostGroups []string `url:"costGroups,omitempty,brackets"`
|
CostGroups []string `url:"costGroups,omitempty,brackets"`
|
||||||
CostItems []string `url:"costItems,omitempty,brackets"`
|
CostItems []string `url:"costItems,omitempty,brackets"`
|
||||||
Users []string `url:"users,omitempty,brackets"`
|
Users []int `url:"users,omitempty,brackets"`
|
||||||
DateFrom string `url:"dateFrom,omitempty"`
|
DateFrom string `url:"dateFrom,omitempty"`
|
||||||
DateTo string `url:"dateTo,omitempty"`
|
DateTo string `url:"dateTo,omitempty"`
|
||||||
CreatedAtFrom string `url:"createdAtFrom,omitempty"`
|
CreatedAtFrom string `url:"createdAtFrom,omitempty"`
|
||||||
CreatedAtTo string `url:"createdAtTo,omitempty"`
|
CreatedAtTo string `url:"createdAtTo,omitempty"`
|
||||||
OrderIds []string `url:"orderIds,omitempty,brackets"`
|
OrderIDs []int `url:"orderIds,omitempty,brackets"`
|
||||||
OrderExternalIds []string `url:"orderIds,omitempty,brackets"`
|
OrderExternalIDs []string `url:"orderExternalIds,omitempty,brackets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilesFilter type.
|
// FilesFilter type.
|
||||||
|
@ -448,8 +450,8 @@ type LoyaltyAccountAPIFilter struct {
|
||||||
ID string `url:"id,omitempty"`
|
ID string `url:"id,omitempty"`
|
||||||
Status string `url:"status,,omitempty"`
|
Status string `url:"status,,omitempty"`
|
||||||
Customer string `url:"customer,omitempty"`
|
Customer string `url:"customer,omitempty"`
|
||||||
MinOrderSum string `url:"minOrderSum,omitempty"`
|
MinOrderSum string `url:"minOrdersSum,omitempty"`
|
||||||
MaxOrderSum string `url:"maxOrderSum,omitempty"`
|
MaxOrderSum string `url:"maxOrdersSum,omitempty"`
|
||||||
MinAmount string `url:"minAmount,omitempty"`
|
MinAmount string `url:"minAmount,omitempty"`
|
||||||
MaxAmount string `url:"maxAmount,omitempty"`
|
MaxAmount string `url:"maxAmount,omitempty"`
|
||||||
PhoneNumber string `url:"phoneNumber,omitempty"`
|
PhoneNumber string `url:"phoneNumber,omitempty"`
|
||||||
|
@ -473,3 +475,23 @@ type LoyaltyAPIFilter struct {
|
||||||
Ids []int `url:"ids,omitempty,brackets"`
|
Ids []int `url:"ids,omitempty,brackets"`
|
||||||
Sites []string `url:"sites,omitempty,brackets"`
|
Sites []string `url:"sites,omitempty,brackets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OffersFilter struct {
|
||||||
|
Ids []int `url:"ids,omitempty,brackets"`
|
||||||
|
Active *int `url:"active,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SiteFilter struct {
|
||||||
|
// SiteBy contains information about what is betrayed site id or site code.
|
||||||
|
// id|code, default is code.
|
||||||
|
SiteBy string `url:"siteBy,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetCartFilter struct {
|
||||||
|
// SiteBy contains information about what is betrayed site id or site code.
|
||||||
|
// id|code, default is code.
|
||||||
|
SiteBy string `url:"siteBy,omitempty"`
|
||||||
|
// By contains information about what is betrayed: customer id or customer externalId.
|
||||||
|
// id|externalId, default is externalId.
|
||||||
|
By string `url:"by,omitempty"`
|
||||||
|
}
|
||||||
|
|
24
request.go
24
request.go
|
@ -194,6 +194,22 @@ type DeliveryShipmentsRequest struct {
|
||||||
Page int `url:"page,omitempty"`
|
Page int `url:"page,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearCartRequest type.
|
||||||
|
type ClearCartRequest struct {
|
||||||
|
ClearedAt string `url:"clearedAt,omitempty"`
|
||||||
|
Customer CartCustomer `url:"customer,omitempty"`
|
||||||
|
Order ClearCartOrder `url:"order,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCartRequest type.
|
||||||
|
type SetCartRequest struct {
|
||||||
|
ExternalID string `url:"externalId,omitempty"`
|
||||||
|
DroppedAt string `url:"droppedAt,omitempty"`
|
||||||
|
Link string `url:"link,omitempty"`
|
||||||
|
Customer CartCustomer `url:"customer,omitempty"`
|
||||||
|
Items []SetCartItem `url:"items,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// CostsRequest type.
|
// CostsRequest type.
|
||||||
type CostsRequest struct {
|
type CostsRequest struct {
|
||||||
Filter CostsFilter `url:"filter,omitempty"`
|
Filter CostsFilter `url:"filter,omitempty"`
|
||||||
|
@ -249,7 +265,7 @@ type AccountBonusOperationsRequest struct {
|
||||||
type LoyaltyBonusCreditRequest struct {
|
type LoyaltyBonusCreditRequest struct {
|
||||||
Amount float64 `url:"amount"`
|
Amount float64 `url:"amount"`
|
||||||
ActivationDate string `url:"activationDate,omitempty"`
|
ActivationDate string `url:"activationDate,omitempty"`
|
||||||
ExpiredDate string `url:"expiredDate,omitempty"`
|
ExpiredDate string `url:"expireDate,omitempty"`
|
||||||
Comment string `url:"comment,omitempty"`
|
Comment string `url:"comment,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +277,7 @@ type LoyaltyBonusStatusDetailsRequest struct {
|
||||||
|
|
||||||
type LoyaltyAccountsRequest struct {
|
type LoyaltyAccountsRequest struct {
|
||||||
Limit int `url:"limit,omitempty"`
|
Limit int `url:"limit,omitempty"`
|
||||||
Page int `url:"limit,omitempty"`
|
Page int `url:"page,omitempty"`
|
||||||
Filter LoyaltyAccountAPIFilter `url:"filter,omitempty"`
|
Filter LoyaltyAccountAPIFilter `url:"filter,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,3 +326,7 @@ func (r ConnectRequest) Verify(secret string) bool {
|
||||||
}
|
}
|
||||||
return hmac.Equal([]byte(r.Token), []byte(hex.EncodeToString(mac.Sum(nil))))
|
return hmac.Equal([]byte(r.Token), []byte(hex.EncodeToString(mac.Sum(nil))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OffersRequest struct {
|
||||||
|
OffersFilter `url:"filter,omitempty"`
|
||||||
|
}
|
||||||
|
|
40
response.go
40
response.go
|
@ -407,6 +407,12 @@ type ProductsPropertiesResponse struct {
|
||||||
Properties []Property `json:"properties,omitempty"`
|
Properties []Property `json:"properties,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CartResponse type.
|
||||||
|
type CartResponse struct {
|
||||||
|
SuccessfulResponse
|
||||||
|
Cart Cart `json:"cart"`
|
||||||
|
}
|
||||||
|
|
||||||
// DeliveryShipmentsResponse type.
|
// DeliveryShipmentsResponse type.
|
||||||
type DeliveryShipmentsResponse struct {
|
type DeliveryShipmentsResponse struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
|
@ -596,6 +602,34 @@ type AccountBonusOperationsResponse struct {
|
||||||
BonusOperations []BonusOperation `json:"bonusOperations,omitempty"`
|
BonusOperations []BonusOperation `json:"bonusOperations,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientIDResponse type.
|
||||||
|
type ClientIDResponse struct {
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
Errors map[string]string `json:"errors,omitempty"`
|
||||||
|
FailedClientIds []ClientID `json:"failed_client_ids,omitempty"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SourcesResponse type.
|
||||||
|
type SourcesResponse struct {
|
||||||
|
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||||
|
Errors map[string]string `json:"errors,omitempty"`
|
||||||
|
FailedSources []Source `json:"failed_sources,omitempty"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CurrencyResponse type.
|
||||||
|
type CurrencyResponse struct {
|
||||||
|
Currencies []Currency `json:"currencies,omitempty"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CurrencyCreateResponse type.
|
||||||
|
type CurrencyCreateResponse struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type LoyaltyAccountResponse struct {
|
type LoyaltyAccountResponse struct {
|
||||||
SuccessfulResponse
|
SuccessfulResponse
|
||||||
LoyaltyAccount `json:"loyaltyAccount"`
|
LoyaltyAccount `json:"loyaltyAccount"`
|
||||||
|
@ -657,3 +691,9 @@ type MGChannelTemplatesResponse struct {
|
||||||
Templates []MGChannelTemplate `json:"templates"`
|
Templates []MGChannelTemplate `json:"templates"`
|
||||||
SuccessfulResponse
|
SuccessfulResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StoreOffersResponse struct {
|
||||||
|
Pagination *Pagination `json:"pagination"`
|
||||||
|
SuccessfulResponse
|
||||||
|
Offers []Offer `json:"offers,omitempty"`
|
||||||
|
}
|
||||||
|
|
30
system_time.go
Normal file
30
system_time.go
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
package retailcrm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SystemTime time.Time
|
||||||
|
|
||||||
|
const systemTimeLayout = "2006-01-02 15:04:05"
|
||||||
|
|
||||||
|
// UnmarshalJSON parses time.Time from system format.
|
||||||
|
func (st *SystemTime) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
s := strings.Trim(string(b), `"`)
|
||||||
|
nt, err := time.Parse(systemTimeLayout, s)
|
||||||
|
*st = SystemTime(nt)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON will marshal time.Time to system format.
|
||||||
|
func (st SystemTime) MarshalJSON() ([]byte, error) {
|
||||||
|
return []byte(st.String()), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the time in the custom format.
|
||||||
|
func (st *SystemTime) String() string {
|
||||||
|
t := time.Time(*st)
|
||||||
|
return fmt.Sprintf("%q", t.Format(systemTimeLayout))
|
||||||
|
}
|
44
testutils.go
44
testutils.go
|
@ -519,3 +519,47 @@ func getMGTemplatesResponse() string {
|
||||||
func getMGTemplatesForEdit() string {
|
func getMGTemplatesForEdit() string {
|
||||||
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]`
|
return `[{"header":{"text":{"parts":["Hello,",{"var":"custom"}],"example":["Henry"]},"document":{"example":"https://example.com/file/123.pdf"},"image":{"example":"https://example.com/file/123.png"},"video":{"example":"https://example.com/file/123.mp4"}},"lang":"en","category":"test_0","code":"namespace#name_0#ru","name":"name_0","namespace":"namespace","footer":"footer_0","verificationStatus":"REJECTED","template":["Text_0",{"var":"custom"}],"buttons":[{"type":"PHONE_NUMBER","text":"your-phone-button-text","phoneNumber":"+79895553535"},{"type":"QUICK_REPLY","text":"Yes"},{"type":"URL","url":"https://example.com/file/{{1}}","text":"button","example":["https://www.website.com/dynamic-url-example"]}],"templateExample":["WIU"],"id":1,"externalId":10,"mgChannelId":110,"active":true}]`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStoreOfferResponse() string {
|
||||||
|
return `{
|
||||||
|
"success": true,
|
||||||
|
"pagination": {
|
||||||
|
"limit": 20,
|
||||||
|
"totalCount": 1,
|
||||||
|
"currentPage": 1,
|
||||||
|
"totalPageCount": 1
|
||||||
|
},
|
||||||
|
"offers": [
|
||||||
|
{
|
||||||
|
"images": [
|
||||||
|
"https://s3-s1.retailcrm.tech/ru-central1/retailcrm/dev-vega-d32aea7f9a5bc26eba6ad986077cea03/product/65a92fa0bb737-test.jpeg"
|
||||||
|
],
|
||||||
|
"id": 76,
|
||||||
|
"site": "main",
|
||||||
|
"name": "Название\nПеревод строки",
|
||||||
|
"article": "Артикул",
|
||||||
|
"product": {
|
||||||
|
"type": "product",
|
||||||
|
"catalogId": 2,
|
||||||
|
"id": 222
|
||||||
|
},
|
||||||
|
"prices": [
|
||||||
|
{
|
||||||
|
"priceType": "base",
|
||||||
|
"price": 10000,
|
||||||
|
"ordering": 991,
|
||||||
|
"currency": "RUB"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"purchasePrice": 10,
|
||||||
|
"quantity": 5,
|
||||||
|
"active": true,
|
||||||
|
"unit": {
|
||||||
|
"code": "pc",
|
||||||
|
"name": "Штука",
|
||||||
|
"sym": "шт."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
|
256
types.go
256
types.go
|
@ -5,14 +5,28 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ByID is "id" constant to use as `by` property in methods.
|
// ByID is "id" constant to use as `by` property in methods.
|
||||||
const ByID = "id"
|
const ByID = "id"
|
||||||
|
|
||||||
// ByExternalId is "externalId" constant to use as `by` property in methods.
|
// ByExternalID is "externalId" constant to use as `by` property in methods.
|
||||||
const ByExternalID = "externalId"
|
const ByExternalID = "externalId"
|
||||||
|
|
||||||
|
// RateLimiter configuration constants.
|
||||||
|
const (
|
||||||
|
regularPathRPS = 10 // API rate limit (requests per second).
|
||||||
|
telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).
|
||||||
|
regularDelay = time.Second / regularPathRPS // Delay between regular requests.
|
||||||
|
telephonyDelay = time.Second / telephonyPathRPS // Delay between telephony requests.
|
||||||
|
)
|
||||||
|
|
||||||
|
// HTTPStatusUnknown can return for the method `/api/v5/customers/upload`, `/api/v5/customers-corporate/upload`,
|
||||||
|
// `/api/v5/orders/upload`.
|
||||||
|
const HTTPStatusUnknown = 460
|
||||||
|
|
||||||
// Client type.
|
// Client type.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
URL string
|
URL string
|
||||||
|
@ -20,6 +34,15 @@ type Client struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
logger BasicLogger
|
logger BasicLogger
|
||||||
|
limiter *RateLimiter
|
||||||
|
mutex sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// RateLimiter manages API request rates to prevent hitting rate limits.
|
||||||
|
type RateLimiter struct {
|
||||||
|
maxAttempts uint // Maximum number of retry attempts (0 = infinite).
|
||||||
|
lastRequest time.Time // Time of the last request.
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pagination type.
|
// Pagination type.
|
||||||
|
@ -53,22 +76,29 @@ type Address struct {
|
||||||
Text string `json:"text,omitempty"`
|
Text string `json:"text,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GeoID type. Can be empty string.
|
||||||
|
type GeoID json.Number
|
||||||
|
|
||||||
// GeoHierarchyRow type.
|
// GeoHierarchyRow type.
|
||||||
type GeoHierarchyRow struct {
|
type GeoHierarchyRow struct {
|
||||||
Country string `json:"country,omitempty"`
|
Country string `json:"country,omitempty"`
|
||||||
Region string `json:"region,omitempty"`
|
Region string `json:"region,omitempty"`
|
||||||
RegionID int `json:"regionId,omitempty"`
|
RegionID GeoID `json:"regionId,omitempty"`
|
||||||
City string `json:"city,omitempty"`
|
City string `json:"city,omitempty"`
|
||||||
CityID int `json:"cityId,omitempty"`
|
CityID GeoID `json:"cityId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source type.
|
// Source type.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Source string `json:"source,omitempty"`
|
Source string `json:"source,omitempty"`
|
||||||
Medium string `json:"medium,omitempty"`
|
Medium string `json:"medium,omitempty"`
|
||||||
Campaign string `json:"campaign,omitempty"`
|
Campaign string `json:"campaign,omitempty"`
|
||||||
Keyword string `json:"keyword,omitempty"`
|
Keyword string `json:"keyword,omitempty"`
|
||||||
Content string `json:"content,omitempty"`
|
Content string `json:"content,omitempty"`
|
||||||
|
ClientID string `json:"client_id,omitempty"`
|
||||||
|
Site string `json:"site,omitempty"`
|
||||||
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
|
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contragent type.
|
// Contragent type.
|
||||||
|
@ -217,6 +247,15 @@ type CorporateCustomerContactCustomer struct {
|
||||||
Site string `json:"site,omitempty"`
|
Site string `json:"site,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CartCustomer type.
|
||||||
|
type CartCustomer struct {
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ExternalID string `json:"externalId,omitempty"`
|
||||||
|
Site string `json:"site,omitempty"`
|
||||||
|
BrowserID string `json:"browserId,omitempty"`
|
||||||
|
GaClientID string `json:"gaClientId,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type Company struct {
|
type Company struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
IsMain bool `json:"isMain,omitempty"`
|
IsMain bool `json:"isMain,omitempty"`
|
||||||
|
@ -344,6 +383,56 @@ type Order struct {
|
||||||
ApplyRound *bool `json:"applyRound,omitempty"`
|
ApplyRound *bool `json:"applyRound,omitempty"`
|
||||||
PrivilegeType string `json:"privilegeType,omitempty"`
|
PrivilegeType string `json:"privilegeType,omitempty"`
|
||||||
DialogID int `json:"dialogId,omitempty"`
|
DialogID int `json:"dialogId,omitempty"`
|
||||||
|
Links []OrderLink `json:"links,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LinkedOrder type.
|
||||||
|
type LinkedOrder struct {
|
||||||
|
Number string `json:"number,omitempty"`
|
||||||
|
ExternalID string `json:"externalID,omitempty"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OrderLink type.
|
||||||
|
type OrderLink struct {
|
||||||
|
Comment string `json:"comment,omitempty"`
|
||||||
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SerializedOrderLink type.
|
||||||
|
type SerializedOrderLink struct {
|
||||||
|
Comment string `json:"comment,omitempty"`
|
||||||
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
|
Orders []LinkedOrder `json:"orders,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearCartOrder type.
|
||||||
|
type ClearCartOrder struct {
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ExternalID string `json:"externalID,omitempty"`
|
||||||
|
Number string `json:"number,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientID type.
|
||||||
|
type ClientID struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
CreateAt string `json:"createAt,omitempty"`
|
||||||
|
Site string `json:"site,omitempty"`
|
||||||
|
Customer SerializedEntityCustomer `json:"customer,omitempty"`
|
||||||
|
Order LinkedOrder `json:"order,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currency type.
|
||||||
|
type Currency struct {
|
||||||
|
Code string `json:"code,omitempty"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ManualConvertNominal int `json:"manualConvertNominal,omitempty"`
|
||||||
|
AutoConvertExtraPercent int `json:"autoConvertExtraPercent,omitempty"`
|
||||||
|
IsBase bool `json:"isBase,omitempty"`
|
||||||
|
IsAutoConvert bool `json:"isAutoConvert,omitempty"`
|
||||||
|
ManualConvertValue float32 `json:"manualConvertValue,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrdersStatus type.
|
// OrdersStatus type.
|
||||||
|
@ -396,6 +485,59 @@ type OrderDeliveryData struct {
|
||||||
AdditionalFields map[string]interface{}
|
AdditionalFields map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetCartItem type.
|
||||||
|
type SetCartItem struct {
|
||||||
|
Quantity float64 `json:"quantity,omitempty"`
|
||||||
|
Price float64 `json:"price,omitempty"`
|
||||||
|
Offer SetCartOffer `json:"offer,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCartOffer type.
|
||||||
|
type SetCartOffer struct {
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ExternalID string `json:"externalID,omitempty"`
|
||||||
|
XMLID string `json:"xmlId,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cart type.
|
||||||
|
type Cart struct {
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
|
ExternalID string `json:"externalId,omitempty"`
|
||||||
|
DroppedAt string `json:"droppedAt,omitempty"`
|
||||||
|
ClearedAt string `json:"clearedAt,omitempty"`
|
||||||
|
Link string `json:"link,omitempty"`
|
||||||
|
Items []CartItem `json:"items,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CartItem type.
|
||||||
|
type CartItem struct {
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
Quantity float64 `json:"quantity,omitempty"`
|
||||||
|
Price float64 `json:"price,omitempty"`
|
||||||
|
Offer CartOffer `json:"offer,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CartOffer type.
|
||||||
|
type CartOffer struct {
|
||||||
|
DisplayName string `json:"displayName,omitempty"`
|
||||||
|
ID int `json:"id,omitempty"`
|
||||||
|
ExternalID string `json:"externalId,omitempty"`
|
||||||
|
XMLID string `json:"xmlId,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Article string `json:"article,omitempty"`
|
||||||
|
VatRate string `json:"vatRate,omitempty"`
|
||||||
|
Properties StringMap `json:"properties,omitempty"`
|
||||||
|
Unit CartUnit `json:"unit,omitempty"`
|
||||||
|
Barcode string `json:"barcode,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CartUnit type.
|
||||||
|
type CartUnit struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Sym string `json:"sym"`
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalJSON method.
|
// UnmarshalJSON method.
|
||||||
func (v *OrderDeliveryData) UnmarshalJSON(b []byte) error {
|
func (v *OrderDeliveryData) UnmarshalJSON(b []byte) error {
|
||||||
var additionalData map[string]interface{}
|
var additionalData map[string]interface{}
|
||||||
|
@ -551,6 +693,7 @@ type Offer struct {
|
||||||
Prices []OfferPrice `json:"prices,omitempty"`
|
Prices []OfferPrice `json:"prices,omitempty"`
|
||||||
Images []string `json:"images,omitempty"`
|
Images []string `json:"images,omitempty"`
|
||||||
Unit *Unit `json:"unit,omitempty"`
|
Unit *Unit `json:"unit,omitempty"`
|
||||||
|
Product *Product `json:"product,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inventory type.
|
// Inventory type.
|
||||||
|
@ -580,6 +723,7 @@ type OfferPrice struct {
|
||||||
Price float32 `json:"price,omitempty"`
|
Price float32 `json:"price,omitempty"`
|
||||||
Ordering int `json:"ordering,omitempty"`
|
Ordering int `json:"ordering,omitempty"`
|
||||||
PriceType string `json:"priceType,omitempty"`
|
PriceType string `json:"priceType,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OfferPriceUpload type.
|
// OfferPriceUpload type.
|
||||||
|
@ -619,6 +763,7 @@ type User struct {
|
||||||
CreatedAt string `json:"createdAt,omitempty"`
|
CreatedAt string `json:"createdAt,omitempty"`
|
||||||
Active bool `json:"active,omitempty"`
|
Active bool `json:"active,omitempty"`
|
||||||
Online bool `json:"online,omitempty"`
|
Online bool `json:"online,omitempty"`
|
||||||
|
Position string `json:"position,omitempty"`
|
||||||
IsAdmin bool `json:"isAdmin,omitempty"`
|
IsAdmin bool `json:"isAdmin,omitempty"`
|
||||||
IsManager bool `json:"isManager,omitempty"`
|
IsManager bool `json:"isManager,omitempty"`
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
|
@ -832,6 +977,7 @@ type DeliveryType struct {
|
||||||
DeliveryServices []string `json:"deliveryServices,omitempty"`
|
DeliveryServices []string `json:"deliveryServices,omitempty"`
|
||||||
PaymentTypes []string `json:"paymentTypes,omitempty"` // Deprecated, use DeliveryPaymentTypes
|
PaymentTypes []string `json:"paymentTypes,omitempty"` // Deprecated, use DeliveryPaymentTypes
|
||||||
DeliveryPaymentTypes []DeliveryPaymentType `json:"deliveryPaymentTypes,omitempty"`
|
DeliveryPaymentTypes []DeliveryPaymentType `json:"deliveryPaymentTypes,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeliveryPaymentType struct {
|
type DeliveryPaymentType struct {
|
||||||
|
@ -862,8 +1008,8 @@ type LegalEntity struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SerializedEntityCustomer struct {
|
type SerializedEntityCustomer struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
ExternalID int `json:"externalId,omitempty"`
|
ExternalID string `json:"externalId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderMethod type.
|
// OrderMethod type.
|
||||||
|
@ -921,6 +1067,7 @@ type PriceType struct {
|
||||||
Ordering int `json:"ordering,omitempty"`
|
Ordering int `json:"ordering,omitempty"`
|
||||||
Groups []string `json:"groups,omitempty"`
|
Groups []string `json:"groups,omitempty"`
|
||||||
Geo []GeoHierarchyRow `json:"geo,omitempty"`
|
Geo []GeoHierarchyRow `json:"geo,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProductStatus type.
|
// ProductStatus type.
|
||||||
|
@ -974,6 +1121,7 @@ type Site struct {
|
||||||
IsDemo bool `json:"isDemo,omitempty"`
|
IsDemo bool `json:"isDemo,omitempty"`
|
||||||
CatalogID string `json:"catalogId,omitempty"`
|
CatalogID string `json:"catalogId,omitempty"`
|
||||||
IsCatalogMainSite bool `json:"isCatalogMainSite,omitempty"`
|
IsCatalogMainSite bool `json:"isCatalogMainSite,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store type.
|
// Store type.
|
||||||
|
@ -1005,24 +1153,33 @@ type ProductGroup struct {
|
||||||
|
|
||||||
// BaseProduct type.
|
// BaseProduct type.
|
||||||
type BaseProduct struct {
|
type BaseProduct struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
URL string `json:"url,omitempty"`
|
Type ProductType `json:"type,omitempty"`
|
||||||
Article string `json:"article,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
ExternalID string `json:"externalId,omitempty"`
|
Article string `json:"article,omitempty"`
|
||||||
Manufacturer string `json:"manufacturer,omitempty"`
|
ExternalID string `json:"externalId,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Manufacturer string `json:"manufacturer,omitempty"`
|
||||||
Popular bool `json:"popular,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Stock bool `json:"stock,omitempty"`
|
Popular bool `json:"popular,omitempty"`
|
||||||
Novelty bool `json:"novelty,omitempty"`
|
Stock bool `json:"stock,omitempty"`
|
||||||
Recommended bool `json:"recommended,omitempty"`
|
Novelty bool `json:"novelty,omitempty"`
|
||||||
Active bool `json:"active,omitempty"`
|
Recommended bool `json:"recommended,omitempty"`
|
||||||
Markable bool `json:"markable,omitempty"`
|
Active bool `json:"active,omitempty"`
|
||||||
|
Markable bool `json:"markable,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProductType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
RegularProduct ProductType = "product"
|
||||||
|
ServiceProduct ProductType = "service"
|
||||||
|
)
|
||||||
|
|
||||||
// Product type.
|
// Product type.
|
||||||
type Product struct {
|
type Product struct {
|
||||||
BaseProduct
|
BaseProduct
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
|
Type ProductType `json:"type"`
|
||||||
MaxPrice float32 `json:"maxPrice,omitempty"`
|
MaxPrice float32 `json:"maxPrice,omitempty"`
|
||||||
MinPrice float32 `json:"minPrice,omitempty"`
|
MinPrice float32 `json:"minPrice,omitempty"`
|
||||||
ImageURL string `json:"imageUrl,omitempty"`
|
ImageURL string `json:"imageUrl,omitempty"`
|
||||||
|
@ -1193,11 +1350,21 @@ type Action struct {
|
||||||
|
|
||||||
// MgTransport type.
|
// MgTransport type.
|
||||||
type MgTransport struct {
|
type MgTransport struct {
|
||||||
WebhookURL string `json:"webhookUrl,omitempty"`
|
WebhookURL string `json:"webhookUrl,omitempty"`
|
||||||
|
RefreshToken bool `json:"refreshToken,omitempty"`
|
||||||
|
Actions *MgTransportActions `json:"actions,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MgTransportActions struct {
|
||||||
|
Visits string `json:"visits,omitempty"`
|
||||||
|
Online string `json:"online,omitempty"`
|
||||||
|
ManualTemplatesSync string `json:"manualTemplatesSync,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MgBot type.
|
// MgBot type.
|
||||||
type MgBot struct{}
|
type MgBot struct {
|
||||||
|
RefreshToken bool `json:"refreshToken,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Cost related types
|
Cost related types
|
||||||
|
@ -1291,6 +1458,45 @@ type Activity struct {
|
||||||
Freeze bool `json:"freeze"`
|
Freeze bool `json:"freeze"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ChatCustomerOnline struct {
|
||||||
|
LastOnline SystemTime `json:"lastOnline"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatVisitsResponse struct {
|
||||||
|
UTM *ChatUTM `json:"utm,omitempty"`
|
||||||
|
Device ChatDevice `json:"device"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
City string `json:"city"`
|
||||||
|
LastVisit ChatLastVisit `json:"lastVisit"`
|
||||||
|
CountVisits uint `json:"countVisits"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatLastVisit struct {
|
||||||
|
CreatedAt SystemTime `json:"createdAt"`
|
||||||
|
EndedAt *SystemTime `json:"endedAt,omitempty"`
|
||||||
|
Source string `json:"source"`
|
||||||
|
Pages []ChatVisitedPage `json:"pages"`
|
||||||
|
Duration uint `json:"duration"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatVisitedPage struct {
|
||||||
|
DateTime SystemTime `json:"dateTime"`
|
||||||
|
Title string `json:"title,omitempty"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatDevice struct {
|
||||||
|
Lang string `json:"lang"`
|
||||||
|
Browser string `json:"browser"`
|
||||||
|
OS string `json:"os"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ChatUTM struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Medium string `json:"medium"`
|
||||||
|
Campaign string `json:"campaign"`
|
||||||
|
}
|
||||||
|
|
||||||
// Tag struct.
|
// Tag struct.
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
@ -1381,6 +1587,7 @@ type Loyalty struct {
|
||||||
ActivatedAt string `json:"activatedAt,omitempty"`
|
ActivatedAt string `json:"activatedAt,omitempty"`
|
||||||
DeactivatedAt string `json:"deactivatedAt,omitempty"`
|
DeactivatedAt string `json:"deactivatedAt,omitempty"`
|
||||||
BlockedAt string `json:"blockedAt,omitempty"`
|
BlockedAt string `json:"blockedAt,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoyaltyLevel type.
|
// LoyaltyLevel type.
|
||||||
|
@ -1424,6 +1631,7 @@ type SerializedLoyaltyOrder struct {
|
||||||
Delivery Delivery `json:"delivery,omitempty"`
|
Delivery Delivery `json:"delivery,omitempty"`
|
||||||
Site string `json:"site,omitempty"`
|
Site string `json:"site,omitempty"`
|
||||||
Items []LoyaltyItems `json:"items,omitempty"`
|
Items []LoyaltyItems `json:"items,omitempty"`
|
||||||
|
Currency string `json:"currency,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoyaltyEventDiscount struct {
|
type LoyaltyEventDiscount struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue