mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-24 22:06:03 +03:00
Add/edit methods
add `/api/v5/store/products/batch/create`, `/api/v5/store/products/batch/edit` add fields `isError` and `isPreprocessing` for statuses of integration delivery add field `deliveryType` for response of creating integration module with inegration delivery add `/api/v5/loyalty/account/create`, `/api/v5/loyalty/account/{id}`, `/api/v5/loyalty/account/{id}/edit` add `/api/v5/loyalty/account/{id}/activate`, `/api/v5/loyalty/account/{id}/bonus/credit` add `/api/v5/loyalty/account/{id}/bonus/{status}/details`
This commit is contained in:
parent
2f6ab28d85
commit
921d4c1295
444
client_test.go
444
client_test.go
@ -3,6 +3,7 @@ package retailcrm
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/google/go-querystring/query"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
@ -21,6 +22,8 @@ import (
|
||||
gock "gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
const prefix = "/api/v5"
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
err := godotenv.Load(".env")
|
||||
if err != nil {
|
||||
@ -5124,6 +5127,26 @@ func TestClient_IntegrationModule(t *testing.T) {
|
||||
BaseURL: fmt.Sprintf("http://example.com/%s", name),
|
||||
ClientID: RandomString(10),
|
||||
Logo: "https://cdn.worldvectorlogo.com/logos/github-icon.svg",
|
||||
Integrations: &Integrations{
|
||||
Delivery: &Delivery{
|
||||
StatusList: []DeliveryStatus{
|
||||
{
|
||||
Code: "st1",
|
||||
Name: "st1",
|
||||
IsEditable: true,
|
||||
IsError: true,
|
||||
IsPreprocessing: false,
|
||||
},
|
||||
{
|
||||
Code: "st2",
|
||||
Name: "st2",
|
||||
IsEditable: false,
|
||||
IsError: false,
|
||||
IsPreprocessing: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
jsonData := fmt.Sprintf(
|
||||
@ -5140,7 +5163,24 @@ func TestClient_IntegrationModule(t *testing.T) {
|
||||
MatchType("url").
|
||||
BodyString(pr.Encode()).
|
||||
Reply(201).
|
||||
BodyString(`{"success": true}`)
|
||||
BodyString(`{
|
||||
"success": true,
|
||||
"info": {
|
||||
"deliveryType": {
|
||||
"id": 38,
|
||||
"code": "sdek-v-2-podkliuchenie-1"
|
||||
},
|
||||
"billingInfo": {
|
||||
"price": 0,
|
||||
"currency": {
|
||||
"name": "Рубль",
|
||||
"shortName": "руб.",
|
||||
"code": "RUB"
|
||||
},
|
||||
"billingType": "fixed"
|
||||
}
|
||||
}
|
||||
}`)
|
||||
|
||||
m, status, err := c.IntegrationModuleEdit(integrationModule)
|
||||
if err != nil {
|
||||
@ -6803,25 +6843,144 @@ func TestClient_AccountBonusOperations_Fail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Проверить реально запросы
|
||||
func TestClient_ProductsBatchCreate(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
products := getProductsCreate()
|
||||
productsJSON, err := json.Marshal(getProductsCreate())
|
||||
productsJSON, err := json.Marshal(products)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := url.Values{"products": {string(productsJSON)}}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post("/store/products/batch/create").
|
||||
Post(prefix + "/store/products/batch/create").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getProductsCreateResponse())
|
||||
|
||||
resp, status, err := client().ProductsBatchCreate(products)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if resp.Success != true || resp.ProcessedProductsCount == 0 {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_ProductsBatchCreateFail(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
products := getProductsCreate()
|
||||
productsJSON, err := json.Marshal(products)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := url.Values{"products": {string(productsJSON)}}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + "/store/products/batch/create").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusBadRequest).
|
||||
JSON(`{"success":false,"errorMsg":"Something went wrong"}`)
|
||||
|
||||
resp, status, err := client().ProductsBatchCreate(products)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
if status < http.StatusBadRequest {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if resp.Success != false {
|
||||
t.Error(successFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_ProductsBatchEdit(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
products := getProductsEdit()
|
||||
productsJSON, err := json.Marshal(products)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := url.Values{"products": {string(productsJSON)}}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + "/store/products/batch/edit").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getProductsEditResponse())
|
||||
|
||||
resp, status, err := client().ProductsBatchEdit(products)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if resp.Success != true || resp.ProcessedProductsCount == 0 {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_ProductsBatchEditFail(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
products := getProductsEdit()
|
||||
productsJSON, err := json.Marshal(products)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := url.Values{"products": {string(productsJSON)}}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + "/store/products/batch/edit").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusInternalServerError).
|
||||
JSON(`{"success":false,"errorMsg":"Something went wrong"}`)
|
||||
|
||||
resp, status, err := client().ProductsBatchEdit(products)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
if status != http.StatusInternalServerError {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if resp.Success != false {
|
||||
t.Error(successFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccountCreate(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
acc := getLoyaltyAccountCreate()
|
||||
accJSON, _ := json.Marshal(acc)
|
||||
p := url.Values{
|
||||
"site": {"second"},
|
||||
"loyaltyAccount": {string(accJSON)},
|
||||
}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + "/loyalty/account/create").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getLoyaltyAccountCreateResponse())
|
||||
|
||||
resp, status, err := client().LoyaltyAccountCreate("second", acc)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
@ -6834,3 +6993,280 @@ func TestClient_ProductsBatchCreate(t *testing.T) {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccountCreateFail(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
acc := getLoyaltyAccountCreate()
|
||||
accJSON, _ := json.Marshal(acc)
|
||||
p := url.Values{
|
||||
"site": {"second"},
|
||||
"loyaltyAccount": {string(accJSON)},
|
||||
}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post("/loyalty/account/create").
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusInternalServerError).
|
||||
JSON(`{"success":false,"errorMsg":"Something went wrong"}`)
|
||||
|
||||
resp, status, err := client().LoyaltyAccountCreate("second", acc)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
if status != http.StatusInternalServerError {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if resp.Success != false {
|
||||
t.Error(successFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccountEdit(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
acc := getLoyaltyAccountCreate()
|
||||
acc.PhoneNumber = "89142221020"
|
||||
req := SerializedEditLoyaltyAccount{acc.SerializedBaseLoyaltyAccount}
|
||||
reqJSON, _ := json.Marshal(req)
|
||||
p := url.Values{
|
||||
"loyaltyAccount": {string(reqJSON)},
|
||||
}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/loyalty/account/%d/edit", 13)).
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getLoyaltyAccountEditResponse())
|
||||
|
||||
res, status, err := client().LoyaltyAccountEdit(13, req)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != true {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccountEditFail(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
acc := getLoyaltyAccountCreate()
|
||||
acc.PhoneNumber = "89142221020"
|
||||
req := SerializedEditLoyaltyAccount{acc.SerializedBaseLoyaltyAccount}
|
||||
reqJSON, _ := json.Marshal(req)
|
||||
p := url.Values{
|
||||
"loyaltyAccount": {string(reqJSON)},
|
||||
}
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/loyalty/account/%d/edit", 13)).
|
||||
BodyString(p.Encode()).
|
||||
Reply(http.StatusInternalServerError).
|
||||
JSON(`{"success":false,"errorMsg":"Something went wrong"}`)
|
||||
|
||||
res, status, err := client().LoyaltyAccountEdit(13, req)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
if status != http.StatusInternalServerError {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != false {
|
||||
t.Error(successFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccount(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
gock.New(crmURL).
|
||||
Get(prefix + fmt.Sprintf("/loyalty/account/%d", 13)).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getLoyaltyAccountResponse())
|
||||
|
||||
res, status, err := client().LoyaltyAccount(13)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != true {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.ID)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Loyalty)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Customer)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.PhoneNumber)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.NextLevelSum)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.LoyaltyLevel)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.CreatedAt)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.ActivatedAt)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Status)
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyAccountActivate(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
var resp LoyaltyAccountActivateResponse
|
||||
err := json.Unmarshal([]byte(getLoyaltyAccountResponse()), &resp)
|
||||
assert.NoError(t, err)
|
||||
resp.Verification = SmsVerification{
|
||||
CreatedAt: "2022-11-24 12:39:37",
|
||||
ExpiredAt: "2022-11-24 12:39:37",
|
||||
VerifiedAt: "2022-11-24 13:39:37",
|
||||
CheckID: "test",
|
||||
ActionType: "test",
|
||||
}
|
||||
gock.New(crmURL).
|
||||
Post(prefix + fmt.Sprintf("/loyalty/account/%d/activate", 13)).
|
||||
Body(strings.NewReader("")).
|
||||
Reply(http.StatusOK).
|
||||
JSON(resp)
|
||||
|
||||
res, status, err := client().LoyaltyAccountActivate(13)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != true {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.ID)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Loyalty)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Customer)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.PhoneNumber)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.NextLevelSum)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.LoyaltyLevel)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.CreatedAt)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.ActivatedAt)
|
||||
assert.NotEmpty(t, res.LoyaltyAccount.Status)
|
||||
assert.NotEmpty(t, res.Verification)
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyBonusCredit(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
req := LoyaltyBonusCreditRequest{
|
||||
Amount: 120,
|
||||
ExpiredDate: "2023-11-24 12:39:37",
|
||||
Comment: "Test",
|
||||
}
|
||||
body, err := query.Values(req)
|
||||
assert.NoError(t, err)
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + fmt.Sprintf("/loyalty/account/%d/bonus/credit", 13)).
|
||||
BodyString(body.Encode()).
|
||||
Reply(http.StatusOK).
|
||||
JSON(`{
|
||||
"success":true,
|
||||
"loyaltyBonus": {
|
||||
"amount":120,
|
||||
"expiredDate":"2023-11-24 12:39:37"
|
||||
}
|
||||
}`)
|
||||
|
||||
res, status, err := client().LoyaltyBonusCredit(13, req)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != true {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyBonusCreditFail(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
req := LoyaltyBonusCreditRequest{
|
||||
Amount: 120,
|
||||
ExpiredDate: "2023-11-24 12:39:37",
|
||||
Comment: "Test",
|
||||
}
|
||||
body, err := query.Values(req)
|
||||
assert.NoError(t, err)
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(prefix + fmt.Sprintf("/loyalty/account/%d/bonus/credit", 13)).
|
||||
BodyString(body.Encode()).
|
||||
Reply(http.StatusInternalServerError).
|
||||
JSON(`{"success":false,"errorMsg":"Something went wrong"}`)
|
||||
|
||||
res, status, err := client().LoyaltyBonusCredit(13, req)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected error")
|
||||
}
|
||||
|
||||
if status != http.StatusInternalServerError {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != false {
|
||||
t.Error(successFail)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_LoyaltyBonusStatusDetails(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
req := LoyaltyBonusStatusDetailsRequest{
|
||||
Limit: 20,
|
||||
Page: 3,
|
||||
}
|
||||
|
||||
gock.New(crmURL).
|
||||
Get(prefix+fmt.Sprintf("/loyalty/account/%d/bonus/%s/details", 13, "waiting_activation")).
|
||||
MatchParam("limit", strconv.Itoa(20)).
|
||||
MatchParam("page", strconv.Itoa(3)).
|
||||
Reply(http.StatusOK).
|
||||
JSON(getBonusDetailsResponse())
|
||||
|
||||
res, status, err := client().LoyaltyBonusStatusDetails(13, "waiting_activation", req)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if !statuses[status] {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
if res.Success != true {
|
||||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
assert.NotEmpty(t, res.Pagination.TotalCount)
|
||||
assert.NotEmpty(t, res.Bonuses)
|
||||
assert.NotEmpty(t, res.Statistic.TotalAmount)
|
||||
}
|
||||
|
13
request.go
13
request.go
@ -246,6 +246,19 @@ type AccountBonusOperationsRequest struct {
|
||||
Page int `url:"page,omitempty"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusCreditRequest struct {
|
||||
Amount float64 `url:"amount"`
|
||||
ActivationDate string `url:"activationDate,omitempty"`
|
||||
ExpiredDate string `url:"expiredDate,omitempty"`
|
||||
Comment string `url:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusStatusDetailsRequest struct {
|
||||
Limit int `url:"limit,omitempty"`
|
||||
Page int `url:"page,omitempty"`
|
||||
Filter LoyaltyBonusApiFilterType `url:"filter,omitempty"`
|
||||
}
|
||||
|
||||
// SystemURL returns system URL from the connection request without trailing slash.
|
||||
func (r ConnectRequest) SystemURL() string {
|
||||
if r.URL == "" {
|
||||
|
54
response.go
54
response.go
@ -5,6 +5,17 @@ type SuccessfulResponse struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type CreateLoyaltyAccountResponse struct {
|
||||
SuccessfulResponse
|
||||
LoyaltyAccount LoyaltyAccount `json:"loyaltyAccount,omitempty"`
|
||||
Warnings []string `json:"warnings,omitempty"`
|
||||
}
|
||||
|
||||
type EditLoyaltyAccountResponse struct {
|
||||
SuccessfulResponse
|
||||
LoyaltyAccount LoyaltyAccount `json:"loyaltyAccount,omitempty"`
|
||||
}
|
||||
|
||||
// CreateResponse type.
|
||||
type CreateResponse struct {
|
||||
Success bool `json:"success"`
|
||||
@ -376,13 +387,13 @@ type ProductEditNotFoundResponse struct {
|
||||
}
|
||||
|
||||
type ProductsBatchEditResponse struct {
|
||||
Success bool `json:"success"`
|
||||
SuccessfulResponse
|
||||
ProcessedProductsCount int `json:"processedProductsCount,omitempty"`
|
||||
NotFoundProducts []ProductEditNotFoundResponse `json:"notFoundProducts,omitempty"`
|
||||
}
|
||||
|
||||
type ProductsBatchCreateResponse struct {
|
||||
Success bool `json:"success"`
|
||||
SuccessfulResponse
|
||||
ProcessedProductsCount int `json:"processedProductsCount,omitempty"`
|
||||
AddedProducts []int `json:"addedProducts,omitempty"`
|
||||
}
|
||||
@ -434,9 +445,10 @@ type IntegrationModuleEditResponse struct {
|
||||
|
||||
// ResponseInfo type.
|
||||
type ResponseInfo struct {
|
||||
MgTransportInfo MgInfo `json:"mgTransport,omitempty"`
|
||||
MgBotInfo MgInfo `json:"mgBot,omitempty"`
|
||||
BillingInfo *BillingInfo `json:"billingInfo,omitempty"`
|
||||
MgTransportInfo MgInfo `json:"mgTransport,omitempty"`
|
||||
MgBotInfo MgInfo `json:"mgBot,omitempty"`
|
||||
BillingInfo *BillingInfo `json:"billingInfo,omitempty"`
|
||||
DeliveryTypeInfo DeliveryTypeInfo `json:"deliveryType,omitempty"`
|
||||
}
|
||||
|
||||
type BillingInfo struct {
|
||||
@ -581,3 +593,35 @@ type AccountBonusOperationsResponse struct {
|
||||
Pagination *Pagination `json:"pagination,omitempty"`
|
||||
BonusOperations []BonusOperation `json:"bonusOperations,omitempty"`
|
||||
}
|
||||
|
||||
type LoyaltyAccountResponse struct {
|
||||
SuccessfulResponse
|
||||
LoyaltyAccount `json:"loyaltyAccount"`
|
||||
}
|
||||
|
||||
type LoyaltyAccountActivateResponse struct {
|
||||
SuccessfulResponse
|
||||
LoyaltyAccount `json:"loyaltyAccount"`
|
||||
Verification SmsVerification `json:"verification,omitempty"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusCreditResponse struct {
|
||||
SuccessfulResponse
|
||||
LoyaltyBonus LoyaltyBonus `json:"loyaltyBonus"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusDetailsResponse struct {
|
||||
SuccessfulResponse
|
||||
Pagination `json:"pagination"`
|
||||
Statistic LoyaltyBonusStatisticResponse `json:"statistic"`
|
||||
Bonuses []BonusDetail `json:"bonuses"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusStatisticResponse struct {
|
||||
TotalAmount float64 `json:"totalAmount"`
|
||||
}
|
||||
|
||||
type BonusDetail struct {
|
||||
Date string `json:"date"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
138
testutils.go
138
testutils.go
@ -6,7 +6,7 @@ package retailcrm
|
||||
func getProductsCreate() []ProductCreate {
|
||||
products := []ProductCreate{
|
||||
{
|
||||
CatalogID: 123,
|
||||
CatalogID: 3,
|
||||
BaseProduct: BaseProduct{
|
||||
Name: "Product 1",
|
||||
URL: "https://example.com/p/1",
|
||||
@ -19,12 +19,12 @@ func getProductsCreate() []ProductCreate {
|
||||
Novelty: true,
|
||||
Recommended: true,
|
||||
Active: true,
|
||||
Groups: []ProductGroup{{ID: 333}},
|
||||
Markable: true,
|
||||
},
|
||||
Groups: []ProductEditGroupInput{{ID: 19}},
|
||||
},
|
||||
{
|
||||
CatalogID: 123,
|
||||
CatalogID: 3,
|
||||
BaseProduct: BaseProduct{
|
||||
Name: "Product 2",
|
||||
URL: "https://example.com/p/2",
|
||||
@ -37,9 +37,9 @@ func getProductsCreate() []ProductCreate {
|
||||
Novelty: true,
|
||||
Recommended: true,
|
||||
Active: true,
|
||||
Groups: []ProductGroup{{ID: 444}},
|
||||
Markable: true,
|
||||
},
|
||||
Groups: []ProductEditGroupInput{{ID: 19}},
|
||||
},
|
||||
}
|
||||
|
||||
@ -48,8 +48,134 @@ func getProductsCreate() []ProductCreate {
|
||||
|
||||
func getProductsCreateResponse() ProductsBatchCreateResponse {
|
||||
return ProductsBatchCreateResponse{
|
||||
Success: true,
|
||||
SuccessfulResponse: SuccessfulResponse{Success: true},
|
||||
ProcessedProductsCount: 2,
|
||||
AddedProducts: []int{1, 2},
|
||||
AddedProducts: []int{1, 2},
|
||||
}
|
||||
}
|
||||
|
||||
func getProductsEdit() []ProductEdit {
|
||||
products := []ProductEdit{
|
||||
{
|
||||
BaseProduct: getProductsCreate()[0].BaseProduct,
|
||||
ID: 194,
|
||||
CatalogID: 3,
|
||||
Site: "second",
|
||||
},
|
||||
{
|
||||
BaseProduct: getProductsCreate()[1].BaseProduct,
|
||||
ID: 195,
|
||||
CatalogID: 3,
|
||||
Site: "second",
|
||||
},
|
||||
}
|
||||
|
||||
return products
|
||||
}
|
||||
|
||||
func getProductsEditResponse() ProductsBatchEditResponse {
|
||||
return ProductsBatchEditResponse{
|
||||
SuccessfulResponse: SuccessfulResponse{Success: true},
|
||||
ProcessedProductsCount: 2,
|
||||
NotFoundProducts: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func getLoyaltyAccountCreate() SerializedCreateLoyaltyAccount {
|
||||
return SerializedCreateLoyaltyAccount{
|
||||
SerializedBaseLoyaltyAccount: SerializedBaseLoyaltyAccount{
|
||||
PhoneNumber: "89151005004",
|
||||
CustomFields: []string{"dog"},
|
||||
},
|
||||
Customer: SerializedEntityCustomer{
|
||||
ID: 123,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getLoyaltyAccountCreateResponse() CreateLoyaltyAccountResponse {
|
||||
return CreateLoyaltyAccountResponse{
|
||||
SuccessfulResponse: SuccessfulResponse{Success: true},
|
||||
LoyaltyAccount: LoyaltyAccount{
|
||||
Active: true,
|
||||
ID: 13,
|
||||
PhoneNumber: "89151005004",
|
||||
LoyaltyLevel: LoyaltyLevel{},
|
||||
CreatedAt: "2022-11-24 12:39:37",
|
||||
ActivatedAt: "2022-11-24 12:39:37",
|
||||
CustomFields: []string{"dog"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getLoyaltyAccountEditResponse() EditLoyaltyAccountResponse {
|
||||
return EditLoyaltyAccountResponse{
|
||||
SuccessfulResponse: SuccessfulResponse{Success: true},
|
||||
LoyaltyAccount: LoyaltyAccount{
|
||||
Active: true,
|
||||
ID: 13,
|
||||
PhoneNumber: "89142221020",
|
||||
LoyaltyLevel: LoyaltyLevel{},
|
||||
CreatedAt: "2022-11-24 12:39:37",
|
||||
ActivatedAt: "2022-11-24 12:39:37",
|
||||
CustomFields: []string{"dog"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getLoyaltyAccountResponse() string {
|
||||
return `{
|
||||
"success": true,
|
||||
"loyaltyAccount": {
|
||||
"active": true,
|
||||
"id": 13,
|
||||
"loyalty": {
|
||||
"id": 2
|
||||
},
|
||||
"customer": {
|
||||
"id": 123,
|
||||
"customFields": [],
|
||||
"firstName": "Руслан1",
|
||||
"lastName": "Ефанов",
|
||||
"patronymic": ""
|
||||
},
|
||||
"phoneNumber": "89142221020",
|
||||
"amount": 0,
|
||||
"ordersSum": 0,
|
||||
"nextLevelSum": 10000,
|
||||
"level": {
|
||||
"type": "bonus_percent",
|
||||
"id": 5,
|
||||
"name": "Новичок",
|
||||
"sum": 0,
|
||||
"privilegeSize": 5,
|
||||
"privilegeSizePromo": 3
|
||||
},
|
||||
"createdAt": "2022-11-24 12:39:37",
|
||||
"activatedAt": "2022-11-24 12:39:37",
|
||||
"status": "activated",
|
||||
"customFields": []
|
||||
}
|
||||
}`
|
||||
}
|
||||
|
||||
func getBonusDetailsResponse() string {
|
||||
return `{
|
||||
"success": true,
|
||||
"pagination": {
|
||||
"limit": 20,
|
||||
"totalCount": 41,
|
||||
"currentPage": 3,
|
||||
"totalPageCount": 3
|
||||
},
|
||||
"statistic": {
|
||||
"totalAmount": 240
|
||||
},
|
||||
"bonuses": [
|
||||
{
|
||||
"date": "2022-12-08",
|
||||
"amount": 240
|
||||
}
|
||||
]
|
||||
}`
|
||||
}
|
||||
|
149
types.go
149
types.go
@ -703,6 +703,21 @@ type WorkTime struct {
|
||||
LunchEndTime string `json:"lunch_end_time"`
|
||||
}
|
||||
|
||||
type SerializedBaseLoyaltyAccount struct {
|
||||
PhoneNumber string `json:"phoneNumber,omitempty"`
|
||||
CardNumber string `json:"cardNumber,omitempty"`
|
||||
CustomFields []string `json:"customFields,omitempty"`
|
||||
}
|
||||
|
||||
type SerializedCreateLoyaltyAccount struct {
|
||||
SerializedBaseLoyaltyAccount
|
||||
Customer SerializedEntityCustomer `json:"customer"`
|
||||
}
|
||||
|
||||
type SerializedEditLoyaltyAccount struct {
|
||||
SerializedBaseLoyaltyAccount
|
||||
}
|
||||
|
||||
// Settings type. Contains retailCRM configuration.
|
||||
type Settings struct {
|
||||
DefaultCurrency SettingsNode `json:"default_currency"`
|
||||
@ -793,6 +808,11 @@ type LegalEntity struct {
|
||||
BankAccount string `json:"bankAccount,omitempty"`
|
||||
}
|
||||
|
||||
type SerializedEntityCustomer struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID int `json:"externalId,omitempty"`
|
||||
}
|
||||
|
||||
// OrderMethod type.
|
||||
type OrderMethod struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
@ -926,45 +946,53 @@ type ProductGroup struct {
|
||||
|
||||
// BaseProduct type.
|
||||
type BaseProduct struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Article string `json:"article,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Manufacturer string `json:"manufacturer,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Popular bool `json:"popular,omitempty"`
|
||||
Stock bool `json:"stock,omitempty"`
|
||||
Novelty bool `json:"novelty,omitempty"`
|
||||
Recommended bool `json:"recommended,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
Groups []ProductGroup `json:"groups,omitempty"`
|
||||
Markable bool `json:"markable,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
URL string `json:"url,omitempty"`
|
||||
Article string `json:"article,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Manufacturer string `json:"manufacturer,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Popular bool `json:"popular,omitempty"`
|
||||
Stock bool `json:"stock,omitempty"`
|
||||
Novelty bool `json:"novelty,omitempty"`
|
||||
Recommended bool `json:"recommended,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
Markable bool `json:"markable,omitempty"`
|
||||
}
|
||||
|
||||
// Product type.
|
||||
type Product struct {
|
||||
BaseProduct
|
||||
ID int `json:"id,omitempty"`
|
||||
MaxPrice float32 `json:"maxPrice,omitempty"`
|
||||
MinPrice float32 `json:"minPrice,omitempty"`
|
||||
ImageURL string `json:"imageUrl,omitempty"`
|
||||
Quantity float32 `json:"quantity,omitempty"`
|
||||
Offers []Offer `json:"offers,omitempty"`
|
||||
Properties StringMap `json:"properties,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
MaxPrice float32 `json:"maxPrice,omitempty"`
|
||||
MinPrice float32 `json:"minPrice,omitempty"`
|
||||
ImageURL string `json:"imageUrl,omitempty"`
|
||||
Quantity float32 `json:"quantity,omitempty"`
|
||||
Offers []Offer `json:"offers,omitempty"`
|
||||
Properties StringMap `json:"properties,omitempty"`
|
||||
Groups []ProductGroup `json:"groups,omitempty"`
|
||||
}
|
||||
|
||||
// ProductEdit type.
|
||||
type ProductEdit struct {
|
||||
BaseProduct
|
||||
ID int `json:"id,omitempty"`
|
||||
CatalogID int `json:"catalogId,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
// ProductEditGroupInput type.
|
||||
type ProductEditGroupInput struct {
|
||||
ID int `json:"id"`
|
||||
ExternalID int `json:"externalId,omitempty"`
|
||||
}
|
||||
|
||||
// ProductCreate type.
|
||||
type ProductCreate struct {
|
||||
BaseProduct
|
||||
CatalogID int `json:"catalogId,omitempty"`
|
||||
Groups []ProductEditGroupInput `json:"groups,omitempty"`
|
||||
CatalogID int `json:"catalogId,omitempty"`
|
||||
}
|
||||
|
||||
// ProductEdit type.
|
||||
type ProductEdit struct {
|
||||
BaseProduct
|
||||
ID int `json:"id,omitempty"`
|
||||
CatalogID int `json:"catalogId,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
Groups []ProductEditGroupInput `json:"groups,omitempty"`
|
||||
}
|
||||
|
||||
// DeliveryHistoryRecord type.
|
||||
@ -1042,9 +1070,11 @@ type Delivery struct {
|
||||
|
||||
// DeliveryStatus type.
|
||||
type DeliveryStatus struct {
|
||||
Code string `json:"code,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
IsEditable bool `json:"isEditable,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
IsEditable bool `json:"isEditable,omitempty"`
|
||||
IsError bool `json:"isError,omitempty"`
|
||||
IsPreprocessing bool `json:"isPreprocessing,omitempty"`
|
||||
}
|
||||
|
||||
// Plate type.
|
||||
@ -1250,3 +1280,62 @@ type OperationLoyalty struct {
|
||||
type CursorPagination struct {
|
||||
NextCursor string `json:"nextCursor,omitempty"`
|
||||
}
|
||||
|
||||
// DeliveryTypeInfo type.
|
||||
type DeliveryTypeInfo struct {
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// LoyaltyAccount type.
|
||||
type LoyaltyAccount struct {
|
||||
Active bool `json:"active"`
|
||||
ID int `json:"id"`
|
||||
PhoneNumber string `json:"phoneNumber,omitempty"`
|
||||
CardNumber string `json:"cardNumber,omitempty"`
|
||||
Amount float64 `json:"amount,omitempty"`
|
||||
LoyaltyLevel LoyaltyLevel `json:"level"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
ActivatedAt string `json:"activatedAt,omitempty"`
|
||||
ConfirmedPhoneAt string `json:"confirmedPhoneAt,omitempty"`
|
||||
LastCheckID int `json:"lastCheckId,omitempty"`
|
||||
CustomFields []string `json:"customFields,omitempty"`
|
||||
Loyalty Loyalty `json:"loyalty,omitempty"`
|
||||
Customer Customer `json:"customer,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
OrderSum float64 `json:"orderSum,omitempty"`
|
||||
NextLevelSum float64 `json:"nextLevelSum,omitempty"`
|
||||
}
|
||||
|
||||
// Loyalty type.
|
||||
type Loyalty struct {
|
||||
ID int `json:"id"`
|
||||
}
|
||||
|
||||
// LoyaltyLevel type.
|
||||
type LoyaltyLevel struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Sum float64 `json:"sum,omitempty"`
|
||||
PrivilegeSize float64 `json:"privilegeSize,omitempty"`
|
||||
PrivilegeSizePromo float64 `json:"privilegeSizePromo,omitempty"`
|
||||
}
|
||||
|
||||
type SmsVerification struct {
|
||||
CreatedAt string `json:"createdAt"`
|
||||
ExpiredAt string `json:"expiredAt"`
|
||||
VerifiedAt string `json:"verifiedAt"`
|
||||
CheckID string `json:"checkId"`
|
||||
ActionType string `json:"actionType"`
|
||||
}
|
||||
|
||||
type LoyaltyBonus struct {
|
||||
Amount float64 `json:"amount"`
|
||||
ActivationDate string `json:"activationDate"`
|
||||
ExpiredDate string `json:"expiredDate,omitempty"`
|
||||
}
|
||||
|
||||
type LoyaltyBonusApiFilterType struct {
|
||||
Date string `url:"date,omitempty"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user