-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtransfer_control_client.go
More file actions
executable file
·196 lines (185 loc) · 5.12 KB
/
transfer_control_client.go
File metadata and controls
executable file
·196 lines (185 loc) · 5.12 KB
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
package paystack
import (
"context"
"net/http"
"github.com/gray-adeyi/paystack/enum"
)
// TransferControlClient interacts with endpoints related to paystack transfer control resource that lets
// you manage settings of your Transfers.
type TransferControlClient struct {
*restClient
}
// NewTransferControlClient creates a TransferControlClient
func NewTransferControlClient(options ...ClientOptions) *TransferControlClient {
client := NewClient(options...)
return client.TransferControl
}
// Balance lets you retrieve the available balance on your Integration
//
// Default response: models.Response[[]models.IntegrationBalance]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[[]models.IntegrationBalance]
// if err := client.TransferControl.Balance(context.TODO(), &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) Balance(ctx context.Context, response any) error {
return t.APICall(ctx, http.MethodGet, "/balance", nil, response)
}
// BalanceLedger lets you retrieve all pay-ins and pay-outs that occurred on your Integration
//
// Default response: models.Response[[]models.BalanceLedgerItem]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[[]models.BalanceLedgerItem]
// if err := client.TransferControl.BalanceLedger(context.TODO(), &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) BalanceLedger(ctx context.Context, response any) error {
return t.APICall(ctx, http.MethodGet, "/balance/ledger", nil, response)
}
// ResendOtp lets you generate a new OTP and sends to customer in the event they are having trouble receiving one.
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// "github.com/gray-adeyi/paystack/enum"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[struct{}]
// if err := client.TransferControl.ResendOtp(context.TODO(),"TRF_vsyqdmlzble3uii",enum.ReasonResendOtp, &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) ResendOtp(ctx context.Context, transferCode string, reason enum.Reason, response any) error {
payload := map[string]any{
"transfer_code": transferCode,
"reason": reason,
}
return t.APICall(ctx, http.MethodPost, "/transfer/resend_otp", payload, response)
}
// DisableOtp lets you complete Transfers without use of OTPs.
// You will get an OTP to complete the request.
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[struct{}]
// if err := client.TransferControl.DisableOtp(context.TODO(), &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) DisableOtp(ctx context.Context, response any) error {
return t.APICall(ctx, http.MethodPost, "/transfer/disable_otp", nil, response)
}
// FinalizeDisableOtp lets you finalize the request to disable OTP on your Transfers.
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[struct{}]
// if err := client.TransferControl.FinalizeDisableOtp(context.TODO(),"<otp>", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) FinalizeDisableOtp(ctx context.Context, otp string, response any) error {
payload := map[string]any{"otp": otp}
return t.APICall(ctx, http.MethodPost, "/transfer/disable_otp", payload, response)
}
// EnableOtp lets you turn OTP requirement back on.
//
// Default response: models.Response[struct{}]
//
// Example:
//
// import (
// "context"
// "fmt"
//
// p "github.com/gray-adeyi/paystack"
// "github.com/gray-adeyi/paystack/models"
// )
//
// func main() {
// client := p.NewClient(p.WithSecretKey("<paystack-secret-key>"))
//
// var response models.Response[struct{}]
// if err := client.TransferControl.EnableOtp(context.TODO(),"<otp>", &response); err != nil {
// panic(err)
// }
//
// fmt.Println(response)
// }
func (t *TransferControlClient) EnableOtp(ctx context.Context, response any) error {
return t.APICall(ctx, http.MethodPost, "/transfer/enable_otp", nil, response)
}