add validate labeling codes
This commit is contained in:
81
ozon/fbs.go
81
ozon/fbs.go
@@ -375,3 +375,84 @@ func (c FBS) PackOrder(params *PackOrderParams) (*PackOrderResponse, error) {
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type ValidateLabelingCodesParams struct {
|
||||
// Shipment number
|
||||
PostingNumber string `json:"posting_number"`
|
||||
|
||||
// Products list
|
||||
Products []ValidateLabelingCodesProduct `json:"products"`
|
||||
}
|
||||
|
||||
type ValidateLabelingCodesProduct struct {
|
||||
// Product items data
|
||||
Exemplars []ValidateLabelingCodesExemplar `json:"exemplars"`
|
||||
|
||||
// Product identifier
|
||||
ProductId int64 `json:"product_id"`
|
||||
}
|
||||
|
||||
type ValidateLabelingCodesExemplar struct {
|
||||
// Сustoms cargo declaration (CCD) number
|
||||
GTD string `json:"gtd"`
|
||||
|
||||
// Mandatory “Chestny ZNAK” labeling
|
||||
MandatoryMark string `json:"mandatory_mark"`
|
||||
|
||||
// Product batch registration number
|
||||
RNPT string `json:"rnpt"`
|
||||
}
|
||||
|
||||
type ValidateLabelingCodesResponse struct {
|
||||
core.CommonResponse
|
||||
|
||||
// Method result
|
||||
Result struct {
|
||||
// Products list
|
||||
Products []struct {
|
||||
// Error code
|
||||
Error string `json:"error"`
|
||||
|
||||
// Product items data
|
||||
Exemplars []struct {
|
||||
// Product item validation errors
|
||||
Errors []string `json:"errors"`
|
||||
|
||||
// Сustoms cargo declaration (CCD) number
|
||||
GTD string `json:"gtd"`
|
||||
|
||||
// Mandatory “Chestny ZNAK” labeling
|
||||
MandatoryMark string `json:"mandatory_mark"`
|
||||
|
||||
// Check result. true if the labeling code of product item meets the requirements
|
||||
Valid bool `json:"valid"`
|
||||
|
||||
// Product batch registration number
|
||||
RNPT string `json:"rnpt"`
|
||||
} `json:"exemplars"`
|
||||
|
||||
// Product identifier
|
||||
ProductId int64 `json:"product_id"`
|
||||
|
||||
// Check result. true if the labeling codes of all product items meet the requirements
|
||||
Valid bool `json:"valid"`
|
||||
} `json:"products"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
// Method for checking whether labeling codes meet the "Chestny ZNAK" system requirements on length and symbols.
|
||||
//
|
||||
// If you don't have the customs cargo declaration (CCD) number, you don't have to specify it
|
||||
func (c FBS) ValidateLabelingCodes(params *ValidateLabelingCodesParams) (*ValidateLabelingCodesResponse, error) {
|
||||
url := "/v4/fbs/posting/product/exemplar/validate"
|
||||
|
||||
resp := &ValidateLabelingCodesResponse{}
|
||||
|
||||
response, err := c.client.Request(http.MethodPost, url, params, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.CopyCommonResponse(&resp.CommonResponse)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -343,3 +343,74 @@ func TestPackOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLabelingCodes(t *testing.T) {
|
||||
tests := []struct {
|
||||
statusCode int
|
||||
headers map[string]string
|
||||
params *ValidateLabelingCodesParams
|
||||
response string
|
||||
}{
|
||||
// Test Ok
|
||||
{
|
||||
http.StatusOK,
|
||||
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||
&ValidateLabelingCodesParams{
|
||||
PostingNumber: "23281294-0063-2",
|
||||
Products: []ValidateLabelingCodesProduct{
|
||||
{
|
||||
Exemplars: []ValidateLabelingCodesExemplar{
|
||||
{
|
||||
GTD: "",
|
||||
MandatoryMark: "010290000151642731tVMohkbfFgunB",
|
||||
},
|
||||
},
|
||||
ProductId: 476925391,
|
||||
},
|
||||
},
|
||||
},
|
||||
`{
|
||||
"result": {
|
||||
"products": [
|
||||
{
|
||||
"product_id": 476925391,
|
||||
"exemplars": [
|
||||
{
|
||||
"mandatory_mark": "010290000151642731tVMohkbfFgunB",
|
||||
"gtd": "",
|
||||
"valid": true,
|
||||
"errors": []
|
||||
}
|
||||
],
|
||||
"valid": true,
|
||||
"error": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}`,
|
||||
},
|
||||
// Test No Client-Id or Api-Key
|
||||
{
|
||||
http.StatusUnauthorized,
|
||||
map[string]string{},
|
||||
&ValidateLabelingCodesParams{},
|
||||
`{
|
||||
"code": 16,
|
||||
"message": "Client-Id and Api-Key headers are required"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||
|
||||
resp, err := c.FBS().ValidateLabelingCodes(test.params)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != test.statusCode {
|
||||
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,10 +347,7 @@ type GetProductDetailsResponseItemError struct {
|
||||
AttributeName string `json:"attribute_name"`
|
||||
|
||||
// Additional fields for error description
|
||||
OptionalDescriptionElements struct {
|
||||
// Additional field for error description
|
||||
PropertyName string `json:"property_name"`
|
||||
} `json:"optional_description_elements"`
|
||||
OptionalDescriptionElements map[string]string `json:"optional_description_elements"`
|
||||
}
|
||||
|
||||
// Get product details
|
||||
|
||||
Reference in New Issue
Block a user