add method for getting shipment data by barcode for fbs

This commit is contained in:
diPhantxm
2023-03-18 16:20:51 +03:00
parent 159e1501df
commit 0fe3d86c48
6 changed files with 218 additions and 5 deletions

View File

@@ -92,7 +92,7 @@
- [x] List of unprocessed shipments (version 3) - [x] List of unprocessed shipments (version 3)
- [x] Shipments list (version 3) - [x] Shipments list (version 3)
- [ ] Get shipment details by identifier (version 3) - [ ] Get shipment details by identifier (version 3)
- [ ] Get shipment data by barcode - [x] Get shipment data by barcode
- [ ] List of manufacturing countries - [ ] List of manufacturing countries
- [ ] Set the manufacturing country - [ ] Set the manufacturing country
- [ ] Specify number of boxes for multi-box shipments - [ ] Specify number of boxes for multi-box shipments

View File

@@ -112,7 +112,7 @@ type GetStocksOnWarehousesParams struct {
// Number of values per page. // Number of values per page.
// //
// Default is 100 // Default is 100
Limit int64 `json:"limit"` Limit int64 `json:"limit" default:"100"`
// Number of elements that will be skipped in the response. For example, if `offset=10`, the response will start with the 11th element found // Number of elements that will be skipped in the response. For example, if `offset=10`, the response will start with the 11th element found
Offset int64 `json:"offset"` Offset int64 `json:"offset"`

View File

@@ -456,3 +456,105 @@ func (c FBS) ValidateLabelingCodes(params *ValidateLabelingCodesParams) (*Valida
return resp, nil return resp, nil
} }
type GetShipmentDataByBarcodeParams struct {
// Shipment barcode
Barcode string `json:"barcode"`
}
type GetShipmentDataByBarcodeResponse struct {
core.CommonResponse
// Method result
Result struct {
// Analytical data
AnalyticsData struct {
// Delivery city
City string `json:"city"`
// Delivery method
DeliveryType string `json:"delivery_type"`
// Indication that the recipient is a legal entity:
// - true — a legal entity
// - false — a natural person
IsLegal bool `json:"is_legal"`
// Premium subscription availability
IsPremium bool `json:"is_premium"`
// Payment method
PaymentTypeGroupName string `json:"payment_type_group_name"`
// Delivery region
Region string `json:"region"`
} `json:"analytics_data"`
// Shipment barcodes
Barcodes struct {
// Lower barcode on the shipment label
Lower string `json:"lower_barcode"`
// Upper barcode on the shipment label
Upper string `json:"upper_barcode"`
} `json:"barcodes"`
// Cancellation reason identifier
CancelReasonId int64 `json:"cancel_reason_id"`
// Date and time when the shipment was created
CreatedAt time.Time `json:"created_at"`
// Financial data
FinancialData struct {
// Identifier of the cluster, where the shipment is sent from
ClusterFrom string `json:"cluster_from"`
// Identifier of the cluster, where the shipment is delivered to
ClusterTo string `json:"cluster_to"`
// Services
PostingServices []MarketplaceServices `json:"posting_services"`
// Products list
Products []FinancialDataProduct `json:"products"`
} `json:"financial_data"`
// Start date and time of shipment processing
InProcessAt time.Time `json:"in_process_at"`
// Order identifier to which the shipment belongs
OrderId int64 `json:"order_id"`
// Order number to which the shipment belongs
OrderNumber string `json:"order_number"`
// Shipment number
PostingNumber string `json:"posting_number"`
// List of products in the shipment
Products []PostingProduct `json:"products"`
// Date and time before which the shipment must be packaged.
// If the shipment is not packaged by this date, it will be canceled automatically
ShipmentDate time.Time `json:"shipment_date"`
// Shipment status
Status string `json:"status"`
} `json:"result"`
}
// Methof for getting shipments data by barcode
func (c FBS) GetShipmentDataByBarcode(params *GetShipmentDataByBarcodeParams) (*GetShipmentDataByBarcodeResponse, error) {
url := "/v2/posting/fbs/get-by-barcode"
resp := &GetShipmentDataByBarcodeResponse{}
response, err := c.client.Request(http.MethodPost, url, params, resp)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -437,3 +437,114 @@ func TestValidateLabelingCodes(t *testing.T) {
} }
} }
} }
func TestGetShipmentDataByBarcode(t *testing.T) {
t.Parallel()
tests := []struct {
statusCode int
headers map[string]string
params *GetShipmentDataByBarcodeParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetShipmentDataByBarcodeParams{
Barcode: "20325804886000",
},
`{
"result": {
"posting_number": "57195475-0050-3",
"order_id": 438764970,
"order_number": "57195475-0050",
"status": "awaiting_packaging",
"delivery_method": {
"id": 18114520187000,
"name": "Ozon Логистика самостоятельно, Москва",
"warehouse_id": 18114520187000,
"warehouse": "Москва основной",
"tpl_provider_id": 24,
"tpl_provider": "Ozon Логистика"
},
"tracking_number": "",
"tpl_integration_type": "ozon",
"in_process_at": "2021-11-20T09:14:16Z",
"shipment_date": "2021-11-23T10:00:00Z",
"delivering_date": null,
"provider_status": "",
"delivery_price": "",
"cancellation": {
"cancel_reason_id": 0,
"cancel_reason": "",
"cancellation_type": "",
"cancelled_after_ship": false,
"affect_cancellation_rating": false,
"cancellation_initiator": ""
},
"customer": null,
"addressee": null,
"products": [
{
"price": "279.0000",
"offer_id": "250-7898-1",
"name": "Кофе ароматизированный \"Шоколадный апельсин\" 250 гр",
"sku": 180550365,
"quantity": 1,
"mandatory_mark": [],
"dimensions": {
"height": "40.00",
"length": "240.00",
"weight": "260",
"width": "140.00"
}
}
],
"barcodes": null,
"analytics_data": null,
"financial_data": null,
"additional_data": [],
"is_express": false,
"requirements": {
"products_requiring_gtd": [],
"products_requiring_country": []
},
"product_exemplars": null
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetShipmentDataByBarcodeParams{},
`{
"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().GetShipmentDataByBarcode(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.Result.OrderId == 0 {
t.Errorf("Order id cannot be 0")
}
if resp.Result.Status == "" {
t.Errorf("Status cannot be empty")
}
}
}
}

View File

@@ -708,7 +708,7 @@ type CreateOrUpdateProductItem struct {
// Service type. Pass one of the values in upper case: // Service type. Pass one of the values in upper case:
// - IS_CODE_SERVICE, // - IS_CODE_SERVICE,
// - IS_NO_CODE_SERVICE // - IS_NO_CODE_SERVICE
ServiceType string `json:"service_type"` ServiceType string `json:"service_type" default:"IS_CODE_SERVICE"`
// VAT rate for the product: // VAT rate for the product:
// - 0 — not subject to VAT, // - 0 — not subject to VAT,

View File

@@ -31,7 +31,7 @@ type GetReportsListParams struct {
// - SELLER_RETURNS — returns report, // - SELLER_RETURNS — returns report,
// - SELLER_POSTINGS — shipments report, // - SELLER_POSTINGS — shipments report,
// - SELLER_FINANCE — financial report // - SELLER_FINANCE — financial report
ReportType string `json:"report_type"` ReportType string `json:"report_type" default:"ALL"`
} }
type GetReportsListResponse struct { type GetReportsListResponse struct {
@@ -408,7 +408,7 @@ type GetShipmentReportParams struct {
// Response language: // Response language:
// - RU — Russian // - RU — Russian
// - EN — English // - EN — English
Language string `json:"language"` Language string `json:"language" default:"DEFAULT"`
} }
type GetShipmentReportFilter struct { type GetShipmentReportFilter struct {