-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathsubaccount.go
83 lines (72 loc) · 3.22 KB
/
subaccount.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
package paystack
import "fmt"
// SubAccountService handles operations related to sub accounts
// For more details see https://developers.paystack.co/v1.0/reference#create-subaccount
type SubAccountService service
// SubAccount is the resource representing your Paystack subaccount.
// For more details see https://developers.paystack.co/v1.0/reference#create-subaccount
type SubAccount struct {
ID int `json:"id,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Domain string `json:"domain,omitempty"`
Integration int `json:"integration,omitempty"`
BusinessName string `json:"business_name,omitempty"`
SubAccountCode string `json:"subaccount_code,omitempty"`
Description string `json:"description,omitempty"`
PrimaryContactName string `json:"primary_contact_name,omitempty"`
PrimaryContactEmail string `json:"primary_contact_email,omitempty"`
PrimaryContactPhone string `json:"primary_contact_phone,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
PercentageCharge float32 `json:"percentage_charge,omitempty"`
IsVerified bool `json:"is_verified,omitempty"`
SettlementBank string `json:"settlement_bank,omitempty"`
AccountNumber string `json:"account_number,omitempty"`
SettlementSchedule string `json:"settlement_schedule,omitempty"`
Active bool `json:"active,omitempty"`
Migrate bool `json:"migrate,omitempty"`
}
// SubAccountList is a list object for subaccounts.
type SubAccountList struct {
Meta ListMeta
Values []SubAccount `json:"data"`
}
// Create creates a new subaccount
// For more details see https://paystack.com/docs/api/#subaccount-create
func (s *SubAccountService) Create(subaccount *SubAccount) (*SubAccount, error) {
u := fmt.Sprintf("/subaccount")
acc := &SubAccount{}
err := s.client.Call("POST", u, subaccount, acc)
return acc, err
}
// Update updates a subaccount's properties.
// For more details see https://developers.paystack.co/v1.0/reference#update-subaccount
// TODO: use ID or slug
func (s *SubAccountService) Update(subaccount *SubAccount) (*SubAccount, error) {
u := fmt.Sprintf("subaccount/%d", subaccount.ID)
acc := &SubAccount{}
err := s.client.Call("PUT", u, subaccount, acc)
return acc, err
}
// Get returns the details of a subaccount.
// For more details see https://developers.paystack.co/v1.0/reference#fetch-subaccount
// TODO: use ID or slug
func (s *SubAccountService) Get(id int) (*SubAccount, error) {
u := fmt.Sprintf("/subaccount/%d", id)
acc := &SubAccount{}
err := s.client.Call("GET", u, nil, acc)
return acc, err
}
// List returns a list of subaccounts.
// For more details see https://developers.paystack.co/v1.0/reference#list-subaccounts
func (s *SubAccountService) List() (*SubAccountList, error) {
return s.ListN(10, 1)
}
// ListN returns a list of subaccounts
// For more details see https://paystack.com/docs/api/#subaccount-list
func (s *SubAccountService) ListN(count, offset int) (*SubAccountList, error) {
u := paginateURL("/subaccount", count, offset)
acc := &SubAccountList{}
err := s.client.Call("GET", u, nil, acc)
return acc, err
}