forked from checkout/checkout-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
119 lines (100 loc) · 2.74 KB
/
client.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package nas
import (
"github.com/PaddleHQ/checkout-sdk-go/client"
"github.com/PaddleHQ/checkout-sdk-go/common"
"github.com/PaddleHQ/checkout-sdk-go/configuration"
"github.com/PaddleHQ/checkout-sdk-go/instruments"
)
type Client struct {
configuration *configuration.Configuration
apiClient client.HttpClient
}
func NewClient(configuration *configuration.Configuration, apiClient client.HttpClient) *Client {
return &Client{
configuration: configuration,
apiClient: apiClient,
}
}
func (c *Client) Create(request CreateInstrumentRequest) (*CreateInstrumentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}
var response CreateInstrumentResponse
err = c.apiClient.Post(
common.BuildPath(instruments.Path),
auth,
request,
&response,
nil,
)
if err != nil {
return nil, err
}
return &response, nil
}
func (c *Client) Get(instrumentId string) (*GetInstrumentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}
var response GetInstrumentResponse
err = c.apiClient.Get(common.BuildPath(instruments.Path, instrumentId), auth, &response)
if err != nil {
return nil, err
}
return &response, nil
}
func (c *Client) GetBankAccountFieldFormatting(
country string,
currency string,
query QueryBankAccountFormatting,
) (*GetBankAccountFieldFormattingResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.OAuth)
if err != nil {
return nil, err
}
url, err := common.BuildQueryPath(
common.BuildPath(instruments.ValidationPath,
country,
currency),
query)
if err != nil {
return nil, err
}
var response GetBankAccountFieldFormattingResponse
err = c.apiClient.Get(url, auth, &response)
if err != nil {
return nil, err
}
return &response, nil
}
func (c *Client) Update(instrumentId string, request UpdateInstrumentRequest) (*UpdateInstrumentResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}
var response UpdateInstrumentResponse
err = c.apiClient.Patch(
common.BuildPath(instruments.Path, instrumentId),
auth,
request,
&response,
)
if err != nil {
return nil, err
}
return &response, nil
}
func (c *Client) Delete(instrumentId string) (*common.MetadataResponse, error) {
auth, err := c.configuration.Credentials.GetAuthorization(configuration.SecretKeyOrOauth)
if err != nil {
return nil, err
}
var response common.MetadataResponse
err = c.apiClient.Delete(common.BuildPath(instruments.Path, instrumentId), auth, &response)
if err != nil {
return nil, err
}
return &response, nil
}