-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.go
39 lines (32 loc) · 1.05 KB
/
statement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package clearbank
import (
"context"
"fmt"
"net/http"
)
type StatementClient interface {
RequestStatement(context.Context, StatementPayload) error
RequestStatementFor(context.Context, string, StatementPayload) error
}
type StatementPayload struct {
Year int `json:"year"`
Month int `json:"month"`
Format string `json:"format"`
Currency string `json:"currency"`
}
func (c *client) RequestStatement(ctx context.Context, payload StatementPayload) error {
req, err := c.newRequest(ctx, http.MethodPost, "/mccy/v1/StatementRequests", payload)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
req.ExpectStatus(http.StatusAccepted)
return c.do(ctx, req)
}
func (c *client) RequestStatementFor(ctx context.Context, iban string, payload StatementPayload) error {
req, err := c.newRequest(ctx, http.MethodPost, fmt.Sprintf("/mccy/v1/StatementRequests/account/%s", iban), payload)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
req.ExpectStatus(http.StatusAccepted)
return c.do(ctx, req)
}