diff --git a/ozon/fbs.go b/ozon/fbs.go index e54ce3d..b33495e 100644 --- a/ozon/fbs.go +++ b/ozon/fbs.go @@ -3086,3 +3086,55 @@ func (c FBS) SetShippingDate(ctx context.Context, params *SetShippingDateParams) return resp, nil } + +type SplitOrderParams struct { + // Shipment number + PostingNumber string `json:"posting_number"` + + // Shipments list the order will be split into. You can split one order per one request + Postings []SplitOrderParamPosting `json:"postings"` +} + +type SplitOrderParamPosting struct { + Products []SplitOrderPostingProduct `json:"products"` +} + +type SplitOrderResponse struct { + core.CommonResponse + + // Original shipment details + ParentPosting SplitOrderPosting `json:"parent_posting"` + + // List of shipments the order was split into + Postings []SplitOrderPosting `json:"postings"` +} + +type SplitOrderPosting struct { + // Shipment number + PostingNumber string `json:"posting_number"` + + // List of products in the shipment + Products []SplitOrderPostingProduct `json:"products"` +} + +type SplitOrderPostingProduct struct { + // FBS product identifier in the Ozon system, SKU + ProductId int64 `json:"product_id"` + + // Product quantity + Quantity int64 `json:"quantity"` +} + +func (c FBS) SplitOrder(ctx context.Context, params *SplitOrderParams) (*SplitOrderResponse, error) { + url := "/v1/posting/fbs/split" + + resp := &SplitOrderResponse{} + + response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil) + 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 bb4b9ff..50c5765 100644 --- a/ozon/fbs_test.go +++ b/ozon/fbs_test.go @@ -3130,3 +3130,82 @@ func TestSetShippingDate(t *testing.T) { } } } + +func TestSplitOrder(t *testing.T) { + t.Parallel() + + tests := []struct { + statusCode int + headers map[string]string + params *SplitOrderParams + response string + }{ + // Test Ok + { + http.StatusOK, + map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, + &SplitOrderParams{ + PostingNumber: "string", + Postings: []SplitOrderParamPosting{ + { + Products: []SplitOrderPostingProduct{ + { + ProductId: 1, + Quantity: 1, + }, + }, + }, + }, + }, + `{ + "parent_posting": { + "posting_number": "string", + "products": [ + { + "product_id": 0, + "quantity": 0 + } + ] + }, + "postings": [ + { + "posting_number": "string", + "products": [ + { + "product_id": 0, + "quantity": 0 + } + ] + } + ] + }`, + }, + // Test No Client-Id or Api-Key + { + http.StatusUnauthorized, + map[string]string{}, + &SplitOrderParams{}, + `{ + "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)) + + ctx, _ := context.WithTimeout(context.Background(), testTimeout) + resp, err := c.FBS().SplitOrder(ctx, test.params) + if err != nil { + t.Error(err) + continue + } + + compareJsonResponse(t, test.response, &SplitOrderResponse{}) + + if resp.StatusCode != test.statusCode { + t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) + } + } +}