-
Notifications
You must be signed in to change notification settings - Fork 9
/
ondemand_authorization.go
52 lines (40 loc) · 1.5 KB
/
ondemand_authorization.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
package dwolla
import (
"context"
"fmt"
)
// OnDemandAuthorizationService is the on-demand authorization interface
//
// see: https://docsv2.dwolla.com/#create-an-on-demand-transfer-authorization
type OnDemandAuthorizationService interface {
Create(context.Context) (*OnDemandAuthorization, error)
Retrieve(context.Context, string) (*OnDemandAuthorization, error)
}
// OnDemandAuthorizationServiceOp is an implementation of the on-demand authorization interface
type OnDemandAuthorizationServiceOp struct {
client *Client
}
// OnDemandAuthorization is a dwolla on-demand transfer authorization
type OnDemandAuthorization struct {
Resource
BodyText string `json:"bodyText"`
ButtonText string `json:"buttonText"`
}
// Create creates an on-demand transfer authorization
func (o *OnDemandAuthorizationServiceOp) Create(ctx context.Context) (*OnDemandAuthorization, error) {
var authorization OnDemandAuthorization
if err := o.client.Post(ctx, "on-demand-authorizations", nil, nil, &authorization); err != nil {
return nil, err
}
authorization.client = o.client
return &authorization, nil
}
// Retrieve returns a on-demand authorization matching the id
func (o *OnDemandAuthorizationServiceOp) Retrieve(ctx context.Context, id string) (*OnDemandAuthorization, error) {
var authorization OnDemandAuthorization
if err := o.client.Get(ctx, fmt.Sprintf("on-demand-authorizations/%s", id), nil, nil, &authorization); err != nil {
return nil, err
}
authorization.client = o.client
return &authorization, nil
}