From 739f672caf00c323bfddf4b9a0388d490cc064f1 Mon Sep 17 00:00:00 2001 From: Kirill Date: Sun, 2 Mar 2025 01:18:53 +0300 Subject: [PATCH] Update January 17, 2025 (#141) --- ozon/fbs.go | 39 +++++++++++++++++++++++++++++++++ ozon/fbs_test.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/ozon/fbs.go b/ozon/fbs.go index 2e48ec1..d447f3c 100644 --- a/ozon/fbs.go +++ b/ozon/fbs.go @@ -154,6 +154,9 @@ type FBSPosting struct { // Number of the parent shipment which split resulted in the current shipment ParentPostingNumber string `json:"parent_posting_number"` + // Date and time of successful verification of the courier code + PickupCodeVerifiedAt time.Time `json:"pickup_code_verified_at"` + // Shipment number PostingNumber string `json:"posting_number"` @@ -1016,6 +1019,9 @@ type GetShipmentDataByIdentifierResult struct { // Shipment number PostingNumber string `json:"posting_number"` + // Date and time of successful verification of the courier code + PickupCodeVerifiedAt time.Time `json:"pickup_code_verified_at"` + // Information on products and their instances. // // The response contains the field product_exemplars, if the attribute with.product_exemplars = true is passed in the request @@ -1027,6 +1033,9 @@ type GetShipmentDataByIdentifierResult struct { // Delivery service status ProviderStatus string `json:"provider_status"` + // Previous sub-status of the shipment + PreviousSubstatus string `json:"previous_substatus"` + // Information on lifting service. Only relevant for bulky products // with a delivery by a third-party or integrated service PRROption GetShipmentDataByIdentifierResultPRROption `json:"prr_option"` @@ -3271,3 +3280,33 @@ func (c FBS) DeleteShipment(ctx context.Context, params *DeleteShipmentParams) ( return resp, nil } + +type VerifyCourierCodeParams struct { + // Courier code + PickupCode string `json:"pickup_code"` + + // Shipment number + PostingNumber string `json:"posting_number"` +} + +type VerifyCourierCodeResponse struct { + core.CommonResponse + + // true, if the code is correct + Valid bool `json:"valid"` +} + +// Use this method to verify the courier code when handing over realFBS Express shipments +func (c FBS) VerifyCourierCode(ctx context.Context, params *VerifyCourierCodeParams) (*VerifyCourierCodeResponse, error) { + url := "/v1/posting/fbs/pick-up-code/verify" + + resp := &VerifyCourierCodeResponse{} + + 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 f7bec1d..85998c4 100644 --- a/ozon/fbs_test.go +++ b/ozon/fbs_test.go @@ -43,6 +43,7 @@ func TestListUnprocessedShipments(t *testing.T) { "posting_number": "23713478-0018-3", "order_id": 559293114, "order_number": "33713378-0051", + "pickup_code_verified_at": "2025-01-17T11:03:00.124Z", "status": "awaiting_packaging", "delivery_method": { "id": 15110442724000, @@ -238,6 +239,7 @@ func TestGetFBSShipmentsList(t *testing.T) { "posting_number": "05708065-0029-1", "order_id": 680420041, "order_number": "05708065-0029", + "pickup_code_verified_at": "2025-01-17T10:59:26.614Z", "status": "awaiting_deliver", "substatus": "posting_awaiting_passport_data", "delivery_method": { @@ -301,7 +303,7 @@ func TestGetFBSShipmentsList(t *testing.T) { ], "has_next": true } - }`, + }`, }, // Test No Client-Id or Api-Key { @@ -591,8 +593,10 @@ func TestGetShipmentDataByIdentifier(t *testing.T) { "posting_number": "57195475-0050-3", "order_id": 438764970, "order_number": "57195475-0050", + "pickup_code_verified_at": "2025-01-17T11:04:59.958Z", "status": "awaiting_packaging", "substatus": "posting_awaiting_passport_data", + "previous_substatus": "posting_transferring_to_delivery", "delivery_method": { "id": 18114520187000, "name": "Ozon Логистика самостоятельно, Москва", @@ -3371,3 +3375,54 @@ func TestDeleteShipment(t *testing.T) { } } } + +func TestVerifyCourierCode(t *testing.T) { + t.Parallel() + + tests := []struct { + statusCode int + headers map[string]string + params *VerifyCourierCodeParams + response string + }{ + // Test Ok + { + http.StatusOK, + map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, + &VerifyCourierCodeParams{ + PickupCode: "string", + PostingNumber: "string", + }, + `{ + "valid": true + }`, + }, + // Test No Client-Id or Api-Key + { + http.StatusUnauthorized, + map[string]string{}, + &VerifyCourierCodeParams{}, + `{ + "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().VerifyCourierCode(ctx, test.params) + if err != nil { + t.Error(err) + continue + } + + compareJsonResponse(t, test.response, &VerifyCourierCodeResponse{}) + + if resp.StatusCode != test.statusCode { + t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) + } + } +}