-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer_control_client.go
230 lines (221 loc) · 7.99 KB
/
transfer_control_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package paystack
import "net/http"
// TransferControlClient interacts with endpoints related to paystack transfer control resource that lets
// you manage settings of your Transfers.
type TransferControlClient struct {
*baseAPIClient
}
// NewTransferControlClient creates a TransferControlClient
//
// Example
//
// import p "github.com/gray-adeyi/paystack"
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
func NewTransferControlClient(options ...ClientOptions) *TransferControlClient {
client := NewAPIClient(options...)
return client.TransferControl
}
// Balance lets you retrieve the available balance on your Integration
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.Balance()
//
// resp, err := tcClient.Balance()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) Balance() (*Response, error) {
return t.APICall(http.MethodGet, "/balance", nil)
}
// BalanceLedger lets you retrieve all pay-ins and pay-outs that occurred on your Integration
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.BalanceLedger()
//
// resp, err := tcClient.BalanceLedger()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) BalanceLedger() (*Response, error) {
return t.APICall(http.MethodGet, "/balance/ledger", nil)
}
// ResendOTP lets you generate a new OTP and sends to customer in the event they are having trouble receiving one.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.ResendOTP("TRF_vsyqdmlzble3uii","resend_otp")
//
// resp, err := tcClient.ResendOTP("TRF_vsyqdmlzble3uii","resend_otp")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) ResendOTP(transferCode string, reason string) (*Response, error) {
payload := make(map[string]interface{})
payload["transfer_code"] = transferCode
payload["reason"] = reason
return t.APICall(http.MethodPost, "/transfer/resend_otp", payload)
}
// DisableOTP lets you complete Transfers without use of OTPs.
// You will get an OTP to complete the request.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.DisableOTP()
//
// resp, err := tcClient.DisableOTP()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) DisableOTP() (*Response, error) {
return t.APICall(http.MethodPost, "/transfer/disable_otp", nil)
}
// FinalizeDisableOTP lets you finalize the request to disable OTP on your Transfers.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.FinalizeDisableOTP("<otp>")
//
// resp, err := tcClient.FinalizeDisableOTP("<otp>")
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) FinalizeDisableOTP(otp string) (*Response, error) {
payload := map[string]interface{}{"otp": otp}
return t.APICall(http.MethodPost, "/transfer/disable_otp", payload)
}
// EnableOTP lets you turn OTP requirement back on.
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// tcClient := p.NewTransferControlClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a transfer control client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.TransferControl field is a `TransferControlClient`
// // Therefore, this is possible
// // resp, err := paystackClient.TransferControl.EnableOTP()
//
// resp, err := tcClient.EnableOTP()
// if err != nil {
// panic(err)
// }
// // you can have data be a custom structure based on the data your interested in retrieving from
// // from paystack for simplicity, we're using `map[string]interface{}` which is sufficient to
// // to serialize the json data returned by paystack
// data := make(map[string]interface{})
//
// err := json.Unmarshal(resp.Data, &data); if err != nil {
// panic(err)
// }
// fmt.Println(data)
func (t *TransferControlClient) EnableOTP() (*Response, error) {
return t.APICall(http.MethodPost, "/transfer/enable_otp", nil)
}