mirror of
https://github.com/retailcrm/api-client-go.git
synced 2024-11-23 21:36:05 +03:00
add new order field DialogID and fix custom fields marshaling
This commit is contained in:
commit
b445dfdfe5
@ -58,6 +58,30 @@ func (l *StringMap) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *CustomFieldMap) UnmarshalJSON(data []byte) error {
|
||||
var i interface{}
|
||||
var items CustomFieldMap
|
||||
if err := json.Unmarshal(data, &i); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch e := i.(type) {
|
||||
case map[string]interface{}:
|
||||
items = make(CustomFieldMap, len(e))
|
||||
for idx, val := range e {
|
||||
items[idx] = val
|
||||
}
|
||||
case []interface{}:
|
||||
items = make(CustomFieldMap, len(e))
|
||||
for idx, val := range e {
|
||||
items[strconv.Itoa(idx)] = val
|
||||
}
|
||||
}
|
||||
|
||||
*l = items
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *OrderPayments) UnmarshalJSON(data []byte) error {
|
||||
var i interface{}
|
||||
var m OrderPayments
|
||||
|
@ -44,7 +44,7 @@ func TestAPIErrorsList_UnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
||||
var list StringMap
|
||||
var list CustomFieldMap
|
||||
|
||||
require.NoError(t, json.Unmarshal([]byte(`["first", "second"]`), &list))
|
||||
assert.Len(t, list, 2)
|
||||
@ -56,6 +56,13 @@ func TestCustomFieldsList_UnmarshalJSON(t *testing.T) {
|
||||
assert.Equal(t, list["a"], "first")
|
||||
assert.Equal(t, list["b"], "second")
|
||||
|
||||
require.NoError(t, json.Unmarshal([]byte(`{"a": ["first", "second"], "b": "second"}`), &list))
|
||||
assert.Len(t, list, 2)
|
||||
assert.Len(t, list["a"].([]interface{}), 2)
|
||||
assert.Equal(t, list["a"].([]interface{})[0], "first")
|
||||
assert.Equal(t, list["a"].([]interface{})[1], "second")
|
||||
assert.Equal(t, list["b"], "second")
|
||||
|
||||
require.NoError(t, json.Unmarshal([]byte(`[]`), &list))
|
||||
assert.Len(t, list, 0)
|
||||
}
|
||||
|
230
types.go
230
types.go
@ -122,41 +122,41 @@ Customer related types
|
||||
|
||||
// Customer type.
|
||||
type Customer struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
Patronymic string `json:"patronymic,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Phones []Phone `json:"phones,omitempty"`
|
||||
Address *Address `json:"address,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Birthday string `json:"birthday,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
Vip bool `json:"vip,omitempty"`
|
||||
Bad bool `json:"bad,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
||||
CumulativeDiscount float32 `json:"cumulativeDiscount,omitempty"`
|
||||
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
||||
EmailMarketingUnsubscribedAt string `json:"emailMarketingUnsubscribedAt,omitempty"`
|
||||
AvgMarginSumm float32 `json:"avgMarginSumm,omitempty"`
|
||||
MarginSumm float32 `json:"marginSumm,omitempty"`
|
||||
TotalSumm float32 `json:"totalSumm,omitempty"`
|
||||
AverageSumm float32 `json:"averageSumm,omitempty"`
|
||||
OrdersCount int `json:"ordersCount,omitempty"`
|
||||
CostSumm float32 `json:"costSumm,omitempty"`
|
||||
MaturationTime int `json:"maturationTime,omitempty"`
|
||||
FirstClientID string `json:"firstClientId,omitempty"`
|
||||
LastClientID string `json:"lastClientId,omitempty"`
|
||||
BrowserID string `json:"browserId,omitempty"`
|
||||
MgCustomerID string `json:"mgCustomerId,omitempty"`
|
||||
PhotoURL string `json:"photoUrl,omitempty"`
|
||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
Patronymic string `json:"patronymic,omitempty"`
|
||||
Sex string `json:"sex,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Phones []Phone `json:"phones,omitempty"`
|
||||
Address *Address `json:"address,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Birthday string `json:"birthday,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
Vip bool `json:"vip,omitempty"`
|
||||
Bad bool `json:"bad,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
||||
CumulativeDiscount float32 `json:"cumulativeDiscount,omitempty"`
|
||||
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
||||
EmailMarketingUnsubscribedAt string `json:"emailMarketingUnsubscribedAt,omitempty"`
|
||||
AvgMarginSumm float32 `json:"avgMarginSumm,omitempty"`
|
||||
MarginSumm float32 `json:"marginSumm,omitempty"`
|
||||
TotalSumm float32 `json:"totalSumm,omitempty"`
|
||||
AverageSumm float32 `json:"averageSumm,omitempty"`
|
||||
OrdersCount int `json:"ordersCount,omitempty"`
|
||||
CostSumm float32 `json:"costSumm,omitempty"`
|
||||
MaturationTime int `json:"maturationTime,omitempty"`
|
||||
FirstClientID string `json:"firstClientId,omitempty"`
|
||||
LastClientID string `json:"lastClientId,omitempty"`
|
||||
BrowserID string `json:"browserId,omitempty"`
|
||||
MgCustomerID string `json:"mgCustomerId,omitempty"`
|
||||
PhotoURL string `json:"photoUrl,omitempty"`
|
||||
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||
Tags []Tag `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// CorporateCustomer type.
|
||||
@ -167,7 +167,7 @@ type CorporateCustomer struct {
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Vip bool `json:"vip,omitempty"`
|
||||
Bad bool `json:"bad,omitempty"`
|
||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
||||
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||
PersonalDiscount float32 `json:"personalDiscount,omitempty"`
|
||||
DiscountCardNumber string `json:"discountCardNumber,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
@ -218,17 +218,17 @@ type CorporateCustomerContactCustomer struct {
|
||||
}
|
||||
|
||||
type Company struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
IsMain bool `json:"isMain,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Brand string `json:"brand,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
Address *IdentifiersPair `json:"address,omitempty"`
|
||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
IsMain bool `json:"isMain,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Brand string `json:"brand,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
Address *IdentifiersPair `json:"address,omitempty"`
|
||||
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||
}
|
||||
|
||||
// CorporateCustomerNote type.
|
||||
@ -287,61 +287,63 @@ Order related types
|
||||
|
||||
type OrderPayments map[string]OrderPayment
|
||||
type StringMap map[string]string
|
||||
type CustomFieldMap map[string]interface{}
|
||||
type Properties map[string]Property
|
||||
|
||||
// Order type.
|
||||
type Order struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Number string `json:"number,omitempty"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
Patronymic string `json:"patronymic,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Phone string `json:"phone,omitempty"`
|
||||
AdditionalPhone string `json:"additionalPhone,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
StatusUpdatedAt string `json:"statusUpdatedAt,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
Mark int `json:"mark,omitempty"`
|
||||
Call bool `json:"call,omitempty"`
|
||||
Expired bool `json:"expired,omitempty"`
|
||||
FromAPI bool `json:"fromApi,omitempty"`
|
||||
MarkDatetime string `json:"markDatetime,omitempty"`
|
||||
CustomerComment string `json:"customerComment,omitempty"`
|
||||
ManagerComment string `json:"managerComment,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
StatusComment string `json:"statusComment,omitempty"`
|
||||
FullPaidAt string `json:"fullPaidAt,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
OrderType string `json:"orderType,omitempty"`
|
||||
OrderMethod string `json:"orderMethod,omitempty"`
|
||||
CountryIso string `json:"countryIso,omitempty"`
|
||||
Summ float32 `json:"summ,omitempty"`
|
||||
TotalSumm float32 `json:"totalSumm,omitempty"`
|
||||
PrepaySum float32 `json:"prepaySum,omitempty"`
|
||||
PurchaseSumm float32 `json:"purchaseSumm,omitempty"`
|
||||
DiscountManualAmount float32 `json:"discountManualAmount,omitempty"`
|
||||
DiscountManualPercent float32 `json:"discountManualPercent,omitempty"`
|
||||
Weight float32 `json:"weight,omitempty"`
|
||||
Length int `json:"length,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
ShipmentStore string `json:"shipmentStore,omitempty"`
|
||||
ShipmentDate string `json:"shipmentDate,omitempty"`
|
||||
ClientID string `json:"clientId,omitempty"`
|
||||
Shipped bool `json:"shipped,omitempty"`
|
||||
UploadedToExternalStoreSystem bool `json:"uploadedToExternalStoreSystem,omitempty"`
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
Customer *Customer `json:"customer,omitempty"`
|
||||
Delivery *OrderDelivery `json:"delivery,omitempty"`
|
||||
Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
|
||||
Items []OrderItem `json:"items,omitempty"`
|
||||
CustomFields map[string]interface{} `json:"customFields,omitempty"`
|
||||
Payments OrderPayments `json:"payments,omitempty"`
|
||||
ApplyRound *bool `json:"applyRound,omitempty"`
|
||||
PrivilegeType string `json:"privilegeType,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
ExternalID string `json:"externalId,omitempty"`
|
||||
Number string `json:"number,omitempty"`
|
||||
FirstName string `json:"firstName,omitempty"`
|
||||
LastName string `json:"lastName,omitempty"`
|
||||
Patronymic string `json:"patronymic,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Phone string `json:"phone,omitempty"`
|
||||
AdditionalPhone string `json:"additionalPhone,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
StatusUpdatedAt string `json:"statusUpdatedAt,omitempty"`
|
||||
ManagerID int `json:"managerId,omitempty"`
|
||||
Mark int `json:"mark,omitempty"`
|
||||
Call bool `json:"call,omitempty"`
|
||||
Expired bool `json:"expired,omitempty"`
|
||||
FromAPI bool `json:"fromApi,omitempty"`
|
||||
MarkDatetime string `json:"markDatetime,omitempty"`
|
||||
CustomerComment string `json:"customerComment,omitempty"`
|
||||
ManagerComment string `json:"managerComment,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
StatusComment string `json:"statusComment,omitempty"`
|
||||
FullPaidAt string `json:"fullPaidAt,omitempty"`
|
||||
Site string `json:"site,omitempty"`
|
||||
OrderType string `json:"orderType,omitempty"`
|
||||
OrderMethod string `json:"orderMethod,omitempty"`
|
||||
CountryIso string `json:"countryIso,omitempty"`
|
||||
Summ float32 `json:"summ,omitempty"`
|
||||
TotalSumm float32 `json:"totalSumm,omitempty"`
|
||||
PrepaySum float32 `json:"prepaySum,omitempty"`
|
||||
PurchaseSumm float32 `json:"purchaseSumm,omitempty"`
|
||||
DiscountManualAmount float32 `json:"discountManualAmount,omitempty"`
|
||||
DiscountManualPercent float32 `json:"discountManualPercent,omitempty"`
|
||||
Weight float32 `json:"weight,omitempty"`
|
||||
Length int `json:"length,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
ShipmentStore string `json:"shipmentStore,omitempty"`
|
||||
ShipmentDate string `json:"shipmentDate,omitempty"`
|
||||
ClientID string `json:"clientId,omitempty"`
|
||||
Shipped bool `json:"shipped,omitempty"`
|
||||
UploadedToExternalStoreSystem bool `json:"uploadedToExternalStoreSystem,omitempty"`
|
||||
Source *Source `json:"source,omitempty"`
|
||||
Contragent *Contragent `json:"contragent,omitempty"`
|
||||
Customer *Customer `json:"customer,omitempty"`
|
||||
Delivery *OrderDelivery `json:"delivery,omitempty"`
|
||||
Marketplace *OrderMarketplace `json:"marketplace,omitempty"`
|
||||
Items []OrderItem `json:"items,omitempty"`
|
||||
CustomFields CustomFieldMap `json:"customFields,omitempty"`
|
||||
Payments OrderPayments `json:"payments,omitempty"`
|
||||
ApplyRound *bool `json:"applyRound,omitempty"`
|
||||
PrivilegeType string `json:"privilegeType,omitempty"`
|
||||
DialogID int `json:"dialogId,omitempty"`
|
||||
}
|
||||
|
||||
// OrdersStatus type.
|
||||
@ -1332,22 +1334,22 @@ type DeliveryTypeInfo struct {
|
||||
|
||||
// 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,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
ActivatedAt string `json:"activatedAt,omitempty"`
|
||||
ConfirmedPhoneAt string `json:"confirmedPhoneAt,omitempty"`
|
||||
LastCheckID int `json:"lastCheckId,omitempty"`
|
||||
CustomFields map[string]interface{} `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"`
|
||||
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,omitempty"`
|
||||
CreatedAt string `json:"createdAt,omitempty"`
|
||||
ActivatedAt string `json:"activatedAt,omitempty"`
|
||||
ConfirmedPhoneAt string `json:"confirmedPhoneAt,omitempty"`
|
||||
LastCheckID int `json:"lastCheckId,omitempty"`
|
||||
CustomFields CustomFieldMap `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.
|
||||
|
Loading…
Reference in New Issue
Block a user