Skip to content

Commit

Permalink
Merge pull request #278 from VictorAvelar/feat/add-terminals-api
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorAvelar authored Aug 10, 2023
2 parents e00522c + da233ae commit 8f44c39
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 0 deletions.
99 changes: 99 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ type Client struct {
Partners *PartnerService
Balances *BalancesService
ClientLinks *ClientLinksService
Terminals *TerminalsService
}
```

Expand Down Expand Up @@ -4688,6 +4689,104 @@ type Subtotal struct {

Subtotal balance descriptor.

#### type Terminal

```go
type Terminal struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
ProfileID string `json:"profileID,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Brand string `json:"brand,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
```

Terminal symbolizes a physical device to receive payments.

#### type TerminalList

```go
type TerminalList struct {
Count int `json:"count,omitempty"`
Embedded struct {
Terminals []*Terminal `json:"terminals,omitempty"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}
```

TerminalList describes the response for terminals list endpoints.

#### type TerminalListOptions

```go
type TerminalListOptions struct {
From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
ProfileID string `url:"profileID,omitempty"`
TestMode bool `url:"testMode,omitempty"`
}
```

TerminalListOptions holds query string parameters valid for terminals lists.

ProfileID and TestMode are valid only when using access tokens.

#### type TerminalStatus

```go
type TerminalStatus string
```

TerminalStatus is the status of the terminal, which is a read-only value
determined by Mollie.

```go
const (
TerminalPending TerminalStatus = "pending"
TerminalActive TerminalStatus = "active"
TerminalInactive TerminalStatus = "inactive"
)
```

Possible terminal statuses.

#### type TerminalsService

```go
type TerminalsService service
```

TerminalsService operates over terminals resource.

#### func (*TerminalsService) Get

```go
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error)
```

Get terminal retrieves a single terminal object by its terminal ID.

#### func (*TerminalsService) List

```go
func (ts *TerminalsService) List(ctx context.Context, options *TerminalListOptions) (
res *Response,
tl *TerminalList,
err error,
)
```

List retrieves a list of terminals symbolizing the physical devices to receive
payments.

#### type TransactionType

```go
Expand Down
2 changes: 2 additions & 0 deletions mollie/mollie.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Client struct {
Partners *PartnerService
Balances *BalancesService
ClientLinks *ClientLinksService
Terminals *TerminalsService
}

type service struct {
Expand Down Expand Up @@ -302,6 +303,7 @@ func NewClient(baseClient *http.Client, conf *Config) (mollie *Client, err error
mollie.Partners = (*PartnerService)(&mollie.common)
mollie.Balances = (*BalancesService)(&mollie.common)
mollie.ClientLinks = (*ClientLinksService)(&mollie.common)
mollie.Terminals = (*TerminalsService)(&mollie.common)

mollie.userAgent = strings.Join([]string{
runtime.GOOS,
Expand Down
92 changes: 92 additions & 0 deletions mollie/terminals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package mollie

import (
"context"
"encoding/json"
"fmt"
"time"
)

// TerminalsService operates over terminals resource.
type TerminalsService service

// TerminalStatus is the status of the terminal, which is a read-only value determined by Mollie.
type TerminalStatus string

// Possible terminal statuses.
const (
TerminalPending TerminalStatus = "pending"
TerminalActive TerminalStatus = "active"
TerminalInactive TerminalStatus = "inactive"
)

// Terminal symbolizes a physical device to receive payments.
type Terminal struct {
ID string `json:"id,omitempty"`
Resource string `json:"resource,omitempty"`
ProfileID string `json:"profileID,omitempty"`
Status TerminalStatus `json:"status,omitempty"`
Brand string `json:"brand,omitempty"`
Model string `json:"model,omitempty"`
SerialNumber string `json:"serialNumber,omitempty"`
Currency string `json:"currency,omitempty"`
Description string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}

// Get terminal retrieves a single terminal object by its terminal ID.
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error) {
res, err = ts.client.get(ctx, fmt.Sprintf("v2/terminals/%s", id), nil)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &t); err != nil {
return
}

return
}

// TerminalListOptions holds query string parameters valid for terminals lists.
//
// ProfileID and TestMode are valid only when using access tokens.
type TerminalListOptions struct {
From string `url:"from,omitempty"`
Limit int `url:"limit,omitempty"`
ProfileID string `url:"profileID,omitempty"`
TestMode bool `url:"testMode,omitempty"`
}

// TerminalList describes the response for terminals list endpoints.
type TerminalList struct {
Count int `json:"count,omitempty"`
Embedded struct {
Terminals []*Terminal `json:"terminals,omitempty"`
} `json:"_embedded,omitempty"`
Links PaginationLinks `json:"_links,omitempty"`
}

// List retrieves a list of terminals symbolizing the physical devices to receive payments.
func (ts *TerminalsService) List(ctx context.Context, options *TerminalListOptions) (
res *Response,
tl *TerminalList,
err error,
) {
if ts.client.HasAccessToken() && ts.client.config.testing {
options.TestMode = true
}

res, err = ts.client.get(ctx, "v2/terminals", options)
if err != nil {
return
}

if err = json.Unmarshal(res.content, &tl); err != nil {
return
}

return
}
Loading

0 comments on commit 8f44c39

Please sign in to comment.