-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_splits.go
133 lines (116 loc) · 4.93 KB
/
transaction_splits.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
package paystack
import (
"context"
"fmt"
)
type TransactionSplit struct {
client *Client
}
func newTransactionSplit(client *Client) *TransactionSplit {
return &TransactionSplit{
client: client,
}
}
type TransactionSplitSubAccount struct {
Subaccount string `json:"subaccount,omitempty"`
Share int `json:"share,omitempty"`
}
type TransactionSplitRequest struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Currency string `json:"currency,omitempty"`
Subaccounts []TransactionSplitSubAccount `json:"subaccounts,omitempty"`
BearerType string `json:"bearer_type,omitempty"`
BearerSubaccount string `json:"bearer_subaccount,omitempty"`
Active bool `json:"active,omitempty"`
}
type TransactionSplitList struct {
Meta PaginationMeta `json:"meta"`
Data []TransactionSplitResponse `json:"data"`
}
type TransactionSplitResponse struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Currency string `json:"currency,omitempty"`
Integration int `json:"integration,omitempty"`
Domain string `json:"domain,omitempty"`
SplitCode string `json:"split_code,omitempty"`
Active bool `json:"active,omitempty"`
BearerType string `json:"bearer_type,omitempty"`
BearerSubaccount int `json:"bearer_subaccount,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
Subaccounts []struct {
Subaccount struct {
ID int `json:"id,omitempty"`
SubaccountCode string `json:"subaccount_code,omitempty"`
BusinessName string `json:"business_name,omitempty"`
Description string `json:"description,omitempty"`
PrimaryContactName interface{} `json:"primary_contact_name,omitempty"`
PrimaryContactEmail interface{} `json:"primary_contact_email,omitempty"`
PrimaryContactPhone interface{} `json:"primary_contact_phone,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
PercentageCharge int `json:"percentage_charge,omitempty"`
SettlementBank string `json:"settlement_bank,omitempty"`
AccountNumber string `json:"account_number,omitempty"`
} `json:"subaccount,omitempty"`
Share int `json:"share,omitempty"`
} `json:"subaccounts,omitempty"`
TotalSubaccounts int `json:"total_subaccounts,omitempty"`
}
// Create a transaction split
// For more details see https://paystack.com/docs/api/split/#create
func (ts *TransactionSplit) Create(ctx context.Context, txn *TransactionSplitRequest) (*TransactionSplitResponse, error) {
url := "split"
resp := &TransactionSplitResponse{}
err := postResource(ctx, ts.client, url, txn, resp)
return resp, err
}
// List/Search Transaction splits
//
// For more details see https://paystack.com/docs/api/split/#list
func (ts *TransactionSplit) List(ctx context.Context, params ...QueryType) (*TransactionSplitList, error) {
var url string
if len(params) > 0 {
url = addQueryToUrl("split", params...)
} else {
url = "/split"
}
resp := &TransactionSplitList{}
err := getResource(ctx, ts.client, url, resp)
return resp, err
}
// Fetch a Transaction splits
//
// For more details see https://paystack.com/docs/api/split/#fetch
func (ts *TransactionSplit) Fetch(ctx context.Context, id string) (*TransactionSplitResponse, error) {
url := fmt.Sprintf("/split/%s", id)
resp := &TransactionSplitResponse{}
err := getResource(ctx, ts.client, url, resp)
return resp, err
}
// Update a transaction split
// For more details see https://paystack.com/docs/api/split/#update
func (ts *TransactionSplit) Update(ctx context.Context, id string, txn *TransactionSplitRequest) (*TransactionSplitResponse, error) {
url := fmt.Sprintf("/split/%s", id)
resp := &TransactionSplitResponse{}
err := putResource(ctx, ts.client, url, txn, resp)
return resp, err
}
// Add/Update a transaction split subaccount
// For more details see https://paystack.com/docs/api/split/#add-subaccount
func (ts *TransactionSplit) AddSubaccount(ctx context.Context, id string, txn *TransactionSplitSubAccount) (*TransactionSplitResponse, error) {
url := fmt.Sprintf("/split/%s/subaccount/add", id)
resp := &TransactionSplitResponse{}
err := postResource(ctx, ts.client, url, txn, resp)
return resp, err
}
// Remove a transaction split subaccount
// For more details see https://paystack.com/docs/api/split/#remove-subaccount
func (ts *TransactionSplit) RemoveSubaccount(ctx context.Context, id string, txn *TransactionSplitSubAccount) (*GenericResponse, error) {
url := fmt.Sprintf("/split/%s/subaccount/remove", id)
resp := &GenericResponse{}
err := postResource(ctx, ts.client, url, txn, resp)
return resp, err
}