diff --git a/v5/client.go b/v5/client.go index 31c096b..4c6b339 100644 --- a/v5/client.go +++ b/v5/client.go @@ -1806,30 +1806,31 @@ func (c *Client) CorporateCustomerEdit(customer CorporateCustomer, by string, si // Example: // // var client = v5.New("https://demo.url", "09jIJ") +// t, _ := time.Parse("2006-01-02 15:04:05", "2012-12-12 12:12:12") // // data, status, err := client.DeliveryTracking( -// v5.DeliveryTrackingRequest{ +// []v5.DeliveryTrackingRequest{{ // DeliveryID: "1", -// TrackNumber "123", -// History: []DeliveryHistoryRecord{ +// TrackNumber: "123", +// History: []v5.DeliveryHistoryRecord{ // { // Code: "cancel", -// UpdatedAt: "2012-12-12 12:12:12" +// UpdatedAt: t.Format(time.RFC3339), // }, -// } -// }, +// }, +// }}, // "delivery-1", // ) // // if err.Error() != "" { -// fmt.Printf("%v", err.RuntimeErr) +// fmt.Printf("%v", err.Error()) // } // // if status >= http.StatusBadRequest { -// fmt.Printf("%v", err.ApiErr()) +// fmt.Printf("%v", err.Error()) // } // -func (c *Client) DeliveryTracking(parameters DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) { +func (c *Client) DeliveryTracking(parameters []DeliveryTrackingRequest, subcode string) (SuccessfulResponse, int, *errs.Failure) { var resp SuccessfulResponse updateJSON, _ := json.Marshal(¶meters) diff --git a/v5/client_test.go b/v5/client_test.go index abed43b..5cce145 100644 --- a/v5/client_test.go +++ b/v5/client_test.go @@ -5473,6 +5473,43 @@ func TestClient_ProductsProperties(t *testing.T) { } } +func TestClient_DeliveryTracking(t *testing.T) { + c := client() + + defer gock.Off() + + p := url.Values{ + "statusUpdate": {`[{"deliveryId":"123","history":[{"code":"1","updatedAt":"2020-01-01T00:00:00:000"}]}]`}, + } + + gock.New(crmURL). + Post("/delivery/generic/subcode/tracking"). + MatchType("url"). + BodyString(p.Encode()). + Reply(200). + BodyString(`{"success": true}`) + + g, status, err := c.DeliveryTracking([]DeliveryTrackingRequest{{ + DeliveryID: "123", + History: []DeliveryHistoryRecord{{ + Code: "1", + UpdatedAt: "2020-01-01T00:00:00:000", + }}, + }}, "subcode") + + if err.Error() != "" { + t.Errorf("%v", err.Error()) + } + + if status != http.StatusOK { + t.Errorf("%v", err.ApiError()) + } + + if g.Success != true { + t.Errorf("%v", err.ApiError()) + } +} + func TestClient_DeliveryShipments(t *testing.T) { c := client() diff --git a/v5/request.go b/v5/request.go index 0de069e..87a5582 100644 --- a/v5/request.go +++ b/v5/request.go @@ -175,10 +175,10 @@ type ProductsPropertiesRequest struct { // DeliveryTrackingRequest type type DeliveryTrackingRequest struct { - DeliveryID string `url:"deliveryId,omitempty"` - TrackNumber string `url:"trackNumber,omitempty"` - History []DeliveryHistoryRecord `url:"history,omitempty,brackets"` - ExtraData map[string]string `url:"extraData,omitempty,brackets"` + DeliveryID string `json:"deliveryId,omitempty"` + TrackNumber string `json:"trackNumber,omitempty"` + History []DeliveryHistoryRecord `json:"history,omitempty,brackets"` + ExtraData map[string]string `json:"extraData,omitempty,brackets"` } // DeliveryShipmentsRequest type