-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpayouts.go
executable file
·192 lines (155 loc) · 5.29 KB
/
payouts.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
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
// Code generated by `go-sdk-gen`. DO NOT EDIT.
package sumup
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
)
// FinancialPayout is a schema definition.
type FinancialPayout struct {
Amount *float64 `json:"amount,omitempty"`
Currency *string `json:"currency,omitempty"`
// Format: date
Date *Date `json:"date,omitempty"`
Fee *float64 `json:"fee,omitempty"`
Id *int `json:"id,omitempty"`
Reference *string `json:"reference,omitempty"`
Status *FinancialPayoutStatus `json:"status,omitempty"`
TransactionCode *string `json:"transaction_code,omitempty"`
Type *FinancialPayoutType `json:"type,omitempty"`
}
// FinancialPayoutStatus is a schema definition.
type FinancialPayoutStatus string
const (
FinancialPayoutStatusFailed FinancialPayoutStatus = "FAILED"
FinancialPayoutStatusSuccessful FinancialPayoutStatus = "SUCCESSFUL"
)
// FinancialPayoutType is a schema definition.
type FinancialPayoutType string
const (
FinancialPayoutTypeBalanceDeduction FinancialPayoutType = "BALANCE_DEDUCTION"
FinancialPayoutTypeChargeBackDeduction FinancialPayoutType = "CHARGE_BACK_DEDUCTION"
FinancialPayoutTypeDdReturnDeduction FinancialPayoutType = "DD_RETURN_DEDUCTION"
FinancialPayoutTypePayout FinancialPayoutType = "PAYOUT"
FinancialPayoutTypeRefundDeduction FinancialPayoutType = "REFUND_DEDUCTION"
)
// FinancialPayouts is a schema definition.
type FinancialPayouts []FinancialPayout
// ListPayoutsParams: query parameters for ListPayouts
type ListPayoutsParams struct {
// End date (in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) format).
EndDate Date
Format *string
Limit *int
Order *string
// Start date (in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) format).
StartDate Date
}
// QueryValues converts [ListPayoutsParams] into [url.Values].
func (p *ListPayoutsParams) QueryValues() url.Values {
q := make(url.Values)
q.Set("end_date", p.EndDate.String())
if p.Format != nil {
q.Set("format", *p.Format)
}
if p.Limit != nil {
q.Set("limit", strconv.Itoa(*p.Limit))
}
if p.Order != nil {
q.Set("order", *p.Order)
}
q.Set("start_date", p.StartDate.String())
return q
}
// ListPayoutsV1Params: query parameters for ListPayoutsV1
type ListPayoutsV1Params struct {
// End date (in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) format).
EndDate Date
Format *string
Limit *int
Order *string
// Start date (in [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) format).
StartDate Date
}
// QueryValues converts [ListPayoutsV1Params] into [url.Values].
func (p *ListPayoutsV1Params) QueryValues() url.Values {
q := make(url.Values)
q.Set("end_date", p.EndDate.String())
if p.Format != nil {
q.Set("format", *p.Format)
}
if p.Limit != nil {
q.Set("limit", strconv.Itoa(*p.Limit))
}
if p.Order != nil {
q.Set("order", *p.Order)
}
q.Set("start_date", p.StartDate.String())
return q
}
type PayoutsService service
// ListDeprecated: List payouts
// Lists ordered payouts for the merchant profile.
func (s *PayoutsService) ListDeprecated(ctx context.Context, params ListPayoutsParams) (*FinancialPayouts, error) {
path := fmt.Sprintf("/v0.1/me/financials/payouts")
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
req.URL.RawQuery = params.QueryValues().Encode()
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
switch resp.StatusCode {
case http.StatusOK:
var v FinancialPayouts
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
case http.StatusUnauthorized:
var apiErr Error
if err := json.NewDecoder(resp.Body).Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
default:
return nil, fmt.Errorf("unexpected response %d: %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
}
// List: List payouts
// Lists ordered payouts for the merchant profile.
func (s *PayoutsService) List(ctx context.Context, merchantCode string, params ListPayoutsV1Params) (*FinancialPayouts, error) {
path := fmt.Sprintf("/v1.0/merchants/%v/payouts", merchantCode)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, http.NoBody)
if err != nil {
return nil, fmt.Errorf("error building request: %v", err)
}
req.URL.RawQuery = params.QueryValues().Encode()
resp, err := s.client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
switch resp.StatusCode {
case http.StatusOK:
var v FinancialPayouts
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, fmt.Errorf("decode response: %s", err.Error())
}
return &v, nil
case http.StatusUnauthorized:
var apiErr Error
if err := json.NewDecoder(resp.Body).Decode(&apiErr); err != nil {
return nil, fmt.Errorf("read error response: %s", err.Error())
}
return nil, &apiErr
default:
return nil, fmt.Errorf("unexpected response %d: %s", resp.StatusCode, http.StatusText(resp.StatusCode))
}
}