Skip to content

Commit

Permalink
check shipments resource against api reference (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar authored Mar 16, 2024
1 parent 5c00b3e commit 86b999a
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 83 deletions.
77 changes: 51 additions & 26 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type CreatePaymentRefund](<#CreatePaymentRefund>)
- [type CreatePreAuthorizedPaymentFields](<#CreatePreAuthorizedPaymentFields>)
- [type CreateRecurrentPaymentFields](<#CreateRecurrentPaymentFields>)
- [type CreateShipmentRequest](<#CreateShipmentRequest>)
- [type CreateShipment](<#CreateShipment>)
- [type CreateSubscription](<#CreateSubscription>)
- [type Customer](<#Customer>)
- [type CustomerLinks](<#CustomerLinks>)
Expand Down Expand Up @@ -341,14 +341,15 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [func \(ss \*SettlementsService\) Next\(ctx context.Context\) \(res \*Response, s \*Settlement, err error\)](<#SettlementsService.Next>)
- [func \(ss \*SettlementsService\) Open\(ctx context.Context\) \(res \*Response, s \*Settlement, err error\)](<#SettlementsService.Open>)
- [type Shipment](<#Shipment>)
- [type ShipmentAccessTokenFields](<#ShipmentAccessTokenFields>)
- [type ShipmentLinks](<#ShipmentLinks>)
- [type ShipmentTracking](<#ShipmentTracking>)
- [type ShipmentsList](<#ShipmentsList>)
- [type ShipmentsService](<#ShipmentsService>)
- [func \(ss \*ShipmentsService\) Create\(ctx context.Context, oID string, cs CreateShipmentRequest\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Create>)
- [func \(ss \*ShipmentsService\) Get\(ctx context.Context, oID string, sID string\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Get>)
- [func \(ss \*ShipmentsService\) List\(ctx context.Context, oID string\) \(res \*Response, sl \*ShipmentsList, err error\)](<#ShipmentsService.List>)
- [func \(ss \*ShipmentsService\) Update\(ctx context.Context, oID string, sID string, st ShipmentTracking\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Update>)
- [func \(ss \*ShipmentsService\) Create\(ctx context.Context, order string, cs CreateShipment\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Create>)
- [func \(ss \*ShipmentsService\) Get\(ctx context.Context, order string, shipment string\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Get>)
- [func \(ss \*ShipmentsService\) List\(ctx context.Context, order string\) \(res \*Response, sl \*ShipmentsList, err error\)](<#ShipmentsService.List>)
- [func \(ss \*ShipmentsService\) Update\(ctx context.Context, order string, shipment string, us UpdateShipment\) \(res \*Response, s \*Shipment, err error\)](<#ShipmentsService.Update>)
- [type ShortDate](<#ShortDate>)
- [func \(d \*ShortDate\) MarshalJSON\(\) \(\[\]byte, error\)](<#ShortDate.MarshalJSON>)
- [func \(d \*ShortDate\) UnmarshalJSON\(b \[\]byte\) error](<#ShortDate.UnmarshalJSON>)
Expand Down Expand Up @@ -380,6 +381,7 @@ REST also implies a nice and clean structure for URLs or endpoints. This means y
- [type UpdateOrder](<#UpdateOrder>)
- [type UpdateOrderLine](<#UpdateOrderLine>)
- [type UpdatePayment](<#UpdatePayment>)
- [type UpdateShipment](<#UpdateShipment>)
- [type UpdateSubscription](<#UpdateSubscription>)
- [type UsedGiftCard](<#UsedGiftCard>)
- [type UserAgentToken](<#UserAgentToken>)
Expand Down Expand Up @@ -2099,16 +2101,16 @@ type CreateRecurrentPaymentFields struct {
}
```

<a name="CreateShipmentRequest"></a>
## type [CreateShipmentRequest](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L61-L65>)
<a name="CreateShipment"></a>
## type [CreateShipment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L11-L15>)

CreateShipmentRequest defines information required to create a new shipment.
CreateShipment contains information required to create a new shipment.

```go
type CreateShipmentRequest struct {
Lines []OrderLine `json:"lines,omitempty"`
Tracking ShipmentTracking `json:"tracking,omitempty"`
TestMode bool `json:"testmode,omitempty"`
type CreateShipment struct {
Lines []*OrderLine `json:"lines,omitempty"`
Tracking *ShipmentTracking `json:"tracking,omitempty"`
ShipmentAccessTokenFields
}
```

Expand Down Expand Up @@ -5396,7 +5398,7 @@ Open retrieves the details of the open balance of the organization. This will re
See: https://docs.mollie.com/reference/v2/settlements-api/get-open-settlement

<a name="Shipment"></a>
## type [Shipment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L16-L25>)
## type [Shipment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L25-L34>)

Shipment contains information about a user service/product delivery and is used in the figurative sense here. It can also mean that a service was provided or digital content was delivered.

Expand All @@ -5405,16 +5407,27 @@ type Shipment struct {
Resource string `json:"resource,omitempty"`
ID string `json:"id,omitempty"`
OrderID string `json:"orderId,omitempty"`
TestMode bool `json:"testmode,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Tracking *ShipmentTracking `json:"tracking,omitempty"`
Lines []*OrderLine `json:"lines,omitempty"`
Links ShipmentLinks `json:"_links,omitempty"`
ShipmentAccessTokenFields
}
```

<a name="ShipmentAccessTokenFields"></a>
## type [ShipmentAccessTokenFields](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L18-L20>)

ShipmentAccessTokenFields describes the fields available when using an access token.

```go
type ShipmentAccessTokenFields struct {
Testmode bool `json:"testmode,omitempty"`
}
```

<a name="ShipmentLinks"></a>
## type [ShipmentLinks](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L36-L40>)
## type [ShipmentLinks](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L51-L55>)

ShipmentLinks contains URL objects with shipment relevant information for the user.

Expand All @@ -5427,7 +5440,7 @@ type ShipmentLinks struct {
```

<a name="ShipmentTracking"></a>
## type [ShipmentTracking](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L28-L32>)
## type [ShipmentTracking](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L43-L47>)

ShipmentTracking contains shipment tracking details.

Expand All @@ -5440,7 +5453,7 @@ type ShipmentTracking struct {
```

<a name="ShipmentsList"></a>
## type [ShipmentsList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L94-L100>)
## type [ShipmentsList](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L58-L64>)

ShipmentsList describes how a list of payments will be retrieved by Mollie.

Expand All @@ -5455,7 +5468,7 @@ type ShipmentsList struct {
```

<a name="ShipmentsService"></a>
## type [ShipmentsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L11>)
## type [ShipmentsService](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L67>)

ShipmentsService operates on shipments endpoints.

Expand All @@ -5464,43 +5477,43 @@ type ShipmentsService service
```

<a name="ShipmentsService.Create"></a>
### func \(\*ShipmentsService\) [Create](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L70-L74>)
### func \(\*ShipmentsService\) [Create](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L94-L98>)

```go
func (ss *ShipmentsService) Create(ctx context.Context, oID string, cs CreateShipmentRequest) (res *Response, s *Shipment, err error)
func (ss *ShipmentsService) Create(ctx context.Context, order string, cs CreateShipment) (res *Response, s *Shipment, err error)
```

Create can be used to ship order lines.

See: https://docs.mollie.com/reference/v2/shipments-api/create-shipment

<a name="ShipmentsService.Get"></a>
### func \(\*ShipmentsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L45>)
### func \(\*ShipmentsService\) [Get](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L72-L76>)

```go
func (ss *ShipmentsService) Get(ctx context.Context, oID string, sID string) (res *Response, s *Shipment, err error)
func (ss *ShipmentsService) Get(ctx context.Context, order string, shipment string) (res *Response, s *Shipment, err error)
```

Get retrieves a single shipment and the order lines shipped by a shipment’s ID.

See: https://docs.mollie.com/reference/v2/shipments-api/get-shipment#

<a name="ShipmentsService.List"></a>
### func \(\*ShipmentsService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L105>)
### func \(\*ShipmentsService\) [List](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L120>)

```go
func (ss *ShipmentsService) List(ctx context.Context, oID string) (res *Response, sl *ShipmentsList, err error)
func (ss *ShipmentsService) List(ctx context.Context, order string) (res *Response, sl *ShipmentsList, err error)
```

List retrieves all shipments for an order.

See: https://docs.mollie.com/reference/v2/shipments-api/list-shipments

<a name="ShipmentsService.Update"></a>
### func \(\*ShipmentsService\) [Update](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L123-L127>)
### func \(\*ShipmentsService\) [Update](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L138-L142>)

```go
func (ss *ShipmentsService) Update(ctx context.Context, oID string, sID string, st ShipmentTracking) (res *Response, s *Shipment, err error)
func (ss *ShipmentsService) Update(ctx context.Context, order string, shipment string, us UpdateShipment) (res *Response, s *Shipment, err error)
```

Update can be used to update the tracking information of a shipment
Expand Down Expand Up @@ -5974,6 +5987,18 @@ type UpdatePayment struct {
}
```

<a name="UpdateShipment"></a>
## type [UpdateShipment](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/shipments.go#L37-L40>)

UpdateShipment contains information required to update a shipment.

```go
type UpdateShipment struct {
Tracking *ShipmentTracking `json:"tracking,omitempty"`
ShipmentAccessTokenFields
}
```

<a name="UpdateSubscription"></a>
## type [UpdateSubscription](<https://github.com/VictorAvelar/mollie-api-go/blob/master/mollie/subscriptions.go#L44-L55>)

Expand Down
73 changes: 44 additions & 29 deletions mollie/shipments.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ import (
"time"
)

// ShipmentsService operates on shipments endpoints.
type ShipmentsService service
// CreateShipment contains information required to create a new shipment.
type CreateShipment struct {
Lines []*OrderLine `json:"lines,omitempty"`
Tracking *ShipmentTracking `json:"tracking,omitempty"`
ShipmentAccessTokenFields
}

// ShipmentAccessTokenFields describes the fields available when using an access token.
type ShipmentAccessTokenFields struct {
Testmode bool `json:"testmode,omitempty"`
}

// Shipment contains information about a user service/product delivery and
// is used in the figurative sense here.
Expand All @@ -17,11 +26,17 @@ type Shipment struct {
Resource string `json:"resource,omitempty"`
ID string `json:"id,omitempty"`
OrderID string `json:"orderId,omitempty"`
TestMode bool `json:"testmode,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
Tracking *ShipmentTracking `json:"tracking,omitempty"`
Lines []*OrderLine `json:"lines,omitempty"`
Links ShipmentLinks `json:"_links,omitempty"`
ShipmentAccessTokenFields
}

// UpdateShipment contains information required to update a shipment.
type UpdateShipment struct {
Tracking *ShipmentTracking `json:"tracking,omitempty"`
ShipmentAccessTokenFields
}

// ShipmentTracking contains shipment tracking details.
Expand All @@ -39,11 +54,27 @@ type ShipmentLinks struct {
Documentation *URL `json:"documentation,omitempty"`
}

// ShipmentsList describes how a list of payments will be retrieved by Mollie.
type ShipmentsList struct {
Count int `json:"count,omitempty"`
Embedded struct {
Shipments []Shipment
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}

// ShipmentsService operates on shipments endpoints.
type ShipmentsService service

// Get retrieves a single shipment and the order lines shipped by a shipment’s ID.
//
// See: https://docs.mollie.com/reference/v2/shipments-api/get-shipment#
func (ss *ShipmentsService) Get(ctx context.Context, oID string, sID string) (res *Response, s *Shipment, err error) {
u := fmt.Sprintf("v2/orders/%s/shipments/%s", oID, sID)
func (ss *ShipmentsService) Get(ctx context.Context, order string, shipment string) (
res *Response,
s *Shipment,
err error,
) {
u := fmt.Sprintf("v2/orders/%s/shipments/%s", order, shipment)

res, err = ss.client.get(ctx, u, nil)
if err != nil {
Expand All @@ -57,25 +88,18 @@ func (ss *ShipmentsService) Get(ctx context.Context, oID string, sID string) (re
return
}

// CreateShipmentRequest defines information required to create a new shipment.
type CreateShipmentRequest struct {
Lines []OrderLine `json:"lines,omitempty"`
Tracking ShipmentTracking `json:"tracking,omitempty"`
TestMode bool `json:"testmode,omitempty"`
}

// Create can be used to ship order lines.
//
// See: https://docs.mollie.com/reference/v2/shipments-api/create-shipment
func (ss *ShipmentsService) Create(ctx context.Context, oID string, cs CreateShipmentRequest) (
func (ss *ShipmentsService) Create(ctx context.Context, order string, cs CreateShipment) (
res *Response,
s *Shipment,
err error,
) {
uri := fmt.Sprintf("v2/orders/%s/shipments", oID)
uri := fmt.Sprintf("v2/orders/%s/shipments", order)

if ss.client.HasAccessToken() && ss.client.config.testing {
cs.TestMode = true
cs.Testmode = true
}

res, err = ss.client.post(ctx, uri, cs, nil)
Expand All @@ -90,20 +114,11 @@ func (ss *ShipmentsService) Create(ctx context.Context, oID string, cs CreateShi
return
}

// ShipmentsList describes how a list of payments will be retrieved by Mollie.
type ShipmentsList struct {
Count int `json:"count,omitempty"`
Embedded struct {
Shipments []Shipment
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}

// List retrieves all shipments for an order.
//
// See: https://docs.mollie.com/reference/v2/shipments-api/list-shipments
func (ss *ShipmentsService) List(ctx context.Context, oID string) (res *Response, sl *ShipmentsList, err error) {
u := fmt.Sprintf("v2/orders/%s/shipments", oID)
func (ss *ShipmentsService) List(ctx context.Context, order string) (res *Response, sl *ShipmentsList, err error) {
u := fmt.Sprintf("v2/orders/%s/shipments", order)

res, err = ss.client.get(ctx, u, nil)
if err != nil {
Expand All @@ -120,14 +135,14 @@ func (ss *ShipmentsService) List(ctx context.Context, oID string) (res *Response
// Update can be used to update the tracking information of a shipment
//
// See: https://docs.mollie.com/reference/v2/shipments-api/update-shipment
func (ss *ShipmentsService) Update(ctx context.Context, oID string, sID string, st ShipmentTracking) (
func (ss *ShipmentsService) Update(ctx context.Context, order string, shipment string, us UpdateShipment) (
res *Response,
s *Shipment,
err error,
) {
u := fmt.Sprintf("v2/orders/%s/shipments/%s", oID, sID)
u := fmt.Sprintf("v2/orders/%s/shipments/%s", order, shipment)

res, err = ss.client.patch(ctx, u, st, nil)
res, err = ss.client.patch(ctx, u, us, nil)
if err != nil {
return
}
Expand Down
Loading

0 comments on commit 86b999a

Please sign in to comment.