-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagreements_endpoints.go
72 lines (59 loc) · 2.27 KB
/
agreements_endpoints.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package gocardless
import (
"context"
"strconv"
)
// CreateAgreement creates a new agreement for the enduser
func (c Client) CreateAgreement(ctx context.Context, agreementRequestBody AgreementRequestBody) (*Agreement, error) {
var agreement Agreement
err := c.HTTP.Post(ctx, AgreementsEndusersPath, RequestHeadersWithAuth(c.Token.Access), agreementRequestBody, &agreement)
if err != nil {
return nil, err
}
return &agreement, nil
}
// FetchAgreement retrieves an agreement for the enduser by agreementID
func (c Client) FetchAgreement(ctx context.Context, agreementID string) (*Agreement, error) {
var agreement Agreement
err := c.HTTP.Get(ctx, AgreementsEndusersPath+agreementID, RequestHeadersWithAuth(c.Token.Access), &agreement)
if err != nil {
return nil, err
}
return &agreement, nil
}
// ListAgreements returns a list of agreements for the enduser
func (c Client) ListAgreements(ctx context.Context, requestParams *ListAgreementsParams) (*Agreements, error) {
var agreements Agreements
endpointURL := AgreementsEndusersPath
if requestParams != nil {
if requestParams.Limit != 0 {
endpointURL = endpointURL + "?" + strconv.Itoa(requestParams.Limit)
}
if requestParams.Offset != 0 {
endpointURL = endpointURL + "&" + strconv.Itoa(requestParams.Offset)
}
}
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &agreements)
if err != nil {
return nil, err
}
return &agreements, nil
}
// DeleteAgreement deletes an agreement for the enduser by agreementID
func (c Client) DeleteAgreement(ctx context.Context, agreementID string) error {
err := c.HTTP.Delete(ctx, AgreementsEndusersPath+agreementID, RequestHeadersWithAuth(c.Token.Access), nil)
if err != nil {
return err
}
return nil
}
// UpdateAgreement updates an agreement for the enduser by agreementID
func (c Client) UpdateAgreement(ctx context.Context, agreementID string, updateRequestBody UpdateRequestBody) (*Agreement, error) {
var agreement Agreement
// TODO: Check if this is the correct way to update an agreement, The API doc wants to append a /accept to the end of the URL
err := c.HTTP.Put(ctx, AgreementsEndusersPath+agreementID, RequestHeadersWithAuth(c.Token.Access), updateRequestBody, &agreement)
if err != nil {
return nil, err
}
return &agreement, nil
}