-
Notifications
You must be signed in to change notification settings - Fork 0
/
miscellaneous_client.go
137 lines (131 loc) · 4.83 KB
/
miscellaneous_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
package paystack
import "net/http"
// MiscellaneousClient interacts with endpoints related to paystack Miscellaneous resource that
// provides information that is relevant to other client methods
type MiscellaneousClient struct {
*baseAPIClient
}
// NewMiscellaneousClient creates a MiscellaneousClient
//
// Example
//
// import p "github.com/gray-adeyi/paystack"
//
// miscClient := p.NewMiscellaneousClient(p.WithSecretKey("<paystack-secret-key>"))
func NewMiscellaneousClient(options ...ClientOptions) *MiscellaneousClient {
client := NewAPIClient(options...)
return client.Miscellaneous
}
// Banks lets you retrieve a list of all supported banks and their properties
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// miscClient := p.NewMiscellaneousClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a payment pages client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.Miscellaneous field is a `MiscellaneousClient`
// // Therefore, this is possible
// // resp, err := paystackClient.Miscellaneous.Banks()
//
// // Banks also accepts queries, so say you want to customize how many banks to retrieve
// // and which country the banks to retrieve are from, you can write it like so.
// // resp, err := miscClient.Banks(p.WithQuery("perPage","50"), p.WithQuery("country","nigeria"))
//
// // see https://paystack.com/docs/api/miscellaneous/#bank for supported query parameters
//
// resp, err := miscClient.Banks()
// 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 (p *MiscellaneousClient) Banks(queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl("/bank", queries...)
return p.APICall(http.MethodGet, url, nil)
}
// Countries let you retrieve a list of countries that Paystack currently supports
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// miscClient := p.NewMiscellaneousClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a payment pages client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.Miscellaneous field is a `MiscellaneousClient`
// // Therefore, this is possible
// // resp, err := paystackClient.Miscellaneous.Countries()
//
// resp, err := miscClient.Countries()
// 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 (p *MiscellaneousClient) Countries() (*Response, error) {
return p.APICall(http.MethodGet, "/country", nil)
}
// States lets you retrieve a list of states for a country for address Verification
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// miscClient := p.NewMiscellaneousClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a payment pages client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.Miscellaneous field is a `MiscellaneousClient`
// // Therefore, this is possible
// // resp, err := paystackClient.Miscellaneous.States()
//
// // States also accepts queries, so say you want to specify country the states
// // to retrieve are from, you can write it like so.
// // resp, err := miscClient.States(p.WithQuery("country","nigeria"))
//
// // see https://paystack.com/docs/api/miscellaneous/#avs-states for supported query parameters
//
// resp, err := miscClient.States()
// 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 (p *MiscellaneousClient) States(queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl("/address_verification/states", queries...)
return p.APICall(http.MethodGet, url, nil)
}