This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
directdebit.go
73 lines (60 loc) · 2.1 KB
/
directdebit.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
73
package starling
import (
"context"
"net/http"
)
// DirectDebitMandate represents a single mandate
type DirectDebitMandate struct {
UID string `json:"uid"`
Reference string `json:"reference"`
Status string `json:"status"`
Source string `json:"source"`
Created string `json:"created"`
Cancelled string `json:"cancelled"`
OriginatorName string `json:"originatorName"`
OriginatorUID string `json:"originatorUid"`
}
// DirectDebitMandates represents a list of mandates
type directDebitMandates struct {
Mandates []DirectDebitMandate `json:"mandates"`
}
// HALContacts is a HAL wrapper around the DirectDebitMandates type.
type halDirectDebitMandates struct {
Links struct{} `json:"_links"`
Embedded *directDebitMandates `json:"_embedded"`
}
// DirectDebitMandates returns the DirectDebitMandates for the current customer.
func (c *Client) DirectDebitMandates(ctx context.Context) ([]DirectDebitMandate, *http.Response, error) {
req, err := c.NewRequest("GET", "/api/v1/direct-debit/mandates", nil)
if err != nil {
return nil, nil, err
}
hMandates := new(halDirectDebitMandates)
resp, err := c.Do(ctx, req, &hMandates)
if hMandates == nil {
return nil, resp, err
}
if hMandates.Embedded == nil {
return nil, resp, err
}
return hMandates.Embedded.Mandates, resp, err
}
// DirectDebitMandate returns a single DirectDebitMandate for the current customer.
func (c *Client) DirectDebitMandate(ctx context.Context, uid string) (*DirectDebitMandate, *http.Response, error) {
req, err := c.NewRequest("GET", "/api/v1/direct-debit/mandates/"+uid, nil)
if err != nil {
return nil, nil, err
}
var mandate *DirectDebitMandate
resp, err := c.Do(ctx, req, &mandate)
return mandate, resp, err
}
// DeleteDirectDebitMandate deletes an individual DirectDebitMandate for the current customer.
func (c *Client) DeleteDirectDebitMandate(ctx context.Context, uid string) (*http.Response, error) {
req, err := c.NewRequest("DELETE", "/api/v1/direct-debit/mandates/"+uid, nil)
if err != nil {
return nil, err
}
resp, err := c.Do(ctx, req, nil)
return resp, err
}