From 12773269d4eac33b742a9ef61ebc4c1aeff48b5c Mon Sep 17 00:00:00 2001 From: diPhantxm Date: Thu, 16 Mar 2023 01:09:31 +0300 Subject: [PATCH] add validate labeling codes --- ozon/fbs.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ ozon/fbs_test.go | 71 ++++++++++++++++++++++++++++++++++++++++++ ozon/products.go | 5 +-- 3 files changed, 153 insertions(+), 4 deletions(-) diff --git a/ozon/fbs.go b/ozon/fbs.go index adbc175..e26c91a 100644 --- a/ozon/fbs.go +++ b/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 +} diff --git a/ozon/fbs_test.go b/ozon/fbs_test.go index af8fb9b..92bc130 100644 --- a/ozon/fbs_test.go +++ b/ozon/fbs_test.go @@ -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) + } + } +} diff --git a/ozon/products.go b/ozon/products.go index 533bdd7..4d9192f 100644 --- a/ozon/products.go +++ b/ozon/products.go @@ -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