-
Notifications
You must be signed in to change notification settings - Fork 0
/
settlement_client.go
106 lines (101 loc) · 3.75 KB
/
settlement_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
package paystack
import (
"fmt"
"net/http"
)
// SettlementClient interacts with endpoints related to paystack settlement resource that lets you
// gain insights into payouts made by Paystack to your bank account.
type SettlementClient struct {
*baseAPIClient
}
// NewSettlementClient creates a SettlementClient
//
// Example
//
// import p "github.com/gray-adeyi/paystack"
//
// sClient := p.NewSettlementClient(p.WithSecretKey("<paystack-secret-key>"))
func NewSettlementClient(options ...ClientOptions) *SettlementClient {
client := NewAPIClient(options...)
return client.Settlements
}
// All lets you retrieve Settlements made to your settlement accounts
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// sClient := p.NewSettlementClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a settlement client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.Settlements field is a `SettlementClient`
// // Therefore, this is possible
// // resp, err := paystackClient.Settlements.All()
//
// // All also accepts queries, so say you want to customize how many payment pages to retrieve
// // and which page to retrieve, you can write it like so.
// // resp, err := sClient.All(p.WithQuery("perPage","50"), p.WithQuery("page","2"))
//
// // see https://paystack.com/docs/api/settlement/#list for supported query parameters
//
// resp, err := sClient.All()
// 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 (s *SettlementClient) All(queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl("/settlement", queries...)
return s.APICall(http.MethodGet, url, nil)
}
// AllTransactions lets you retrieve the Transactions that make up a particular settlement
//
// Example:
//
// import (
// "fmt"
// p "github.com/gray-adeyi/paystack"
// "encoding/json"
// )
//
// sClient := p.NewSettlementClient(p.WithSecretKey("<paystack-secret-key>"))
// // Alternatively, you can access a settlement client from an APIClient
// // paystackClient := p.NewAPIClient(p.WithSecretKey("<paystack-secret-key>"))
// // paystackClient.Settlements field is a `SettlementClient`
// // Therefore, this is possible
// // resp, err := paystackClient.Settlements.AllTransactions("<settlementId>")
//
// // All also accepts queries, so say you want to customize how many payment pages to retrieve
// // and which page to retrieve, you can write it like so.
// // resp, err := sClient.AllTransactions("<settlementId>", p.WithQuery("perPage","50"), p.WithQuery("page","2"))
//
// // see https://paystack.com/docs/api/settlement/#transactions for supported query parameters
//
// resp, err := sClient.AllTransactions("<settlementId>")
// 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 (s *SettlementClient) AllTransactions(settlementId string, queries ...Query) (*Response, error) {
url := AddQueryParamsToUrl(fmt.Sprintf("/settlement/%s", settlementId), queries...)
return s.APICall(http.MethodGet, url, nil)
}