Added a method for getting a barcode used during product shipment
This commit is contained in:
33
ozon/fbs.go
33
ozon/fbs.go
@@ -2645,3 +2645,36 @@ func (c FBS) ETGBCustomsDeclarations(params *ETGBCustomsDeclarationsParams) (*ET
|
|||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BarcodeFromProductShipmentParams struct {
|
||||||
|
// Freight identifier
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BarcodeFromProductShipmentResponse struct {
|
||||||
|
core.CommonResponse
|
||||||
|
|
||||||
|
// Link to barcode image
|
||||||
|
Content string `json:"content"`
|
||||||
|
|
||||||
|
// File name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// File type
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method for getting a barcode to show at a pick-up point or sorting center during the shipment
|
||||||
|
func (c FBS) BarcodeFromProductShipment(params *BarcodeFromProductShipmentParams) (*BarcodeFromProductShipmentResponse, error) {
|
||||||
|
url := "/v2/posting/fbs/act/get-barcode"
|
||||||
|
|
||||||
|
resp := &BarcodeFromProductShipmentResponse{}
|
||||||
|
|
||||||
|
response, err := c.client.Request(http.MethodPost, url, params, resp, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.CopyCommonResponse(&resp.CommonResponse)
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2526,3 +2526,63 @@ func TestETGBCustomsDeclarations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBarcodeFromProductShipment(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
statusCode int
|
||||||
|
headers map[string]string
|
||||||
|
params *BarcodeFromProductShipmentParams
|
||||||
|
response string
|
||||||
|
}{
|
||||||
|
// Test Ok
|
||||||
|
{
|
||||||
|
http.StatusOK,
|
||||||
|
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
|
||||||
|
&BarcodeFromProductShipmentParams{
|
||||||
|
Id: 295662811,
|
||||||
|
},
|
||||||
|
`{
|
||||||
|
"content": "https://cdn.ozone.ru/s3/ozon-disk-api/techdoc/seller-api/barcode_1684849346.png",
|
||||||
|
"name": "barcode-test",
|
||||||
|
"type": "PNG"
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
// Test No Client-Id or Api-Key
|
||||||
|
{
|
||||||
|
http.StatusUnauthorized,
|
||||||
|
map[string]string{},
|
||||||
|
&BarcodeFromProductShipmentParams{},
|
||||||
|
`{
|
||||||
|
"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().BarcodeFromProductShipment(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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode == http.StatusOK {
|
||||||
|
if resp.Content == "" {
|
||||||
|
t.Errorf("content cannot be empty")
|
||||||
|
}
|
||||||
|
if resp.Type == "" {
|
||||||
|
t.Error("type cannot be empty")
|
||||||
|
}
|
||||||
|
if resp.Name == "" {
|
||||||
|
t.Error("name cannot be empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user